hush/coreutils/printenv.c
Denis Vlasenko e013475830 env: micro-optimization
printenv: fix "printenv VAR1 VAR2" bug (wasn't printing VAR2)
(spotted by kalyanatejaswi balabhadrapatruni <kalyanatejaswi@yahoo.co.in>)

env_main                                             267     260      -7
printenv_main                                        147      75     -72
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-79)             Total: -79 bytes
   text    data     bss     dec     hex filename
 770336    1096   11228  782660   bf144 busybox_old
 770256    1096   11228  782580   bf0f4 busybox_unstripped
2007-08-06 02:55:41 +00:00

35 lines
750 B
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 tarball for details.
*/
#include "libbb.h"
extern char **environ;
int printenv_main(int argc, char **argv);
int printenv_main(int argc, char **argv)
{
/* no variables specified, show whole env */
if (argc == 1) {
int e = 0;
while (environ[e])
puts(environ[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);
}
}
fflush_stdout_and_exit(0);
}