From bdc7e223aaced59cd03436e1518845db011fba4b Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 22 Jan 2006 00:57:24 +0000 Subject: * 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. --- io/tst-openat.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'io/tst-openat.c') 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; } -- cgit 1.4.1