]> Savannah Git Hosting - gnulib.git/commitdiff
tests: Strenghten tests with invalid file descriptor.
authorBruno Haible <bruno@clisp.org>
Tue, 3 Sep 2024 21:00:28 +0000 (23:00 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 3 Sep 2024 21:00:28 +0000 (23:00 +0200)
* tests/test-close.c: Include <fcntl.h>.
(main): Check that AT_FDCWD is recognized as an invalid file descriptor.
* tests/test-dup.c: Include <fcntl.h>.
(main): Check that AT_FDCWD is recognized as an invalid file descriptor.
* tests/test-unlockpt.c: Include <fcntl.h>.
(main): Check that AT_FDCWD is recognized as an invalid file descriptor.
* tests/test-fchdir.c (main): Likewise.
* tests/test-fdatasync.c (main): Likewise.
* tests/test-fdopendir.c (main): Likewise.
* tests/test-fsync.c (main): Likewise.
* tests/test-isatty.c (main): Likewise.

ChangeLog
tests/test-close.c
tests/test-dup.c
tests/test-fchdir.c
tests/test-fdatasync.c
tests/test-fdopendir.c
tests/test-fsync.c
tests/test-isatty.c
tests/test-unlockpt.c

index a86f4ee321930b35459f24f898a093e1f1cefc9b..c241453a5bd1137b1f675d1535898099b6567db4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2024-09-03  Bruno Haible  <bruno@clisp.org>
+
+       tests: Strenghten tests with invalid file descriptor.
+       * tests/test-close.c: Include <fcntl.h>.
+       (main): Check that AT_FDCWD is recognized as an invalid file descriptor.
+       * tests/test-dup.c: Include <fcntl.h>.
+       (main): Check that AT_FDCWD is recognized as an invalid file descriptor.
+       * tests/test-unlockpt.c: Include <fcntl.h>.
+       (main): Check that AT_FDCWD is recognized as an invalid file descriptor.
+       * tests/test-fchdir.c (main): Likewise.
+       * tests/test-fdatasync.c (main): Likewise.
+       * tests/test-fdopendir.c (main): Likewise.
+       * tests/test-fsync.c (main): Likewise.
+       * tests/test-isatty.c (main): Likewise.
+
 2024-09-03  Bruno Haible  <bruno@clisp.org>
 
        doc: More details about pthread_setname_np.
index b796e0d200584475b50a6ccfe7d7a2a25e6e297d..ca2c21bfe28f67bd9a5e8426519e5691a9bd1761 100644 (file)
@@ -22,6 +22,7 @@
 SIGNATURE_CHECK (close, int, (int));
 
 #include <errno.h>
+#include <fcntl.h>
 
 #include "macros.h"
 
@@ -40,6 +41,13 @@ main (void)
     ASSERT (close (99) == -1);
     ASSERT (errno == EBADF);
   }
+#ifdef AT_FDCWD
+  {
+    errno = 0;
+    ASSERT (close (AT_FDCWD) == -1);
+    ASSERT (errno == EBADF);
+  }
+#endif
 
   return test_exit_status;
 }
index bf3f519bb83f0596b71e36031d31d725dee6abd7..884fbc605c7e072706aefacad0b2f3165c93b4c6 100644 (file)
@@ -22,6 +22,7 @@
 SIGNATURE_CHECK (dup, int, (int));
 
 #include <errno.h>
+#include <fcntl.h>
 
 #include "macros.h"
 
@@ -40,6 +41,13 @@ main (void)
     ASSERT (dup (99) == -1);
     ASSERT (errno == EBADF);
   }
+#ifdef AT_FDCWD
+  {
+    errno = 0;
+    ASSERT (dup (AT_FDCWD) == -1);
+    ASSERT (errno == EBADF);
+  }
+#endif
 
   return test_exit_status;
 }
