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
|
#include <u.h>
#include <libc.h>
static char *modes[] =
{
"---",
"--x",
"-w-",
"-wx",
"r--",
"r-x",
"rw-",
"rwx",
};
static void
rwx(long m, char *s)
{
strncpy(s, modes[m], 3);
}
int
dirmodefmt(Fmt *f)
{
static char buf[16];
ulong m;
m = va_arg(f->args, ulong);
if(m & DMDIR)
buf[0]='d';
else if(m & DMAPPEND)
buf[0]='a';
else if(m & DMAUTH)
buf[0]='A';
else if(m & DMDEVICE)
buf[0] = 'D';
else if(m & DMSOCKET)
buf[0] = 'S';
else if(m & DMNAMEDPIPE)
buf[0] = 'P';
else
buf[0]='-';
/*
* It's a little weird to have DMSYMLINK conflict with DMEXCL
* here, but since you can have symlinks to any of the above
* things, this is a better display. Especially since we don't do
* DMEXCL on any of the supported systems.
*/
if(m & DMEXCL)
buf[1]='l';
else if(m & DMSYMLINK)
buf[1] = 'L';
else
buf[1]='-';
rwx((m>>6)&7, buf+2);
rwx((m>>3)&7, buf+5);
rwx((m>>0)&7, buf+8);
buf[11] = 0;
return fmtstrcpy(f, buf);
}
|