Last change
on this file since 3868 was 3232, checked in by Bruno Cornec, 11 years ago |
- Update mindi-busybox to 1.21.1
|
File size:
1.2 KB
|
Rev | Line | |
---|
[1765] | 1 | /* vi: set sw=4 ts=4: */
|
---|
[821] | 2 | /*
|
---|
| 3 | * printenv implementation for busybox
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2005 by Erik Andersen <andersen@codepoet.org>
|
---|
| 6 | * Copyright (C) 2005 by Mike Frysinger <vapier@gentoo.org>
|
---|
| 7 | *
|
---|
[2725] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
---|
[821] | 9 | */
|
---|
| 10 |
|
---|
[3232] | 11 | //usage:#define printenv_trivial_usage
|
---|
| 12 | //usage: "[VARIABLE]..."
|
---|
| 13 | //usage:#define printenv_full_usage "\n\n"
|
---|
| 14 | //usage: "Print environment VARIABLEs.\n"
|
---|
| 15 | //usage: "If no VARIABLE specified, print all."
|
---|
| 16 |
|
---|
[1765] | 17 | #include "libbb.h"
|
---|
[821] | 18 |
|
---|
[2725] | 19 | /* This is a NOFORK applet. Be very careful! */
|
---|
| 20 |
|
---|
| 21 | int printenv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
---|
| 22 | int printenv_main(int argc UNUSED_PARAM, char **argv)
|
---|
[821] | 23 | {
|
---|
[2725] | 24 | int exit_code = EXIT_SUCCESS;
|
---|
| 25 |
|
---|
[821] | 26 | /* no variables specified, show whole env */
|
---|
[2725] | 27 | if (!argv[1]) {
|
---|
[3232] | 28 | char **e = environ;
|
---|
| 29 |
|
---|
| 30 | /* environ can be NULL! (for example, after clearenv())
|
---|
| 31 | * Check for that:
|
---|
| 32 | */
|
---|
| 33 | if (e)
|
---|
| 34 | while (*e)
|
---|
| 35 | puts(*e++);
|
---|
[1765] | 36 | } else {
|
---|
| 37 | /* search for specified variables and print them out if found */
|
---|
[821] | 38 | char *arg, *env;
|
---|
| 39 |
|
---|
[1765] | 40 | while ((arg = *++argv) != NULL) {
|
---|
| 41 | env = getenv(arg);
|
---|
| 42 | if (env)
|
---|
| 43 | puts(env);
|
---|
[2725] | 44 | else
|
---|
| 45 | exit_code = EXIT_FAILURE;
|
---|
[1765] | 46 | }
|
---|
[821] | 47 | }
|
---|
| 48 |
|
---|
[2725] | 49 | fflush_stdout_and_exit(exit_code);
|
---|
[821] | 50 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.