sbase

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

commit 0226c051056e873d7faa46434b1b012eac59af12
parent 6f715d8c6d8e9d620fce35c57c87851c65b229da
Author: FRIGN <dev@frign.de>
Date:   Sat Feb 28 21:47:17 +0100

Audit printenv(1)

1) argc style
2) safeguard argv-loop as already seen in echo(1) with argc-decrement.

Diffstat:
README | 2+-
echo.c | 2+-
printenv.c | 9+++++----
3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/README b/README @@ -51,7 +51,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support, = nl no -d, -f, -h, -l, -p =* nohup yes none #* paste yes none -=* printenv non-posix none +=*| printenv non-posix none #* printf yes none =* pwd yes none = readlink non-posix none diff --git a/echo.c b/echo.c @@ -23,7 +23,7 @@ main(int argc, char *argv[]) } ARGEND; for (; argc > 0; argc--, argv++) - putword(argv[0]); + putword(*argv); if (!nflag) putchar('\n'); diff --git a/printenv.c b/printenv.c @@ -9,7 +9,7 @@ extern char **environ; static void usage(void) { - eprintf("usage: %s [variable...]\n", argv0); + eprintf("usage: %s [var ...]\n", argv0); } int @@ -23,16 +23,17 @@ main(int argc, char *argv[]) usage(); } ARGEND; - if (argc == 0) { + if (!argc) { while (*environ) printf("%s\n", *environ++); } else { - while (*argv) { - if ((var = getenv(*argv++))) + for (; argc > 0; argc--, argv++) { + if ((var = getenv(*argv))) printf("%s\n", var); else ret = 1; } } + return ret; }