svn commit: trunk/busybox/findutils

vda at busybox.net vda at busybox.net
Sun Apr 15 08:38:51 UTC 2007


Author: vda
Date: 2007-04-15 01:38:50 -0700 (Sun, 15 Apr 2007)
New Revision: 18447

Log:
xargs: simplify word list management


Modified:
   trunk/busybox/findutils/xargs.c


Changeset:
Modified: trunk/busybox/findutils/xargs.c
===================================================================
--- trunk/busybox/findutils/xargs.c	2007-04-14 19:16:06 UTC (rev 18446)
+++ trunk/busybox/findutils/xargs.c	2007-04-15 08:38:50 UTC (rev 18447)
@@ -83,9 +83,9 @@
 
 
 typedef struct xlist_t {
-	char *data;
-	size_t length;
 	struct xlist_t *link;
+	size_t length;
+	char xstr[1];
 } xlist_t;
 
 static smallint eof_stdin_detected;
@@ -105,7 +105,7 @@
 
 	char *s = NULL;         /* start word */
 	char *p = NULL;         /* pointer to end word */
-	char q = 0;             /* quote char */
+	char q = '\0';          /* quote char */
 	char state = NORM;
 	char eof_str_detected = 0;
 	size_t line_l = 0;      /* size loaded args line */
@@ -135,18 +135,16 @@
 			state = NORM;
 			goto set;
 		} else if (state == QUOTE) {
-			if (c == q) {
-				q = 0;
-				state = NORM;
-			} else {
+			if (c != q)
 				goto set;
-			}
+			q = '\0';
+			state = NORM;
 		} else { /* if (state == NORM) */
 			if (ISSPACE(c)) {
 				if (s) {
-unexpected_eof:
+ unexpected_eof:
 					state = SPACE;
-					c = 0;
+					c = '\0';
 					goto set;
 				}
 			} else {
@@ -158,7 +156,7 @@
 					q = c;
 					state = QUOTE;
 				} else {
-set:
+ set:
 					if ((size_t)(p - buf) >= mc)
 						bb_error_msg_and_die("argument line too long");
 					*p++ = c;
@@ -176,11 +174,11 @@
 			}
 			if (!eof_str_detected) {
 				size_t length = (p - buf);
-// TODO: smarter llist_t
-				cur = xzalloc(sizeof(xlist_t) + length);
-				cur->data = memcpy(cur + 1, s, length);
+				/* Dont xzalloc - it can be quite big */
+				cur = xmalloc(offsetof(xlist_t, xstr) + length);
+				cur->link = NULL;
 				cur->length = length;
-				/*cur->link = NULL;*/
+				memcpy(cur->xstr, s, length);
 				if (prev == NULL) {
 					list_arg = cur;
 				} else {
@@ -237,7 +235,7 @@
 			s = p = buf;
 		if ((p - buf) >= mc)
 			bb_error_msg_and_die("argument line too long");
-		*p++ = c == EOF ? 0 : c;
+		*p++ = (c == EOF ? '\0' : c);
 		if (c == EOF) { /* word's delimiter or EOF detected */
 			/* word loaded */
 			if (eof_str) {
@@ -245,12 +243,11 @@
 			}
 			if (!eof_str_detected) {
 				size_t length = (p - buf);
-
-				cur = xzalloc(sizeof(xlist_t) + length);
-// TODO: smarter llist_t
-				cur->data = memcpy(cur + 1, s, length);
+				/* Dont xzalloc - it can be quite big */
+				cur = xmalloc(offsetof(xlist_t, xstr) + length);
+				cur->link = NULL;
 				cur->length = length;
-				/*cur->link = NULL;*/
+				memcpy(cur->xstr, s, length);
 				if (prev == NULL) {
 					list_arg = cur;
 				} else {
@@ -318,22 +315,21 @@
 			eof_stdin_detected = 1;
 			if (s == NULL)
 				break;
-			c = 0;
+			c = '\0';
 		}
 		if (s == NULL)
 			s = p = buf;
 		if ((size_t)(p - buf) >= mc)
 			bb_error_msg_and_die("argument line too long");
 		*p++ = c;
-		if (c == 0) {   /* word's delimiter or EOF detected */
+		if (c == '\0') {   /* word's delimiter or EOF detected */
 			/* word loaded */
 			size_t length = (p - buf);
-
-			cur = xzalloc(sizeof(xlist_t) + length);
-// TODO: smarter llist_t
-			cur->data = memcpy(cur + 1, s, length);
+			/* Dont xzalloc - it can be quite big */
+			cur = xmalloc(offsetof(xlist_t, xstr) + length);
+			cur->link = NULL;
 			cur->length = length;
-			/*cur->link = NULL;*/
+			memcpy(cur->xstr, s, length);
 			if (prev == NULL) {
 				list_arg = cur;
 			} else {
@@ -479,7 +475,7 @@
 			args[i] = argv[i];
 		/* (taken from stdin) */
 		for (cur = list; n; cur = cur->link) {
-			args[i++] = cur->data;
+			args[i++] = cur->xstr;
 			n--;
 		}
 




More information about the busybox-cvs mailing list