-
Notifications
You must be signed in to change notification settings - Fork 6
/
example.c
46 lines (34 loc) · 831 Bytes
/
example.c
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
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <unistd.h>
#include <assert.h>
#include <stdio.h>
int main()
{
struct stat s;
assert(access("dummy", R_OK) == -1);
assert(access("dummy", W_OK) == -1);
assert(access("dummy", X_OK) == -1);
assert(access("dummy", F_OK) == -1);
FILE* f = fopen("dummy", "wb");
assert(f);
fclose(f);
stat("dummy", &s);
assert(S_ISREG(s.st_mode));
assert(!S_ISDIR(s.st_mode));
assert(access("dummy", R_OK) == 0);
assert(access("dummy", W_OK) == 0);
assert(access("dummy", X_OK) == 0);
assert(access("dummy", F_OK) == 0);
unlink("dummy");
int fd2 = dup(STDIN_FILENO);
assert(fd2 != STDIN_FILENO);
close(fd2);
assert(rmdir("temp") == -1);
assert(_mkdir("temp") == 0);
stat("temp", &s);
assert(!S_ISREG(s.st_mode));
assert(S_ISDIR(s.st_mode));
assert(rmdir("temp") == 0);
}