Dmitry V. Levin | 9514ac7 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 1 | #include "defs.h" |
| 2 | |
| 3 | #include <fcntl.h> |
Felix Janda | d34e00b | 2015-03-28 18:21:09 +0100 | [diff] [blame^] | 4 | #include <sys/stat.h> |
Dmitry V. Levin | 9514ac7 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 5 | |
| 6 | #include "xlat/modetypes.h" |
| 7 | |
| 8 | const char * |
| 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 | } |