[hackers] [sbase] Audit env(1) || FRIGN

From: <git_AT_suckless.org>
Date: Tue, 3 Mar 2015 14:32:25 +0100 (CET)

commit aa0db75be7d9d1ed99b419505abe0db640d77b46
Author: FRIGN <dev_AT_frign.de>
Date: Mon Mar 2 14:50:43 2015 +0100

    Audit env(1)
    
    1) Shorten synopsis and reflect this in the manual
    2) Use argv0 in usage()
    3) Decrement argc in argv-loop for consistency
    4) Make it clearer which error-code results from which errno in enprintf
    5) Use idiomatic for-loop also for environ. Don't increment these pointers
       in the loop itself!

diff --git a/README b/README
index 8f09017..136a2b7 100644
--- a/README
+++ b/README
_AT_@ -27,7 +27,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
 =*| dirname yes none
 =* du yes none
 =*| echo yes none
-=* env yes none
+=*| env yes none
 #* expand yes none
 #* expr yes none
 =*| false yes none
diff --git a/env.1 b/env.1
index 6c2903d..7d4a9a8 100644
--- a/env.1
+++ b/env.1
_AT_@ -1,4 +1,4 @@
-.Dd January 24, 2015
+.Dd March 1, 2015
 .Dt ENV 1
 .Os sbase
 .Sh NAME
_AT_@ -7,15 +7,15 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl i
-.Oo Fl u Ar variable Oc ...
-.Oo Ar variable Ns = Ns Ar value Oc ...
+.Oo Fl u Ar var Oc ...
+.Oo Ar var Ns = Ns Ar value Oc ...
 .Oo Ar cmd Oo arg ... Oc Oc
 .Sh DESCRIPTION
 .Nm
 unsets each
-.Ar variable ,
+.Ar var ,
 then adds or sets each
-.Ar ( variable , value )
+.Ar ( var , value )
 tuple in the environment.
 .Pp
 If
_AT_@ -28,11 +28,11 @@ otherwise, the modified environment is printed to stdout.
 Completely ignore the existing environment and execute
 .Ar cmd
 only with each
-.Ar ( variable , value )
+.Ar ( var , value )
 tuple specified.
-.It Fl u Ar variable
+.It Fl u Ar var
 Unset
-.Ar variable
+.Ar var
 in the environment.
 .El
 .Sh SEE ALSO
diff --git a/env.c b/env.c
index 2b00902..971514b 100644
--- a/env.c
+++ b/env.c
_AT_@ -12,7 +12,7 @@ extern char **environ;
 static void
 usage(void)
 {
- eprintf("usage: env [-i] [-u variable] ... [variable=value] ... [cmd [arg ...]]\n");
+ eprintf("usage: %s [-i] [-u var] ... [var=value] ... [cmd [arg ...]]\n", argv0);
 }
 
 int
_AT_@ -30,16 +30,16 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
- for (; *argv && strchr(*argv, '='); argv++)
+ for (; *argv && strchr(*argv, '='); argc--, argv++)
                 putenv(*argv);
 
         if (*argv) {
                 execvp(*argv, argv);
- enprintf(127 - (errno != EEXIST), "env: '%s':", *argv);
+ enprintf(126 + (errno == EEXIST), "execvp: %s:", *argv);
         }
 
- while (environ && *environ)
- printf("%s\n", *environ++);
+ for (; environ && *environ; environ++)
+ puts(*environ);
 
         return 0;
 }
Received on Tue Mar 03 2015 - 14:32:25 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 03 2015 - 14:36:21 CET