Displaying 1 result from an estimated 1 matches for "fail_arg".
Did you mean:
fail_args
2010 Sep 16
1
[RFC] function to parse string to argc/argv pair
...*q, *r, *args, **arg;
int sp = 1; //, qt = 0; /* Was a space; inside a quote */
/* Scan 1: Length */
/* I could eliminate this if I knew a max length, like strncpy() */
int len = strlen(istr);
/* Scan 2: Copy, nullify and make argc */
if (!(args = malloc(len + 1)))
goto fail_args;
q = args;
for (p = istr;; p++) {
if (*p <= ' ') {
if (!sp) {
sp = 1;
*q++ = '\0';
}
} else {
if (sp) {
argc++;
sp = 0;
}
*q++ = *p;
}
if (!*p)
break;
}
q--; /* Point q to final null */
/* Scan 3: Build array of po...