]> granicus.if.org Git - strace/blob - printmode.c
process.c: move sched_setaffinity and sched_getaffinity parsers to a separate file
[strace] / printmode.c
1 #include "defs.h"
2
3 #include <fcntl.h>
4
5 #include "xlat/modetypes.h"
6
7 const char *
8 sprintmode(int mode)
9 {
10         static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
11                         + sizeof(int)*3
12                         + /*paranoia:*/ 8];
13         const char *s;
14
15         if ((mode & S_IFMT) == 0)
16                 s = "";
17         else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
18                 sprintf(buf, "%#o", mode);
19                 return buf;
20         }
21         s = buf + sprintf(buf, "%s%s%s%s", s,
22                 (mode & S_ISUID) ? "|S_ISUID" : "",
23                 (mode & S_ISGID) ? "|S_ISGID" : "",
24                 (mode & S_ISVTX) ? "|S_ISVTX" : "");
25         mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
26         if (mode)
27                 sprintf((char*)s, "|%#o", mode);
28         s = (*buf == '|') ? buf + 1 : buf;
29         return *s ? s : "0";
30 }