aboutsummaryrefslogtreecommitdiff
path: root/coreutils/printenv.c
diff options
context:
space:
mode:
authorGravatar Denis Vlasenko <vda.linux@googlemail.com>2007-08-06 02:55:41 +0000
committerGravatar Denis Vlasenko <vda.linux@googlemail.com>2007-08-06 02:55:41 +0000
commite013475830b2399e31f5e17758dd6674b6b60058 (patch)
treead53b26765c6f24e4994402c3a0be899f16219e0 /coreutils/printenv.c
parent84d71f33f5f0201e15bb07d523cef711cd8ef44f (diff)
downloadbusybox-e013475830b2399e31f5e17758dd6674b6b60058.tar.gz
busybox-e013475830b2399e31f5e17758dd6674b6b60058.tar.bz2
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
Diffstat (limited to 'coreutils/printenv.c')
-rw-r--r--coreutils/printenv.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/coreutils/printenv.c b/coreutils/printenv.c
index 2531d5a23..19fa832c8 100644
--- a/coreutils/printenv.c
+++ b/coreutils/printenv.c
@@ -14,25 +14,20 @@ extern char **environ;
int printenv_main(int argc, char **argv);
int printenv_main(int argc, char **argv)
{
- int e = 0;
-
/* no variables specified, show whole env */
- if (argc == 1)
+ if (argc == 1) {
+ int e = 0;
while (environ[e])
puts(environ[e++]);
-
- /* search for specified variables and print them out if found */
- else {
- int i;
- size_t l;
+ } else {
+ /* search for specified variables and print them out if found */
char *arg, *env;
- for (i=1; (arg = argv[i]); ++i)
- for (; (env = environ[e]); ++e) {
- l = strlen(arg);
- if (!strncmp(env, arg, l) && env[l] == '=')
- puts(env + l + 1);
- }
+ while ((arg = *++argv) != NULL) {
+ env = getenv(arg);
+ if (env)
+ puts(env);
+ }
}
fflush_stdout_and_exit(0);