Files
applets
applets_sh
arch
archival
configs
console-tools
coreutils
libcoreutils
Config.src
Kbuild.src
basename.c
cal.c
cat.c
catv.c
chgrp.c
chmod.c
chown.c
chroot.c
cksum.c
comm.c
cp.c
cut.c
date.c
dd.c
df.c
dirname.c
dos2unix.c
du.c
echo.c
env.c
expand.c
expr.c
false.c
fold.c
fsync.c
head.c
hostid.c
id.c
id_test.sh
install.c
length.c.disabled
ln.c
logname.c
ls.c
md5_sha1_sum.c
mkdir.c
mkfifo.c
mknod.c
mv.c
nice.c
nohup.c
od.c
od_bloaty.c
printenv.c
printf.c
pwd.c
readlink.c
realpath.c
rm.c
rmdir.c
seq.c
sleep.c
sort.c
split.c
stat.c
stty.c
sum.c
sync.c
tac.c
tail.c
tee.c
test.c
test_ptr_hack.c
touch.c
tr.c
true.c
tty.c
uname.c
uniq.c
usleep.c
uudecode.c
uuencode.c
wc.c
who.c
whoami.c
yes.c
debianutils
docs
e2fsprogs
editors
examples
findutils
include
init
libbb
libpwdgrp
loginutils
mailutils
miscutils
modutils
networking
printutils
procps
runit
scripts
selinux
shell
sysklogd
testsuite
util-linux
.gitignore
.indent.pro
AUTHORS
Config.in
INSTALL
LICENSE
Makefile
Makefile.custom
Makefile.flags
Makefile.help
README
TODO
TODO_unicode
busybox/coreutils/printenv.c
Pere Orga 34425389e0 move help text from include/usage.src.h to coreutils/*.c
Signed-off-by: Pere Orga <gotrunks@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-03-31 14:43:25 +02:00

51 lines
1.2 KiB
C

/* vi: set sw=4 ts=4: */
/*
* printenv implementation for busybox
*
* Copyright (C) 2005 by Erik Andersen <andersen@codepoet.org>
* Copyright (C) 2005 by Mike Frysinger <vapier@gentoo.org>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//usage:#define printenv_trivial_usage
//usage: "[VARIABLE]..."
//usage:#define printenv_full_usage "\n\n"
//usage: "Print environment VARIABLEs.\n"
//usage: "If no VARIABLE specified, print all."
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
int printenv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int printenv_main(int argc UNUSED_PARAM, char **argv)
{
int exit_code = EXIT_SUCCESS;
/* no variables specified, show whole env */
if (!argv[1]) {
char **e = environ;
/* environ can be NULL! (for example, after clearenv())
* Check for that:
*/
if (e)
while (*e)
puts(*e++);
} else {
/* search for specified variables and print them out if found */
char *arg, *env;
while ((arg = *++argv) != NULL) {
env = getenv(arg);
if (env)
puts(env);
else
exit_code = EXIT_FAILURE;
}
}
fflush_stdout_and_exit(exit_code);
}