about summary refs log tree commit diff
path: root/io/tst-openat.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-01-22 00:57:24 +0000
committerUlrich Drepper <drepper@redhat.com>2006-01-22 00:57:24 +0000
commitbdc7e223aaced59cd03436e1518845db011fba4b (patch)
tree51323b0689ccb4fa33978808e61009e2231f31ae /io/tst-openat.c
parentb2680b0331f23ae44f259ecf6c0016e5644c36b6 (diff)
downloadglibc-bdc7e223aaced59cd03436e1518845db011fba4b.tar.gz
glibc-bdc7e223aaced59cd03436e1518845db011fba4b.tar.xz
glibc-bdc7e223aaced59cd03436e1518845db011fba4b.zip
* sysdeps/unix/sysv/linux/renameat.c (__atfct_seterrno_2): Correcty
	return EBADF for non-existing file descriptors.
	* sysdeps/unix/sysv/linux/openat.c (__atfct_seterrno): Likewise.
	* io/tst-openat.c (do_test): Add some more tests.
	* io/tst-faccessat.c (do_test): Likewise.
	* io/tst-renameat.c (do_test): Likewise.
	* io/tst-fstatat.c (do_test): Likewise.
	* io/tst-fchmodat.c (do_test): Likewise.
	* io/tst-fchownat.c (do_test): Likewise.
Diffstat (limited to 'io/tst-openat.c')
-rw-r--r--io/tst-openat.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/io/tst-openat.c b/io/tst-openat.c
index d10b654fa9..0ceb745880 100644
--- a/io/tst-openat.c
+++ b/io/tst-openat.c
@@ -94,6 +94,21 @@ do_test (void)
       return 1;
     }
   write (fd, "hello", 5);
+
+  /* Before closing the file, try using this file descriptor to open
+     another file.  This must fail.  */
+  int fd2 = openat (fd, "should-not-work", O_CREAT|O_RDWR, 0666);
+  if (fd2 != -1)
+    {
+      puts ("openat using descriptor for normal file worked");
+      return 1;
+    }
+  if (errno != ENOTDIR)
+    {
+      puts ("error for openat using descriptor for normal file not ENOTDIR ");
+      return 1;
+    }
+
   close (fd);
   puts ("file created");
 
@@ -165,5 +180,30 @@ do_test (void)
   close (dir_fd);
   close (cwdfd);
 
+  /* With the file descriptor closed the next call must fail.  */
+  fd = openat (dir_fd, "some-file", O_CREAT|O_RDWR|O_EXCL, 0666);
+  if (fd != -1)
+    {
+      puts ("openat using closed descriptor succeeded");
+      return 1;
+    }
+  if (errno != EBADF)
+    {
+      puts ("openat using closed descriptor did not set EBADF");
+      return 1;
+    }
+
+  fd = openat (-1, "some-file", O_CREAT|O_RDWR|O_EXCL, 0666);
+  if (fd != -1)
+    {
+      puts ("openat using -1 descriptor succeeded");
+      return 1;
+    }
+  if (errno != EBADF)
+    {
+      puts ("openat using -1 descriptor did not set EBADF");
+      return 1;
+    }
+
   return 0;
 }