[hackers] [ubase] errno: check only errno if return value was NULL || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Wed, 09 Jul 2014 16:07:37 +0200

commit 96f15f1d049bcecee159196131d2296ed7d39584
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Wed Jul 9 14:56:02 2014 +0000

    errno: check only errno if return value was NULL

diff --git a/id.c b/id.c
index 32ad42d..6d60139 100644
--- a/id.c
+++ b/id.c
_AT_@ -42,7 +42,6 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
- errno = 0;
         switch (argc) {
         case 0:
                 userid(getuid());
_AT_@ -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
", nam);
+ if(!pw) {
+ if (errno)
+ eprintf("getpwnam %s:", nam);
+ else
+ eprintf("getpwnam %s: no such user
", nam);
+ }
         if (Gflag)
                 groupid(pw);
         else
_AT_@ -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
", id);
+ if(!pw) {
+ if (errno)
+ eprintf("getpwuid %d:", id);
+ else
+ eprintf("getpwuid %d: no such user
", id);
+ }
         if (Gflag)
                 groupid(pw);
         else
diff --git a/su.c b/su.c
index 7690952..5eb9f62 100644
--- a/su.c
+++ b/su.c
_AT_@ -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?
");
+ if(!pw) {
+ if (errno)
+ eprintf("getpwnam: %s:", usr);
+ else
+ eprintf("who are you?
");
+ }
 
         uid = getuid();
         if (uid) {
diff --git a/unshare.c b/unshare.c
index 3bcb581..0df0355 100644
--- a/unshare.c
+++ b/unshare.c
_AT_@ -1,5 +1,4 @@
 /* See LICENSE file for copyright and license details. */
-#include <errno.h>
 #include <sched.h>
 #include <stdio.h>
 #include <stdlib.h>
Received on Wed Jul 09 2014 - 16:07:37 CEST

This archive was generated by hypermail 2.3.0 : Wed Jul 09 2014 - 16:12:08 CEST