summaryrefslogtreecommitdiff
path: root/io/tst-openat.c
diff options
context:
space:
mode:
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;
}