ubase

suckless linux base utils
git clone git://git.2f30.org/ubase.git
Log | Files | Refs | README | LICENSE

commit 96f15f1d049bcecee159196131d2296ed7d39584
parent 528f10be6c3f38fdb99193e8fff1e810c5ccb1c5
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Wed Jul  9 14:56:02 +0000

errno: check only errno if return value was NULL

Diffstat:
id.c | 21++++++++++++---------
su.c | 10++++++----
unshare.c | 1-
3 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/id.c b/id.c @@ -42,7 +42,6 @@ main(int argc, char *argv[]) usage(); } ARGEND; - errno = 0; switch (argc) { case 0: userid(getuid()); @@ -86,10 +85,12 @@ usernam(const char *nam) errno = 0; pw = getpwnam(nam); - if (errno != 0) - eprintf("getpwnam %s:", nam); - else if (!pw) - eprintf("getpwnam %s: no such user\n", nam); + if(!pw) { + if (errno) + eprintf("getpwnam %s:", nam); + else + eprintf("getpwnam %s: no such user\n", nam); + } if (Gflag) groupid(pw); else @@ -103,10 +104,12 @@ userid(uid_t id) errno = 0; pw = getpwuid(id); - if (errno != 0) - eprintf("getpwuid %d:", id); - else if (!pw) - eprintf("getpwuid %d: no such user\n", id); + if(!pw) { + if (errno) + eprintf("getpwuid %d:", id); + else + eprintf("getpwuid %d: no such user\n", id); + } if (Gflag) groupid(pw); else diff --git a/su.c b/su.c @@ -55,10 +55,12 @@ main(int argc, char *argv[]) errno = 0; pw = getpwnam(usr); - if (errno) - eprintf("getpwnam: %s:", usr); - else if (!pw) - eprintf("who are you?\n"); + if(!pw) { + if (errno) + eprintf("getpwnam: %s:", usr); + else + eprintf("who are you?\n"); + } uid = getuid(); if (uid) { diff --git a/unshare.c b/unshare.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include <errno.h> #include <sched.h> #include <stdio.h> #include <stdlib.h>