diff options
Diffstat (limited to 'src/nnn.c')
-rw-r--r-- | src/nnn.c | 32 |
1 files changed, 12 insertions, 20 deletions
@@ -2783,47 +2783,39 @@ static char *coolsize(off_t size) return size_buf; } -static char get_fileind(mode_t mode) +/* Convert a mode field into "ls -l" type perms field. */ +static char *get_lsperms(mode_t mode) { - char c = '\0'; + static const char * const rwx[] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"}; + static char bits[11] = {'\0'}; switch (mode & S_IFMT) { case S_IFREG: - c = '-'; + bits[0] = '-'; break; case S_IFDIR: - c = 'd'; + bits[0] = 'd'; break; case S_IFLNK: - c = 'l'; + bits[0] = 'l'; break; case S_IFSOCK: - c = 's'; + bits[0] = 's'; break; case S_IFIFO: - c = 'p'; + bits[0] = 'p'; break; case S_IFBLK: - c = 'b'; + bits[0] = 'b'; break; case S_IFCHR: - c = 'c'; + bits[0] = 'c'; break; default: - c = '?'; + bits[0] = '?'; break; } - return c; -} - -/* Convert a mode field into "ls -l" type perms field. */ -static char *get_lsperms(mode_t mode) -{ - static const char * const rwx[] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"}; - static char bits[11] = {'\0'}; - - bits[0] = get_fileind(mode); xstrlcpy(&bits[1], rwx[(mode >> 6) & 7], 4); xstrlcpy(&bits[4], rwx[(mode >> 3) & 7], 4); xstrlcpy(&bits[7], rwx[(mode & 7)], 4); |