1 #include <sys/stat.h>
2 #include <errno.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <time.h>
6 #include <stdint.h>
7 #include <unistd.h>
8 #include <fcntl.h>
9 #include "test.h"
10
11 #define TEST(c, ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0))
12 #define TESTVAL(v,op,x) TEST(v op x, "%jd\n", (intmax_t)(v))
13
14 extern int __fstat_time64(int, struct stat *);
15 extern int __futimens_time64(int, const struct timespec [2]);
16
main(void)17 int main(void)
18 {
19 struct stat st;
20 FILE *f;
21 int fd;
22 time_t t;
23
24 TEST(utimensat(AT_FDCWD, "/dev/null/invalid", ((struct timespec[2]){{.tv_nsec=UTIME_OMIT},{.tv_nsec=UTIME_OMIT}}), 0)==0 || errno==ENOTDIR,
25 "%s\n", strerror(errno));
26 TEST(__futimens_time64(-1, ((struct timespec[2]){{.tv_nsec=UTIME_OMIT},{.tv_nsec=UTIME_OMIT}}))==0 || errno==EBADF,
27 "%s\n", strerror(errno));
28
29 if (!TEST(f = tmpfile())) return t_status;
30 fd = fileno(f);
31
32 TEST(__futimens_time64(fd, (struct timespec[2]){0}) == 0, "\n");
33 TEST(__fstat_time64(fd, &st) == 0, "\n");
34 TESTVAL(st.st_atim.tv_sec,==,0);
35 TESTVAL(st.st_atim.tv_nsec,==,0);
36 TESTVAL(st.st_mtim.tv_sec,==,0);
37 TESTVAL(st.st_mtim.tv_nsec,==,0);
38
39 TEST(__futimens_time64(fd, ((struct timespec[2]){{.tv_sec=1,.tv_nsec=UTIME_OMIT},{.tv_sec=1,.tv_nsec=UTIME_OMIT}})) == 0, "\n");
40 TEST(__fstat_time64(fd, &st) == 0, "\n");
41 TESTVAL(st.st_atim.tv_sec,==,0);
42 TESTVAL(st.st_atim.tv_nsec,==,0);
43 TESTVAL(st.st_mtim.tv_sec,==,0);
44 TESTVAL(st.st_mtim.tv_nsec,==,0);
45
46 t = time(0);
47
48 TEST(__futimens_time64(fd, ((struct timespec[2]){{.tv_nsec=UTIME_NOW},{.tv_nsec=UTIME_OMIT}})) == 0, "\n");
49 TEST(__fstat_time64(fd, &st) == 0, "\n");
50 TESTVAL(st.st_atim.tv_sec,>=,t);
51 TESTVAL(st.st_mtim.tv_sec,==,0);
52 TESTVAL(st.st_mtim.tv_nsec,==,0);
53
54 TEST(__futimens_time64(fd, (struct timespec[2]){0}) == 0, "\n");
55 TEST(__futimens_time64(fd, ((struct timespec[2]){{.tv_nsec=UTIME_OMIT},{.tv_nsec=UTIME_NOW}})) == 0, "\n");
56 TEST(__fstat_time64(fd, &st) == 0, "\n");
57 TESTVAL(st.st_atim.tv_sec,==,0);
58 TESTVAL(st.st_mtim.tv_sec,>=,t);
59
60 TEST(__futimens_time64(fd, ((struct timespec[2]){{.tv_nsec=UTIME_NOW},{.tv_nsec=UTIME_OMIT}})) == 0, "\n");
61 TEST(__fstat_time64(fd, &st) == 0, "\n");
62 TESTVAL(st.st_atim.tv_sec,>=,t);
63 TESTVAL(st.st_mtim.tv_sec,>=,t);
64
65 if (TEST((time_t)(1LL<<32) == (1LL<<32), "implementation has Y2038 EOL\n")) {
66 if (TEST(__futimens_time64(fd, ((struct timespec[2]){{.tv_sec=1LL<<32},{.tv_sec=1LL<<32}})) == 0, "%s\n", strerror(errno))) {
67 TEST(__fstat_time64(fd, &st) == 0, "\n");
68 TESTVAL(st.st_atim.tv_sec, ==, 1LL<<32);
69 TESTVAL(st.st_mtim.tv_sec, ==, 1LL<<32);
70 }
71 }
72
73 fclose(f);
74
75 return t_status;
76 }
77