1 #include <u.h>
2 #include <libc.h>
3 #include <fcall.h>
4 
5 static char *modes[] =
6 {
7 	"---",
8 	"--x",
9 	"-w-",
10 	"-wx",
11 	"r--",
12 	"r-x",
13 	"rw-",
14 	"rwx",
15 };
16 
17 static void
rwx(long m,char * s)18 rwx(long m, char *s)
19 {
20 	strncpy(s, modes[m], 3);
21 }
22 
23 int
dirmodefmt(Fmt * f)24 dirmodefmt(Fmt *f)
25 {
26 	static char buf[16];
27 	ulong m;
28 
29 	m = va_arg(f->args, ulong);
30 
31 	if(m & DMDIR)
32 		buf[0]='d';
33 	else if(m & DMAPPEND)
34 		buf[0]='a';
35 	else if(m & DMAUTH)
36 		buf[0]='A';
37 	else
38 		buf[0]='-';
39 	if(m & DMEXCL)
40 		buf[1]='l';
41 	else
42 		buf[1]='-';
43 	rwx((m>>6)&7, buf+2);
44 	rwx((m>>3)&7, buf+5);
45 	rwx((m>>0)&7, buf+8);
46 	buf[11] = 0;
47 	return fmtstrcpy(f, buf);
48 }
49