Mercurial > hg > toybox
comparison toys/other/printenv.c @ 653:2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 25 Aug 2012 14:25:22 -0500 |
parents | toys/printenv.c@e0eed40f4ab1 |
children | 6df4ccc0acbe |
comparison
equal
deleted
inserted
replaced
652:2d7c56913fda | 653:2986aa63a021 |
---|---|
1 /* vi: set sw=4 ts=4: | |
2 * | |
3 * printenv.c - Print environment variables. | |
4 * | |
5 * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org> | |
6 * | |
7 | |
8 USE_PRINTENV(NEWTOY(printenv, "0(null)", TOYFLAG_USR|TOYFLAG_BIN)) | |
9 | |
10 config PRINTENV | |
11 bool "printenv" | |
12 default y | |
13 help | |
14 usage: printenv [-0] [env_var...] | |
15 | |
16 Print environment variables. | |
17 | |
18 -0 Use \0 as delimiter instead of \n | |
19 */ | |
20 | |
21 #include "toys.h" | |
22 | |
23 extern char **environ; | |
24 | |
25 void printenv_main(void) | |
26 { | |
27 char **env, **var = toys.optargs; | |
28 char delim = '\n'; | |
29 | |
30 if (toys.optflags) delim = 0; | |
31 | |
32 do { | |
33 int catch = 0, len = *var ? strlen(*var) : 0; | |
34 | |
35 for (env = environ; *env; env++) { | |
36 char *out = *env; | |
37 if (*var) { | |
38 if (!strncmp(out, *var, len) && out[len] == '=') | |
39 out += len +1; | |
40 else continue; | |
41 } | |
42 xprintf("%s%c", out, delim); | |
43 catch++; | |
44 } | |
45 if (*var && !catch) toys.exitval = 1; | |
46 } while (*var && *(++var)); | |
47 } |