1 #include "defs.h"
2
3 #include <fcntl.h>
4 #include <sys/stat.h>
5
6 #include "xlat/modetypes.h"
7
8 const char *
sprintmode(int mode)9 sprintmode(int mode)
10 {
11 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
12 + sizeof(int)*3
13 + /*paranoia:*/ 8];
14 const char *s;
15
16 if ((mode & S_IFMT) == 0)
17 s = "";
18 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
19 sprintf(buf, "%#o", mode);
20 return buf;
21 }
22 s = buf + sprintf(buf, "%s%s%s%s", s,
23 (mode & S_ISUID) ? "|S_ISUID" : "",
24 (mode & S_ISGID) ? "|S_ISGID" : "",
25 (mode & S_ISVTX) ? "|S_ISVTX" : "");
26 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
27 if (mode)
28 sprintf((char*)s, "|%#o", mode);
29 s = (*buf == '|') ? buf + 1 : buf;
30 return *s ? s : "0";
31 }
32