This source file includes following definitions.
- do_utimensat
- do_lutimensat
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include <sys/stat.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (utimensat, int, (int, char const *, struct timespec const[2],
25 int));
26
27 #include <fcntl.h>
28 #include <errno.h>
29 #include <stdbool.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <unistd.h>
34
35 #include "stat-time.h"
36 #include "timespec.h"
37 #include "utimecmp.h"
38 #include "ignore-value.h"
39 #include "macros.h"
40
41 #define BASE "test-utimensat.t"
42
43 #include "test-lutimens.h"
44 #include "test-utimens.h"
45
46 static int dfd = AT_FDCWD;
47
48
49 static int
50 do_utimensat (char const *name, struct timespec const times[2])
51 {
52 return utimensat (dfd, name, times, 0);
53 }
54
55
56 static int
57 do_lutimensat (char const *name, struct timespec const times[2])
58 {
59 return utimensat (dfd, name, times, AT_SYMLINK_NOFOLLOW);
60 }
61
62 int
63 main (void)
64 {
65 int result1;
66 int result2;
67 int fd;
68
69
70 ignore_value (system ("rm -rf " BASE "*"));
71
72
73 {
74 errno = 0;
75 ASSERT (utimensat (-1, "foo", NULL, 0) == -1);
76 ASSERT (errno == EBADF);
77 }
78 {
79 close (99);
80 errno = 0;
81 ASSERT (utimensat (99, "foo", NULL, 0) == -1);
82 ASSERT (errno == EBADF);
83 }
84
85
86 result1 = test_utimens (do_utimensat, true);
87 result2 = test_lutimens (do_lutimensat, result1 == 0);
88 dfd = open (".", O_RDONLY);
89 ASSERT (0 <= dfd);
90 ASSERT (test_utimens (do_utimensat, false) == result1);
91 ASSERT (test_lutimens (do_lutimensat, false) == result2);
92
93 ASSERT (result1 <= result2);
94
95
96 ASSERT (mkdir (BASE "dir", 0700) == 0);
97 ASSERT (chdir (BASE "dir") == 0);
98 fd = creat ("file", 0600);
99 ASSERT (0 <= fd);
100 errno = 0;
101 ASSERT (utimensat (fd, ".", NULL, 0) == -1);
102 ASSERT (errno == ENOTDIR);
103 {
104 struct timespec ts[2];
105 struct stat st;
106 ts[0].tv_sec = Y2K;
107 ts[0].tv_nsec = 0;
108 ts[1].tv_sec = Y2K;
109 ts[1].tv_nsec = 0;
110 ASSERT (utimensat (dfd, BASE "dir/file", ts, AT_SYMLINK_NOFOLLOW) == 0);
111 ASSERT (stat ("file", &st) == 0);
112 ASSERT (st.st_atime == Y2K);
113 ASSERT (get_stat_atime_ns (&st) == 0);
114 ASSERT (st.st_mtime == Y2K);
115 ASSERT (get_stat_mtime_ns (&st) == 0);
116 }
117 ASSERT (close (fd) == 0);
118 ASSERT (close (dfd) == 0);
119 errno = 0;
120 ASSERT (utimensat (dfd, ".", NULL, 0) == -1);
121 ASSERT (errno == EBADF);
122
123
124 ASSERT (chdir ("..") == 0);
125 ASSERT (unlink (BASE "dir/file") == 0);
126 ASSERT (rmdir (BASE "dir") == 0);
127 return result1 | result2;
128 }