MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / test

Function test

test/stat/test_chmod.c:45–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45void test() {
46 int err;
47 time_t lastctime;
48 time_t lastmtime;
49 struct stat s;
50
51 //
52 // chmod()ing a file should change metadata modification time (ctime),
53 // but not the file modification time (mtime)
54 //
55 // get the current ctime for the file
56 memset(&s, 0, sizeof s);
57 stat("file", &s);
58 lastctime = s.st_ctime;
59 lastmtime = s.st_mtime;
60 sleep(1);
61
62 // do the actual chmod
63 err = chmod("file", S_IWUSR);
64 assert(!err);
65
66 memset(&s, 0, sizeof s);
67 stat("file", &s);
68 assert(s.st_mode == (S_IWUSR | S_IFREG));
69 assert(s.st_ctime != lastctime);
70 assert(s.st_mtime == lastmtime);
71
72 //
73 // fchmod()ing a file should change metadata modification time,
74 // but not the file modification time
75 //
76 lastctime = s.st_ctime;
77 lastmtime = s.st_mtime;
78 sleep(1);
79
80 err = fchmod(open("file", O_WRONLY), S_IXUSR);
81 assert(!err);
82
83 memset(&s, 0, sizeof s);
84 stat("file", &s);
85 assert(s.st_mode == (S_IXUSR | S_IFREG));
86 assert(s.st_ctime != lastctime);
87 assert(s.st_mtime == lastmtime);
88
89 //
90 // fchmodat()ing a file should also only change metadata modification time,
91 // but not the file modification time.
92 //
93 memset(&s, 0, sizeof s);
94 stat("otherfile", &s);
95 lastctime = s.st_ctime;
96 lastmtime = s.st_mtime;
97 sleep(1);
98 err = fchmodat(AT_FDCWD, "otherfile", S_IXUSR, 0);
99 assert(!err);
100
101 assert(symlink("otherfile", "link") == 0);
102 err = fchmodat(AT_FDCWD, "link", S_IXGRP, AT_SYMLINK_NOFOLLOW);

Callers 1

mainFunction · 0.70

Calls 15

memsetFunction · 0.85
printfFunction · 0.85
strerrorFunction · 0.85
putsFunction · 0.85
statClass · 0.70
sleepFunction · 0.50
chmodFunction · 0.50
assertFunction · 0.50
fchmodFunction · 0.50
openFunction · 0.50
fchmodatFunction · 0.50
symlinkFunction · 0.50

Tested by

no test coverage detected