This repository was archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utime.c
More file actions
94 lines (84 loc) · 2.51 KB
/
test_utime.c
File metadata and controls
94 lines (84 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <utime.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include "tests.h"
static void test_utime_call(const char *name, const struct utimbuf *t)
{
int result = utime(name, t);
if (result)
test_failure(1, "utime('%s', a=%lld m=%lld) returned %d", name, (long long) (t->actime), (long long) (t->modtime), result);
else
test_success();
}
void test_utime(void)
{
test_begin("Creating /utime.null");
int fd1 = open("/utime.null", O_CREAT);
if (fd1 < 0)
{
test_failure(1, "open('/utime.null') returned %d", fd1);
return;
}
close(fd1);
test_success();
test_begin("Call utimes(NULL) on /utime.null");
test_utime_call("/utime.null", NULL);
test_begin("Creating /utime.n2038");
fd1 = open("/utime.n2038", O_CREAT);
if (fd1 < 0)
{
test_failure(1, "open('/utime.n2038') returned %d", fd1);
return;
}
close(fd1);
test_success();
test_begin("Call utime(Y2038-2, Y2038-1) on /utime.n2038");
const struct utimbuf t1 = { 0x7FFFFFFE, 0x7FFFFFFF };
test_utime_call("/utime.n2038", &t1);
test_begin("Check stat of /utime.n2038");
struct stat st1;
int result = stat("/utime.n2038", &st1);
if (result)
test_failure(1, "stat('/utime.n2038') returned %d", result);
else if (st1.st_atim.tv_sec != t1.actime || st1.st_mtim.tv_sec != t1.modtime)
{
test_failure(0, "utime returned a=%lld m=%lld, expected a=%lld m=%lld",
(long long int) st1.st_atim.tv_sec,
(long long int) st1.st_mtim.tv_sec,
(long long int) t1.actime,
(long long int) t1.modtime);
}
else
test_success();
test_begin("Creating /utime.y2038");
fd1 = open("/utime.y2038", O_CREAT);
if (fd1 < 0)
{
test_failure(1, "open('/utime.y2038') returned %d", fd1);
return;
}
close(fd1);
test_success();
test_begin("Call utime(Y2038+1, Y2038+2) on /utime.y2038");
const struct utimbuf t2 = { 0x80000001ull, 0x80000002ull };
test_utime_call("/utime.y2038", &t2);
test_begin("Check stat of /utime.y2038");
struct stat st2;
result = stat("/utime.y2038", &st2);
if (result)
test_failure(1, "stat returned %d", result);
else if (st2.st_atim.tv_sec != t2.actime || st2.st_mtim.tv_sec != t2.modtime)
{
test_failure(0, "utime returned a=%lld m=%lld, expected a=%lld m=%lld",
(long long int) st2.st_atim.tv_sec,
(long long int) st2.st_mtim.tv_sec,
(long long int) t2.actime,
(long long int) t2.modtime);
}
else test_success();
}