sbase/printenv.c
Laslo Hunhold e92a1aef54 Handle { NULL } argv[] properly in manual arg-reduction
Thanks izabera for reporting this!
2017-08-05 23:50:39 +02:00

31 lines
486 B
C

/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
extern char **environ;
int
main(int argc, char *argv[])
{
char *var;
int ret = 0;
argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc) {
for (; *environ; environ++)
puts(*environ);
} else {
for (; *argv; argc--, argv++) {
if ((var = getenv(*argv)))
puts(var);
else
ret = 1;
}
}
return fshut(stdout, "<stdout>") ? 2 : ret;
}