[BusyBox] [PATCH] Unnecessary dups

Felipe Kellermann stdfk at terra.com.br
Sun Sep 5 06:03:30 UTC 2004


Seeing the last patch Tito sent I grepped the source for unnecessary 
bb_xstrdups (or strdups); this patch removes these.  Gives some size 
optimization and less complexity on unnecessary duppings.

-- 
Felipe Kellermann
-------------- next part --------------
Index: loginutils/getty.c
===================================================================
RCS file: /var/cvs/busybox/loginutils/getty.c,v
retrieving revision 1.15
diff -u -3 -p -Iusage.h -r1.15 getty.c
--- loginutils/getty.c	26 Aug 2004 22:26:26 -0000	1.15
+++ loginutils/getty.c	5 Sep 2004 05:50:45 -0000
@@ -384,9 +384,7 @@ static void parse_args(int argc, char **
 	while (isascii(c = getopt(argc, argv, "I:LH:f:hil:mt:wn"))) {
 		switch (c) {
 		case 'I':
-			if (!(op->initstring = strdup(optarg)))
-				error(bb_msg_memory_exhausted);
-
+			op->initstring = optarg;
 			{
 				const char *p;
 				char *q;
Index: modutils/insmod.c
===================================================================
RCS file: /var/cvs/busybox/modutils/insmod.c,v
retrieving revision 1.125
diff -u -3 -p -Iusage.h -r1.125 insmod.c
--- modutils/insmod.c	2 Sep 2004 23:03:25 -0000	1.125
+++ modutils/insmod.c	5 Sep 2004 05:51:03 -0000
@@ -3681,7 +3681,7 @@ extern int insmod_main( int argc, char *
 					break;
 				case 'o':			/* name the output module */
 					free(m_name);
-					m_name = bb_xstrdup(optarg);
+					m_name = optarg;
 					break;
 				case 'L':			/* Stub warning */
 					/* This is needed for compatibility with modprobe.
Index: networking/ifupdown.c
===================================================================
RCS file: /var/cvs/busybox/networking/ifupdown.c,v
retrieving revision 1.50
diff -u -3 -p -Iusage.h -r1.50 ifupdown.c
--- networking/ifupdown.c	30 Jul 2004 14:45:08 -0000	1.50
+++ networking/ifupdown.c	5 Sep 2004 05:51:11 -0000
@@ -1219,7 +1219,7 @@ extern int ifupdown_main(int argc, char 
 		{
 			switch (i) {
 				case 'i':	/* interfaces */
-					interfaces = bb_xstrdup(optarg);
+					interfaces = optarg;
 					break;
 				case 'v':	/* verbose */
 					verbose = 1;
Index: networking/telnet.c
===================================================================
RCS file: /var/cvs/busybox/networking/telnet.c,v
retrieving revision 1.43
diff -u -3 -p -Iusage.h -r1.43 telnet.c
--- networking/telnet.c	15 Mar 2004 08:28:50 -0000	1.43
+++ networking/telnet.c	5 Sep 2004 05:51:22 -0000
@@ -663,7 +663,7 @@ extern int telnet_main(int argc, char** 
 	while ((opt = getopt(argc, argv, "al:")) != EOF) {
 		switch (opt) {
 			case 'l':
-				autologin = bb_xstrdup(optarg);
+				autologin = optarg;
 				break;
 			case 'a':
 				autologin = getenv("USER");
Index: networking/telnetd.c
===================================================================
RCS file: /var/cvs/busybox/networking/telnetd.c,v
retrieving revision 1.12
diff -u -3 -p -Iusage.h -r1.12 telnetd.c
--- networking/telnetd.c	22 Jun 2004 10:07:17 -0000	1.12
+++ networking/telnetd.c	5 Sep 2004 05:51:22 -0000
@@ -401,10 +401,10 @@ telnetd_main(int argc, char **argv)
 		if (c == EOF) break;
 		switch (c) {
 			case 'f':
-				issuefile = strdup (optarg);
+				issuefile = optarg;
 				break;
 			case 'l':
-				loginpath = strdup (optarg);
+				loginpath = optarg;
 				break;
 #ifndef CONFIG_FEATURE_TELNETD_INETD
 			case 'p':
Index: networking/tftp.c
===================================================================
RCS file: /var/cvs/busybox/networking/tftp.c,v
retrieving revision 1.28
diff -u -3 -p -Iusage.h -r1.28 tftp.c
--- networking/tftp.c	22 Jun 2004 10:18:30 -0000	1.28
+++ networking/tftp.c	5 Sep 2004 05:51:22 -0000
@@ -538,10 +538,10 @@ int tftp_main(int argc, char **argv)
 			break;
 #endif
 		case 'l':
-			localfile = bb_xstrdup(optarg);
+			localfile = optarg;
 			break;
 		case 'r':
-			remotefile = bb_xstrdup(optarg);
+			remotefile = optarg;
 			break;
 		}
 	}
Index: sysklogd/syslogd.c
===================================================================
RCS file: /var/cvs/busybox/sysklogd/syslogd.c,v
retrieving revision 1.115
diff -u -3 -p -Iusage.h -r1.115 syslogd.c
--- sysklogd/syslogd.c	2 Sep 2004 22:22:17 -0000	1.115
+++ sysklogd/syslogd.c	5 Sep 2004 05:51:29 -0000
@@ -642,7 +642,7 @@ extern int syslogd_main(int argc, char *
 #endif
 #ifdef CONFIG_FEATURE_REMOTE_LOG
 		case 'R':
-			RemoteHost = bb_xstrdup(optarg);
+			RemoteHost = optarg;
 			if ((p = strchr(RemoteHost, ':'))) {
 				RemotePort = atoi(p + 1);
 				*p = '\0';
Index: util-linux/getopt.c
===================================================================
RCS file: /var/cvs/busybox/util-linux/getopt.c,v
retrieving revision 1.13
diff -u -3 -p -Iusage.h -r1.13 getopt.c
--- util-linux/getopt.c	14 Apr 2004 17:51:38 -0000	1.13
+++ util-linux/getopt.c	5 Sep 2004 05:52:26 -0000
@@ -340,14 +340,14 @@ int getopt_main(int argc, char *argv[])
                         break;
                 case 'o':
                        free(optstr);
-                       optstr=bb_xstrdup(optarg);
+                       optstr = optarg;
                         break;
                 case 'l':
                         add_long_options(optarg);
                         break;
                 case 'n':
                        free(name);
-                       name=bb_xstrdup(optarg);
+                       name = optarg;
                         break;
                 case 'q':
                         quiet_errors=1;


More information about the busybox mailing list