sbase

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

printenv.c (546B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 
      5 #include "util.h"
      6 
      7 extern char **environ;
      8 
      9 static void
     10 usage(void)
     11 {
     12 	eprintf("usage: %s [var ...]\n", argv0);
     13 }
     14 
     15 int
     16 main(int argc, char *argv[])
     17 {
     18 	char *var;
     19 	int ret = 0;
     20 
     21 	ARGBEGIN {
     22 	default:
     23 		usage();
     24 	} ARGEND
     25 
     26 	if (!argc) {
     27 		for (; *environ; environ++)
     28 			puts(*environ);
     29 	} else {
     30 		for (; *argv; argc--, argv++) {
     31 			if ((var = getenv(*argv)))
     32 				puts(var);
     33 			else
     34 				ret = 1;
     35 		}
     36 	}
     37 
     38 	return fshut(stdout, "<stdout>") ? 2 : ret;
     39 }