sbase/printenv.c

31 lines
486 B
C
Raw Normal View History

/* See LICENSE file for copyright and license details. */
2013-06-09 09:20:55 -04:00
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
2013-06-09 09:20:55 -04:00
extern char **environ;
int
2014-04-18 06:51:18 -04:00
main(int argc, char *argv[])
2013-06-09 09:20:55 -04:00
{
char *var;
int ret = 0;
2013-06-09 09:20:55 -04:00
argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
if (!argc) {
for (; *environ; environ++)
puts(*environ);
2014-11-16 08:11:12 -05:00
} else {
for (; *argv; argc--, argv++) {
if ((var = getenv(*argv)))
puts(var);
else
ret = 1;
2014-11-16 08:11:12 -05:00
}
2013-06-09 09:20:55 -04:00
}
return fshut(stdout, "<stdout>") ? 2 : ret;
2013-06-09 09:20:55 -04:00
}