2 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
23 #include "signature.h"
24 SIGNATURE_CHECK (utimensat, int, (int, char const *, struct timespec const[2],
35 #include "stat-time.h"
40 #define BASE "test-utimensat.t"
42 #include "test-lutimens.h"
43 #include "test-utimens.h"
45 static int dfd = AT_FDCWD;
47 /* Wrap utimensat to behave like utimens. */
49 do_utimensat (char const *name, struct timespec const times[2])
51 return utimensat (dfd, name, times, 0);
54 /* Wrap utimensat to behave like lutimens. */
56 do_lutimensat (char const *name, struct timespec const times[2])
58 return utimensat (dfd, name, times, AT_SYMLINK_NOFOLLOW);
64 int result1; /* Skip because of no symlink support. */
65 int result2; /* Skip because of no lutimens support. */
68 /* Clean up any trash from prior testsuite runs. */
69 system ("rm -rf " BASE "*");
72 result1 = test_utimens (do_utimensat, true);
73 result2 = test_lutimens (do_lutimensat, result1 == 0);
74 dfd = open (".", O_RDONLY);
76 ASSERT (test_utimens (do_utimensat, false) == result1);
77 ASSERT (test_lutimens (do_lutimensat, false) == result2);
78 /* We expect 0/0, 0/77, or 77/77, but not 77/0. */
79 ASSERT (result1 <= result2);
81 /* Directory-relative tests. */
82 ASSERT (mkdir (BASE "dir", 0700) == 0);
83 ASSERT (chdir (BASE "dir") == 0);
84 fd = creat ("file", 0600);
87 ASSERT (utimensat (fd, ".", NULL, 0) == -1);
88 ASSERT (errno == ENOTDIR);
90 struct timespec ts[2] = { { Y2K, 0 }, { Y2K, 0 } };
92 ASSERT (utimensat (dfd, BASE "dir/file", ts, AT_SYMLINK_NOFOLLOW) == 0);
93 ASSERT (stat ("file", &st) == 0);
94 ASSERT (st.st_atime == Y2K);
95 ASSERT (get_stat_atime_ns (&st) == 0);
96 ASSERT (st.st_mtime == Y2K);
97 ASSERT (get_stat_mtime_ns (&st) == 0);
99 ASSERT (close (fd) == 0);
100 ASSERT (close (dfd) == 0);
102 ASSERT (utimensat (dfd, ".", NULL, 0) == -1);
103 ASSERT (errno == EBADF);
106 ASSERT (chdir ("..") == 0);
107 ASSERT (unlink (BASE "dir/file") == 0);
108 ASSERT (rmdir (BASE "dir") == 0);
109 return result1 | result2;