morpheus-base

morpheus base system
git clone git://git.2f30.org/morpheus-base
Log | Files | Refs

printenv.c (519B)


      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 [variable...]\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 == 0) {
     27 		while (*environ)
     28 			printf("%s\n", *environ++);
     29 	} else {
     30 		while (*argv) {
     31 			if ((var = getenv(*argv++)))
     32 				printf("%s\n", var);
     33 			else
     34 				ret = 1;
     35 		}
     36 	}
     37 	return ret;
     38 }