[hackers] [sbase] ls: getpwuid, getgrgid, use return code of NULL is an error, not errno || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Mon, 22 Dec 2014 12:28:26 +0100 (CET)

commit 32651cb2da5b04e2fef1eef075374ef79e622ade
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sun Dec 21 22:58:09 2014 +0100

    ls: getpwuid, getgrgid, use return code of NULL is an error, not errno

diff --git a/ls.c b/ls.c
index ef3f5f6..c864295 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -275,17 +275,17 @@ output(Entry *ent)
 
         errno = 0;
         pw = getpwuid(ent->uid);
- if (errno || !pw)
- snprintf(pwname, sizeof(pwname), "%d", ent->uid);
- else
+ if (pw)
                 snprintf(pwname, sizeof(pwname), "%s", pw->pw_name);
+ else
+ snprintf(pwname, sizeof(pwname), "%d", ent->uid);
 
         errno = 0;
         gr = getgrgid(ent->gid);
- if (errno || !gr)
- snprintf(grname, sizeof(grname), "%d", ent->gid);
- else
+ if (gr)
                 snprintf(grname, sizeof(grname), "%s", gr->gr_name);
+ else
+ snprintf(grname, sizeof(grname), "%d", ent->gid);
 
         if (time(NULL) > ent->mtime + (180*24*60*60)) /* 6 months ago? */
                 fmt = "%b %d %Y";
Received on Mon Dec 22 2014 - 12:28:26 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 22 2014 - 12:36:11 CET