diff options
author | Jakub Jelinek <jakub@redhat.com> | 2006-01-30 09:30:09 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2006-01-30 09:30:09 +0000 |
commit | 3e543bc56346540cbf73fd48d0172fc6a588efd5 (patch) | |
tree | b2c3502b6596d238ac861cc82cafdc6f8b84e143 /io/tst-faccessat.c | |
parent | 06f313e361a523605ba6d4c9cdc67a7353cd367c (diff) | |
download | glibc-3e543bc56346540cbf73fd48d0172fc6a588efd5.tar glibc-3e543bc56346540cbf73fd48d0172fc6a588efd5.tar.gz glibc-3e543bc56346540cbf73fd48d0172fc6a588efd5.tar.bz2 glibc-3e543bc56346540cbf73fd48d0172fc6a588efd5.zip |
Updated to fedora-glibc-20060130T0922
Diffstat (limited to 'io/tst-faccessat.c')
-rw-r--r-- | io/tst-faccessat.c | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/io/tst-faccessat.c b/io/tst-faccessat.c index 3bf7aed2e5..48532070a7 100644 --- a/io/tst-faccessat.c +++ b/io/tst-faccessat.c @@ -98,6 +98,20 @@ do_test (void) write (fd, "hello", 5); puts ("file created"); + /* Before closing the file, try using this file descriptor to open + another file. This must fail. */ + if (faccessat (fd, "should-not-work", F_OK, AT_EACCESS) != -1) + { + puts ("faccessat using descriptor for normal file worked"); + return 1; + } + if (errno != ENOTDIR) + { + puts ("\ +error for faccessat using descriptor for normal file not ENOTDIR "); + return 1; + } + close (fd); int result = 0; @@ -135,12 +149,45 @@ do_test (void) errno = 0; if (faccessat (dir_fd, "some-file", W_OK, AT_EACCESS) == 0 - || errno != EACCES) + ? (geteuid () != 0) : (errno != EACCES)) { printf ("faccessat W_OK on unwritable file: %m\n"); result = 1; } + /* Create a file descriptor which is closed again right away. */ + int dir_fd2 = dup (dir_fd); + if (dir_fd2 == -1) + { + puts ("dup failed"); + return 1; + } + close (dir_fd2); + + /* With the file descriptor closed the next call must fail. */ + if (faccessat (dir_fd2, "some-file", F_OK, AT_EACCESS) != -1) + { + puts ("faccessat using closed descriptor succeeded"); + return 1; + } + if (errno != EBADF) + { + puts ("faccessat using closed descriptor did not set EBADF"); + return 1; + } + + /* Same with a non-existing file. */ + if (faccessat (dir_fd2, "non-existing-file", F_OK, AT_EACCESS) != -1) + { + puts ("2nd faccessat using closed descriptor succeeded"); + return 1; + } + if (errno != EBADF) + { + puts ("2nd faccessat using closed descriptor did not set EBADF"); + return 1; + } + if (unlinkat (dir_fd, "some-file", 0) != 0) { puts ("unlinkat failed"); @@ -149,5 +196,17 @@ do_test (void) close (dir_fd); + fd = faccessat (-1, "some-file", F_OK, AT_EACCESS); + if (fd != -1) + { + puts ("faccessat using -1 descriptor succeeded"); + return 1; + } + if (errno != EBADF) + { + puts ("faccessat using -1 descriptor did not set EBADF"); + return 1; + } + return result; } |