index 692ab5194c48f05cee2bb0b9b2cf674c6108ea58..0eba209c4732ff717a42e211de0f55e091c7ff45 100644 (file)
@@ -56,6 +56,13 @@ main (void)
     ASSERT (fchdir (99) == -1);
     ASSERT (errno == EBADF);
   }
+#ifdef FD_ATCWD
+  {
+    errno = 0;
+    ASSERT (fchdir (FD_ATCWD) == -1);
+    ASSERT (errno == EBADF);
+  }
+#endif
 
   /* Check for other failure cases.  */
   {
index 3d55a7105b4c9898128785f4ef7bdfca71871a74..691a198a992e86731c7ab16b121341364aff71e4 100644 (file)
@@ -56,6 +56,13 @@ main (void)
     ASSERT (fdatasync (99) == -1);
     ASSERT (errno == EBADF);
   }
+#ifdef AT_FDCWD
+  {
+    errno = 0;
+    ASSERT (fdatasync (AT_FDCWD) == -1);
+    ASSERT (errno == EBADF);
+  }
+#endif
 
   fd = open (file, O_WRONLY|O_CREAT|O_TRUNC, 0644);
   ASSERT (0 <= fd);
index 5dd8a4a96709b24a5eed6f5182ec73259f6cb6d0..3430d03bad3408930638b3b6df15c7ab44bc79ee 100644 (file)
@@ -56,6 +56,13 @@ main ()
     ASSERT (fdopendir (99) == NULL);
     ASSERT (errno == EBADF);
   }
+#ifdef AT_FDCWD
+  {
+    errno = 0;
+    ASSERT (fdopendir (AT_FDCWD) == NULL);
+    ASSERT (errno == EBADF);
+  }
+#endif
 
   /* This should work.  */
   fd = open (".", O_RDONLY);
index c28a5cc6ab62a90359e3df9c9cda8cd823718cae..7e680c274a4014748d632d5ae8782524e014019b 100644 (file)
@@ -56,6 +56,13 @@ main (void)
     ASSERT (fsync (99) == -1);
     ASSERT (errno == EBADF);
   }
+#ifdef AT_FDCWD
+  {
+    errno = 0;
+    ASSERT (fsync (AT_FDCWD) == -1);
+    ASSERT (errno == EBADF);
+  }
+#endif
 
   fd = open (file, O_WRONLY|O_CREAT|O_TRUNC, 0644);
   ASSERT (0 <= fd);
index 1c7d6d8cd9ea507da80d6527e264b57ecece9c3e..d844c62615abf12c390680c5a81a5b98b8c4ab7e 100644 (file)
@@ -56,6 +56,15 @@ main (void)
             || errno == 0 /* seen on IRIX 6.5, Solaris 10 */
            );
   }
+#ifdef AT_FDCWD
+  {
+    errno = 0;
+    ASSERT (isatty (AT_FDCWD) == 0);
+    ASSERT (errno == EBADF
+            || errno == 0 /* seen on IRIX 6.5, Solaris 10 */
+           );
+  }
+#endif
 
   /* Test behaviour for regular files.  */
   {
index e69f72db9799ae95376ba9fc6daa92b71d2ce87c..8fbd36cf693a75e73a802a67657103a2ca00664f 100644 (file)
@@ -22,6 +22,7 @@
 SIGNATURE_CHECK (unlockpt, int, (int));
 
 #include <errno.h>
+#include <fcntl.h>
 #include <unistd.h>
 
 #include "macros.h"
@@ -46,6 +47,15 @@ main (void)
             || errno == EINVAL /* seen on FreeBSD 6.4 */
            );
   }
+# ifdef AT_FDCWD
+  {
+    errno = 0;
+    ASSERT (unlockpt (AT_FDCWD) == -1);
+    ASSERT (errno == EBADF
+            || errno == EINVAL /* seen on FreeBSD 6.4 */
+           );
+  }
+# endif
 #endif
 
   return test_exit_status;