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;
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 */
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 {
q = c;
state = QUOTE;
} else {
-set:
+ set:
if ((size_t)(p - buf) >= mc)
bb_error_msg_and_die("argument line too long");
*p++ = c;
}
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 {
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) {
}
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 {
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 {
args[i] = argv[i];
/* (taken from stdin) */
for (cur = list; n; cur = cur->link) {
- args[i++] = cur->data;
+ args[i++] = cur->xstr;
n--;
}