]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
openat2-tests: fix AT_FDCWD portability
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 1 Sep 2025 18:25:00 +0000 (11:25 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 1 Sep 2025 18:25:52 +0000 (11:25 -0700)
* tests/test-openat.c (main): Work even if AT_FDCWD == -1.

ChangeLog
doc/posix-headers/fcntl.texi
tests/test-openat.c

index 46e8238da13eb9db6add54060002bca369e629b6..0e3d2c7f1eece9fa65a30c0abf6ca6cfdd774973 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2025-09-01  Paul Eggert  <eggert@cs.ucla.edu>
+
+       openat2-tests: fix AT_FDCWD portability
+       * tests/test-openat.c (main): Work even if AT_FDCWD == -1.
+
 2025-08-31  Collin Funk  <collin.funk1@gmail.com>
 
        u64: Allow the header to be included twice.
index 75d9128cd8d2441e7346cbb01d688178591be662..354bae0193ea68a7428056567207215edeaa99f4 100644 (file)
@@ -149,4 +149,11 @@ mingw, MSVC 14.
 @samp{POSIX_FADV_NORMAL}, @samp{POSIX_FADV_RANDOM},
 @samp{POSIX_FADV_SEQUENTIAL}, and @samp{POSIX_FADV_WILLNEED} are not
 defined on some platforms.
+
+@item
+POSIX allows @samp{AT_FDCWD} to be @minus{}1.
+Even though @samp{AT_FDCWD} is less than @minus{}1 on all
+known practical platforms,
+it is better to not assume that @minus{}1 is an invalid argument
+to functions like @samp{openat}.
 @end itemize
index 1405f4f7a5195a30456bfc0f535df74777216390..5b904f97fd3a947391fc34b3122b6fc3b03387dd 100644 (file)
@@ -69,7 +69,7 @@ main ()
   /* Test behaviour for invalid file descriptors.  */
   {
     errno = 0;
-    ASSERT (openat (-1, "foo", O_RDONLY) == -1);
+    ASSERT (openat (AT_FDCWD == -1 ? -2 : -1, "foo", O_RDONLY) == -1);
     ASSERT (errno == EBADF);
   }
   {