dirmodefmt.c - 9base - revived minimalist port of Plan 9 userland to Unix | |
git clone git://git.suckless.org/9base | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
dirmodefmt.c (969B) | |
--- | |
1 #include <u.h> | |
2 #include <libc.h> | |
3 | |
4 static char *modes[] = | |
5 { | |
6 "---", | |
7 "--x", | |
8 "-w-", | |
9 "-wx", | |
10 "r--", | |
11 "r-x", | |
12 "rw-", | |
13 "rwx", | |
14 }; | |
15 | |
16 static void | |
17 rwx(long m, char *s) | |
18 { | |
19 strncpy(s, modes[m], 3); | |
20 } | |
21 | |
22 int | |
23 dirmodefmt(Fmt *f) | |
24 { | |
25 static char buf[16]; | |
26 ulong m; | |
27 | |
28 m = va_arg(f->args, ulong); | |
29 | |
30 if(m & DMDIR) | |
31 buf[0]='d'; | |
32 else if(m & DMAPPEND) | |
33 buf[0]='a'; | |
34 else if(m & DMAUTH) | |
35 buf[0]='A'; | |
36 else if(m & DMDEVICE) | |
37 buf[0] = 'D'; | |
38 else if(m & DMSOCKET) | |
39 buf[0] = 'S'; | |
40 else if(m & DMNAMEDPIPE) | |
41 buf[0] = 'P'; | |
42 else | |
43 buf[0]='-'; | |
44 | |
45 /* | |
46 * It's a little weird to have DMSYMLINK conflict with DMEXCL | |
47 * here, but since you can have symlinks to any of the above | |
48 * things, this is a better display. Especially since we don't … | |
49 * DMEXCL on any of the supported systems. | |
50 */ | |
51 if(m & DMEXCL) | |
52 buf[1]='l'; | |
53 else if(m & DMSYMLINK) | |
54 buf[1] = 'L'; | |
55 else | |
56 buf[1]='-'; | |
57 rwx((m>>6)&7, buf+2); | |
58 rwx((m>>3)&7, buf+5); | |
59 rwx((m>>0)&7, buf+8); | |
60 buf[11] = 0; | |
61 return fmtstrcpy(f, buf); | |
62 } |