| 1 | // { dg-do run { target c++17 } } |
| 2 | // { dg-require-filesystem-ts "" } |
| 3 | |
| 4 | #include <filesystem> |
| 5 | #include <testsuite_fs.h> |
| 6 | #include <testsuite_hooks.h> |
| 7 | |
| 8 | #if defined(_GLIBCXX_HAVE_SYS_STAT_H) && defined(_GLIBCXX_HAVE_SYS_TYPES_H) |
| 9 | # include <sys/types.h> |
| 10 | # include <sys/stat.h> // mkfifo |
| 11 | #endif |
| 12 | |
| 13 | namespace fs = std::filesystem; |
| 14 | |
| 15 | void |
| 16 | test_pr118158() |
| 17 | { |
| 18 | #if defined(_GLIBCXX_HAVE_SYS_STAT_H) && defined(_GLIBCXX_HAVE_SYS_TYPES_H) \ |
| 19 | && defined(S_IWUSR) && defined(S_IRUSR) |
| 20 | auto p1 = __gnu_test::nonexistent_path(); |
| 21 | auto p2 = __gnu_test::nonexistent_path(); |
| 22 | auto p3 = __gnu_test::nonexistent_path(); |
| 23 | const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); |
| 24 | std::error_code ec; |
| 25 | bool result; |
| 26 | |
| 27 | VERIFY( ! ::mkfifo(p1.c_str(), S_IWUSR | S_IRUSR) ); |
| 28 | __gnu_test::scoped_file f1(p1, __gnu_test::scoped_file::adopt_file); |
| 29 | |
| 30 | // Special file is equivalent to itself. |
| 31 | VERIFY( equivalent(p1, p1) ); |
| 32 | VERIFY( equivalent(p1, p1, ec) ); |
| 33 | VERIFY( ! ec ); |
| 34 | |
| 35 | VERIFY( ! ::mkfifo(p2.c_str(), S_IWUSR | S_IRUSR) ); |
| 36 | __gnu_test::scoped_file f2(p2, __gnu_test::scoped_file::adopt_file); |
| 37 | |
| 38 | ec = bad_ec; |
| 39 | // Distinct special files are not equivalent. |
| 40 | VERIFY( ! equivalent(p1, p2, ec) ); |
| 41 | VERIFY( ! ec ); |
| 42 | |
| 43 | // Non-existent paths are always an error. |
| 44 | VERIFY( ! equivalent(p1, p3, ec) ); |
| 45 | VERIFY( ec == std::errc::no_such_file_or_directory ); |
| 46 | ec = bad_ec; |
| 47 | VERIFY( ! equivalent(p3, p2, ec) ); |
| 48 | VERIFY( ec == std::errc::no_such_file_or_directory ); |
| 49 | |
| 50 | // Special file is not equivalent to regular file. |
| 51 | __gnu_test::scoped_file f3(p3); |
| 52 | ec = bad_ec; |
| 53 | VERIFY( ! equivalent(p1, p3, ec) ); |
| 54 | VERIFY( ! ec ); |
| 55 | #endif |
| 56 | } |
| 57 | |
| 58 | int |
| 59 | main() |
| 60 | { |
| 61 | test_pr118158(); |
| 62 | } |