nnn.c | 26 ++++++++++++++++++++++++-- diff --git a/nnn.c b/nnn.c index db3a516db46a10d973f4cd34920db490e45fca97..cdb45403c7ada21629577a50a21729303cf95241 100644 --- a/nnn.c +++ b/nnn.c @@ -279,6 +279,7 @@ #define NLAY 3 #define ATOOL 4 #define APACK 5 #define VIDIR 6 +#define UNKNOWN 7 /* Utilities to open files, run actions */ static char * const utils[] = { @@ -294,7 +295,8 @@ #endif "nlay", "atool", "apack", - "vidir" + "vidir", + "UNKNOWN" }; /* Common strings */ @@ -1729,6 +1731,26 @@ return NULL; } +static char * +xgetpwuid(uid_t uid) +{ + struct passwd *pwd = getpwuid(uid); + if (!pwd) + return utils[7]; + + return pwd->pw_name; +} + +static char * +xgetgrgid(gid_t gid) +{ + struct group *grp = getgrgid(gid); + if (!grp) + return utils[7]; + + return grp->gr_name; +} + /* * Follows the stat(1) output closely */ @@ -1788,7 +1810,7 @@ dprintf(fd, " Device type: %x,%x", major(sb->st_rdev), minor(sb->st_rdev)); /* Show permissions, owner, group */ dprintf(fd, "\n Access: 0%d%d%d/%s Uid: (%u/%s) Gid: (%u/%s)", (sb->st_mode >> 6) & 7, (sb->st_mode >> 3) & 7, - sb->st_mode & 7, perms, sb->st_uid, (getpwuid(sb->st_uid))->pw_name, sb->st_gid, (getgrgid(sb->st_gid))->gr_name); + sb->st_mode & 7, perms, sb->st_uid, xgetpwuid(sb->st_uid), sb->st_gid, xgetgrgid(sb->st_gid)); /* Show last access time */ strftime(g_buf, 40, messages[STR_DATE_ID], localtime(&sb->st_atime));