svn commit: trunk/busybox/coreutils

vda at busybox.net vda at busybox.net
Mon Aug 6 02:55:43 UTC 2007


Author: vda
Date: 2007-08-05 19:55:41 -0700 (Sun, 05 Aug 2007)
New Revision: 19408

Log:
env: micro-optimization
printenv: fix "printenv VAR1 VAR2" bug (wasn't printing VAR2)
(spotted by kalyanatejaswi balabhadrapatruni <kalyanatejaswi at 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



Modified:
   trunk/busybox/coreutils/env.c
   trunk/busybox/coreutils/printenv.c


Changeset:
Modified: trunk/busybox/coreutils/env.c
===================================================================
--- trunk/busybox/coreutils/env.c	2007-08-06 02:36:35 UTC (rev 19407)
+++ trunk/busybox/coreutils/env.c	2007-08-06 02:55:41 UTC (rev 19408)
@@ -63,7 +63,7 @@
 	if (opt & 1) {
 		cleanenv[0] = NULL;
 		environ = cleanenv;
-	} else if (opt & 2) {
+	} else {
 		while (unset_env) {
 			unsetenv(unset_env->data);
 			unset_env = unset_env->link;

Modified: trunk/busybox/coreutils/printenv.c
===================================================================
--- trunk/busybox/coreutils/printenv.c	2007-08-06 02:36:35 UTC (rev 19407)
+++ trunk/busybox/coreutils/printenv.c	2007-08-06 02:55:41 UTC (rev 19408)
@@ -14,25 +14,20 @@
 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);




More information about the busybox-cvs mailing list