int main (void) { int result1; /* Skip because of no symlink support. */ int result2; /* Skip because of no futimens support. */ int result3; /* Skip because of no lutimens support. */ int fd; /* Clean up any trash from prior testsuite runs. */ ignore_value (system ("rm -rf " BASE "*")); /* Basic tests. */ result1 = test_utimens (do_utimens, true); ASSERT (test_utimens (do_fdutimens, false) == result1); result2 = test_futimens (do_futimens, result1 == 0); result3 = test_lutimens (do_lutimens, (result1 + result2) == 0); /* We expect 0/0, 0/77, or 77/77, but not 77/0. */ ASSERT (result1 <= result3); ASSERT (test_lutimens (do_lutimens1, (result1 + result2) == 0) == result3); dfd = open (".", O_RDONLY); ASSERT (0 <= dfd); ASSERT (test_utimens (do_utimens, false) == result1); ASSERT (test_utimens (do_fdutimens, false) == result1); ASSERT (test_futimens (do_futimens, false) == result2); ASSERT (test_lutimens (do_lutimens, false) == result3); ASSERT (test_lutimens (do_lutimens1, false) == result3); /* Directory relative tests. */ ASSERT (mkdir (BASE "dir", 0700) == 0); ASSERT (chdir (BASE "dir") == 0); fd = creat ("file", 0600); ASSERT (0 <= fd); errno = 0; ASSERT (fdutimensat (AT_FDCWD, fd, ".", NULL, 0) == -1); ASSERT (errno == ENOTDIR); { struct timespec ts[2] = { { Y2K, 0 }, { Y2K, 0 } }; struct stat st; ASSERT (fdutimensat (fd, dfd, BASE "dir/file", ts, 0) == 0); ASSERT (stat ("file", &st) == 0); ASSERT (st.st_atime == Y2K); ASSERT (get_stat_atime_ns (&st) == 0); ASSERT (st.st_mtime == Y2K); ASSERT (get_stat_mtime_ns (&st) == 0); } ASSERT (close (fd) == 0); ASSERT (close (dfd) == 0); errno = 0; ASSERT (fdutimensat (-1, dfd, ".", NULL, 0) == -1); ASSERT (errno == EBADF); /* Cleanup. */ ASSERT (chdir ("..") == 0); ASSERT (unlink (BASE "dir/file") == 0); ASSERT (rmdir (BASE "dir") == 0); return result1 | result2 | result3; }
int main (void) { int result1; /* Skip because of no symlink support. */ int result2; /* Skip because of no futimens support. */ int result3; /* Skip because of no lutimens support. */ /* Clean up any trash from prior testsuite runs. */ ignore_value (system ("rm -rf " BASE "*")); result1 = test_utimens (utimens, true); ASSERT (test_utimens (do_fdutimens, false) == result1); /* Print only one skip message. */ result2 = test_futimens (do_futimens, result1 == 0); result3 = test_lutimens (lutimens, (result1 + result2) == 0); /* We expect 0/0, 0/77, or 77/77, but not 77/0. */ ASSERT (result1 <= result3); return result1 | result2 | result3; }
int main (void) { int result1; /* Skip because of no symlink support. */ int result2; /* Skip because of no lutimens support. */ int fd; /* Clean up any trash from prior testsuite runs. */ ignore_value (system ("rm -rf " BASE "*")); /* Test behaviour for invalid file descriptors. */ { errno = 0; ASSERT (utimensat (-1, "foo", NULL, 0) == -1); ASSERT (errno == EBADF); } { close (99); errno = 0; ASSERT (utimensat (99, "foo", NULL, 0) == -1); ASSERT (errno == EBADF); } /* Basic tests. */ result1 = test_utimens (do_utimensat, true); result2 = test_lutimens (do_lutimensat, result1 == 0); dfd = open (".", O_RDONLY); ASSERT (0 <= dfd); ASSERT (test_utimens (do_utimensat, false) == result1); ASSERT (test_lutimens (do_lutimensat, false) == result2); /* We expect 0/0, 0/77, or 77/77, but not 77/0. */ ASSERT (result1 <= result2); /* Directory-relative tests. */ ASSERT (mkdir (BASE "dir", 0700) == 0); ASSERT (chdir (BASE "dir") == 0); fd = creat ("file", 0600); ASSERT (0 <= fd); errno = 0; ASSERT (utimensat (fd, ".", NULL, 0) == -1); ASSERT (errno == ENOTDIR); { struct timespec ts[2] = { { Y2K, 0 }, { Y2K, 0 } }; struct stat st; ASSERT (utimensat (dfd, BASE "dir/file", ts, AT_SYMLINK_NOFOLLOW) == 0); ASSERT (stat ("file", &st) == 0); ASSERT (st.st_atime == Y2K); ASSERT (get_stat_atime_ns (&st) == 0); ASSERT (st.st_mtime == Y2K); ASSERT (get_stat_mtime_ns (&st) == 0); } ASSERT (close (fd) == 0); ASSERT (close (dfd) == 0); errno = 0; ASSERT (utimensat (dfd, ".", NULL, 0) == -1); ASSERT (errno == EBADF); /* Cleanup. */ ASSERT (chdir ("..") == 0); ASSERT (unlink (BASE "dir/file") == 0); ASSERT (rmdir (BASE "dir") == 0); return result1 | result2; }