util-linux/lsusb.c: print manufacturer/product strings if available
[busybox-git.git] / coreutils / printenv.c
blob0ca9e6114bc87932dc73684b2dd0e02607eccc1c
1 /* vi: set sw=4 ts=4: */
2 /*
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.
9 */
10 //config:config PRINTENV
11 //config: bool "printenv (1.6 kb)"
12 //config: default y
13 //config: help
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."
26 #include "libbb.h"
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 */
36 if (!argv[1]) {
37 char **e = environ;
39 /* environ can be NULL! (for example, after clearenv())
40 * Check for that:
42 if (e)
43 while (*e)
44 puts(*e++);
45 } else {
46 /* search for specified variables and print them out if found */
47 char *arg, *env;
49 while ((arg = *++argv) != NULL) {
50 env = getenv(arg);
51 if (env)
52 puts(env);
53 else
54 exit_code = EXIT_FAILURE;
58 fflush_stdout_and_exit(exit_code);