sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit e3c62682ff4c47e303d398074bec989eaa54aae3
parent 81f9cf2a33ddda691a774f96b4280e3a00de6f28
Author: sin <sin@2f30.org>
Date:   Sat Apr  5 19:22:56 +0100

Don't bail out if the username/group name does not exist in ls(1)

Diffstat:
ls.c | 22++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/ls.c b/ls.c @@ -218,6 +218,8 @@ output(Entry *ent) ssize_t len; struct group *gr; struct passwd *pw; + char pwname[_SC_LOGIN_NAME_MAX]; + char grname[_SC_LOGIN_NAME_MAX]; Entry entlnk; if (iflag) @@ -259,17 +261,17 @@ output(Entry *ent) errno = 0; pw = getpwuid(ent->uid); - if(errno) - eprintf("getpwuid %d:", ent->uid); - else if(!pw) - eprintf("getpwuid %d: no such user\n", ent->uid); + if(errno || !pw) + snprintf(pwname, sizeof(pwname), "%d", ent->uid); + else + snprintf(pwname, sizeof(pwname), "%s", pw->pw_name); errno = 0; gr = getgrgid(ent->gid); - if(errno) - eprintf("getgrgid %d:", ent->gid); - else if(!gr) - eprintf("getgrgid %d: no such group\n", ent->gid); + if(errno || !gr) + snprintf(grname, sizeof(grname), "%d", ent->gid); + else + snprintf(grname, sizeof(grname), "%s", gr->gr_name); if(time(NULL) > ent->mtime + (180*24*60*60)) /* 6 months ago? */ fmt = "%b %d %Y"; @@ -277,8 +279,8 @@ output(Entry *ent) fmt = "%b %d %H:%M"; strftime(buf, sizeof buf, fmt, localtime(&ent->mtime)); - printf("%s %2ld %-4s %-5s %6lu %s %s%s", mode, (long)ent->nlink, pw->pw_name, - gr->gr_name, (unsigned long)ent->size, buf, ent->name, indicator(ent->mode)); + printf("%s %2ld %-4s %-5s %6lu %s %s%s", mode, (long)ent->nlink, pwname, + grname, (unsigned long)ent->size, buf, ent->name, indicator(ent->mode)); if(S_ISLNK(ent->mode)) { if((len = readlink(ent->name, buf, sizeof buf)) == -1) eprintf("readlink %s:", ent->name);