1 /* vi: set sw=4 ts=4: */
3 * printenv implementation for busybox
5 * Copyright (C) 2005 by Erik Andersen <andersen@codepoet.org>
6 * Copyright (C) 2005 by Mike Frysinger <vapier@gentoo.org>
8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 //config:config PRINTENV
11 //config: bool "printenv (1 kb)"
14 //config: printenv is used to print all or part of environment.
16 //applet:IF_PRINTENV(APPLET_NOFORK(printenv, printenv, BB_DIR_BIN, BB_SUID_DROP, printenv))
18 //kbuild:lib-$(CONFIG_PRINTENV) += printenv.o
20 //usage:#define printenv_trivial_usage
21 //usage: "[VARIABLE]..."
22 //usage:#define printenv_full_usage "\n\n"
23 //usage: "Print environment VARIABLEs.\n"
24 //usage: "If no VARIABLE specified, print all."
28 /* This is a NOFORK applet. Be very careful! */
30 int printenv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
31 int printenv_main(int argc UNUSED_PARAM, char **argv)
33 int exit_code = EXIT_SUCCESS;
35 /* no variables specified, show whole env */
39 /* environ can be NULL! (for example, after clearenv())
46 /* search for specified variables and print them out if found */
49 while ((arg = *++argv) != NULL) {
54 exit_code = EXIT_FAILURE;
58 fflush_stdout_and_exit(exit_code);