diff options
author | Bruno Haible <bruno@clisp.org> | 2021-01-09 06:11:24 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2021-01-09 07:45:33 +0100 |
commit | 711098617fea3674aada0f1aee583d29cc47bfa7 (patch) | |
tree | 5c66399556b03d825a8a04c37e01dca0157f6ba2 /tests/test-fchmodat.c | |
parent | 893f8c7445af51b51dcfa9fd63b3bcf6e39cdd8a (diff) | |
download | gnulib-711098617fea3674aada0f1aee583d29cc47bfa7.tar.gz |
fchmod-tests, fchmodat tests, lchmod tests: Add more tests.
* tests/test-fchmod.c: Include <fcntl.h>.
(BASE): New macro.
(main): Add more tests.
* tests/test-fchmodat.c (main): Add more tests.
* tests/test-lchmod.c (main): Likewise.
Diffstat (limited to 'tests/test-fchmodat.c')
-rw-r--r-- | tests/test-fchmodat.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test-fchmodat.c b/tests/test-fchmodat.c index 5e4d2b04f4..6d430fa658 100644 --- a/tests/test-fchmodat.c +++ b/tests/test-fchmodat.c @@ -46,6 +46,39 @@ main (void) ASSERT (errno == EBADF); } + /* Test that fchmodat works on regular files. */ + { + struct stat statbuf; + + unlink (BASE "file"); + ASSERT (close (creat (BASE "file", 0600)) == 0); + ASSERT (fchmodat (AT_FDCWD, BASE "file", 0400, 0) == 0); + ASSERT (stat (BASE "file", &statbuf) >= 0); + ASSERT ((statbuf.st_mode & 0700) == 0400); + + errno = 0; + ASSERT (fchmodat (AT_FDCWD, BASE "file/", 0600, 0) == -1); + ASSERT (errno == ENOTDIR); + + /* Clean up. */ + ASSERT (chmod (BASE "file", 0600) == 0); + ASSERT (unlink (BASE "file") == 0); + } + + /* Test that fchmodat works on directories. */ + { + struct stat statbuf; + rmdir (BASE "dir"); + ASSERT (mkdir (BASE "dir", 0700) == 0); + ASSERT (fchmodat (AT_FDCWD, BASE "dir", 0500, 0) == 0); + ASSERT (stat (BASE "dir", &statbuf) >= 0); + ASSERT ((statbuf.st_mode & 0700) == 0500); + ASSERT (fchmodat (AT_FDCWD, BASE "dir/", 0700, 0) == 0); + + /* Clean up. */ + ASSERT (rmdir (BASE "dir") == 0); + } + /* Test that fchmodat works on non-symlinks, when given the AT_SYMLINK_NOFOLLOW flag. */ { |