-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_mode.c
executable file
·62 lines (52 loc) · 1.02 KB
/
print_mode.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifdef CS333_P5
// this is an ugly series of if statements but it works
void
print_mode(struct stat* st)
{
switch (st->type) {
case T_DIR: printf(1, "d"); break;
case T_FILE: printf(1, "-"); break;
case T_DEV: printf(1, "c"); break;
default: printf(1, "?");
}
if (st->mode.flags.u_r)
printf(1, "r");
else
printf(1, "-");
if (st->mode.flags.u_w)
printf(1, "w");
else
printf(1, "-");
if ((st->mode.flags.u_x) & (st->mode.flags.setuid))
printf(1, "S");
else if (st->mode.flags.u_x)
printf(1, "x");
else
printf(1, "-");
if (st->mode.flags.g_r)
printf(1, "r");
else
printf(1, "-");
if (st->mode.flags.g_w)
printf(1, "w");
else
printf(1, "-");
if (st->mode.flags.g_x)
printf(1, "x");
else
printf(1, "-");
if (st->mode.flags.o_r)
printf(1, "r");
else
printf(1, "-");
if (st->mode.flags.o_w)
printf(1, "w");
else
printf(1, "-");
if (st->mode.flags.o_x)
printf(1, "x");
else
printf(1, "-");
return;
}
#endif