This source file includes following definitions.
- test_utime
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19 #include <utime.h>
20
21 #include <stdbool.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include "ignore-value.h"
26 #include "macros.h"
27
28 #define BASE "test-utime.t"
29
30 #include "test-utimens-common.h"
31
32
33 static int
34 test_utime (bool print)
35 {
36 struct stat st1;
37 struct stat st2;
38
39 ASSERT (close (creat (BASE "file", 0600)) == 0);
40 ASSERT (stat (BASE "file", &st1) == 0);
41 nap ();
42 ASSERT (utime (BASE "file", NULL) == 0);
43 ASSERT (stat (BASE "file", &st2) == 0);
44 ASSERT (0 <= utimecmp (BASE "file", &st2, &st1, UTIMECMP_TRUNCATE_SOURCE));
45 if (check_ctime)
46 ASSERT (ctime_compare (&st1, &st2) < 0);
47 {
48
49
50
51
52
53
54
55 struct utimbuf ts;
56 ts.actime = ts.modtime = time (NULL);
57 ASSERT (utime (BASE "file", &ts) == 0);
58 ASSERT (stat (BASE "file", &st1) == 0);
59 nap ();
60 }
61
62
63 errno = 0;
64 ASSERT (utime ("no_such", NULL) == -1);
65 ASSERT (errno == ENOENT);
66 errno = 0;
67 ASSERT (utime ("no_such/", NULL) == -1);
68 ASSERT (errno == ENOENT || errno == ENOTDIR);
69 errno = 0;
70 ASSERT (utime ("", NULL) == -1);
71 ASSERT (errno == ENOENT);
72 {
73 struct utimbuf ts;
74 ts.actime = ts.modtime = Y2K;
75 errno = 0;
76 ASSERT (utime (BASE "file/", &ts) == -1);
77 ASSERT (errno == ENOTDIR || errno == EINVAL);
78 }
79 ASSERT (stat (BASE "file", &st2) == 0);
80 ASSERT (st1.st_atime == st2.st_atime);
81 ASSERT (get_stat_atime_ns (&st1) == get_stat_atime_ns (&st2));
82 ASSERT (utimecmp (BASE "file", &st1, &st2, 0) == 0);
83
84
85 {
86 struct utimbuf ts;
87 ts.actime = ts.modtime = Y2K;
88 ASSERT (utime (BASE "file", &ts) == 0);
89 ASSERT (stat (BASE "file", &st2) == 0);
90 ASSERT (st2.st_atime == Y2K);
91 ASSERT (0 <= get_stat_atime_ns (&st2));
92 ASSERT (get_stat_atime_ns (&st2) < BILLION / 2);
93 ASSERT (st2.st_mtime == Y2K);
94 ASSERT (0 <= get_stat_mtime_ns (&st2));
95 ASSERT (get_stat_mtime_ns (&st2) < BILLION);
96 if (check_ctime)
97 ASSERT (ctime_compare (&st1, &st2) < 0);
98 }
99
100
101 if (symlink (BASE "file", BASE "link"))
102 {
103 ASSERT (unlink (BASE "file") == 0);
104 if (print)
105 fputs ("skipping test: symlinks not supported on this file system\n",
106 stderr);
107 return 77;
108 }
109 ASSERT (lstat (BASE "link", &st1) == 0);
110 ASSERT (st1.st_mtime != Y2K);
111 errno = 0;
112 ASSERT (utime (BASE "link/", NULL) == -1);
113 ASSERT (errno == ENOTDIR);
114 {
115 struct utimbuf ts;
116 ts.actime = ts.modtime = Y2K;
117 ASSERT (utime (BASE "link", &ts) == 0);
118 ASSERT (lstat (BASE "link", &st2) == 0);
119
120 ASSERT (st1.st_mtime == st2.st_mtime);
121 ASSERT (stat (BASE "link", &st2) == 0);
122 ASSERT (st2.st_mtime == Y2K);
123 ASSERT (get_stat_mtime_ns (&st2) == 0);
124 }
125
126
127 ASSERT (unlink (BASE "link") == 0);
128 ASSERT (unlink (BASE "file") == 0);
129 return 0;
130 }
131
132 int
133 main (void)
134 {
135 int result1;
136
137
138 ignore_value (system ("rm -rf " BASE "*"));
139
140 result1 = test_utime (true);
141 return result1;
142 }