X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/c57f93a88ffee4eb75b32bdc479e271f04e32b94..6b6e5f94f81e56e9e9e1cf26ea596c01ed403555:/sbr/arglist.c diff --git a/sbr/arglist.c b/sbr/arglist.c index e6f079e4..716c8be6 100644 --- a/sbr/arglist.c +++ b/sbr/arglist.c @@ -1,6 +1,4 @@ - -/* - * arglist.c -- Routines for handling argument lists for execvp() and friends +/* arglist.c -- Routines for handling argument lists for execvp() and friends * * This code is Copyright (c) 2013, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -41,25 +39,27 @@ char ** argsplit(char *command, char **file, int *argp) { char **argvarray, *p; - int space = 0, metachar = 0, i; + int i; + bool space = false; + bool metachar = false; for (p = command; *p; p++) { if (*p == ' ' || *p == '\t') { - space = 1; + space = true; } else if (strchr(METACHARS, *p)) { - metachar = 1; + metachar = true; break; } } - argvarray = (char **) mh_xmalloc((sizeof(char **) * (MAXARGS + 5))); + argvarray = mh_xmalloc(sizeof *argvarray * (MAXARGS + 5)); /* * The simple case - no spaces or shell metacharacters */ if (!space && !metachar) { - argvarray[0] = getcpy(r1bindex(command, '/')); + argvarray[0] = mh_xstrdup(r1bindex(command, '/')); argvarray[1] = NULL; *file = mh_xstrdup(command); if (argp) @@ -77,12 +77,12 @@ argsplit(char *command, char **file, int *argp) p = mh_xstrdup(command); split = brkstring(p, " \t", NULL); if (split[0] == NULL) { - adios(NULL, "Invalid blank command found"); + die("Invalid blank command found"); } argvarray[0] = mh_xstrdup(r1bindex(split[0], '/')); for (i = 1; split[i] != NULL; i++) { if (i > MAXARGS) { - adios(NULL, "Command exceeded argument limit"); + die("Command exceeded argument limit"); } argvarray[i] = mh_xstrdup(split[i]); } @@ -133,7 +133,7 @@ arglist_free(char *command, char **argvarray) { int i; - mh_xfree(command); + free(command); if (argvarray != NULL) { for (i = 0; argvarray[i] != NULL; i++) @@ -201,8 +201,8 @@ argsplit_insert(struct msgs_array *msgs, char *command, char **program) */ if (msgs->size + argp >= msgs->max) { - msgs->max += MAXMSGS > argp ? MAXMSGS : argp; - msgs->msgs = mh_xrealloc(msgs->msgs, msgs->max * sizeof(*msgs->msgs)); + msgs->max += max(MAXMSGS, argp); + msgs->msgs = mh_xrealloc(msgs->msgs, msgs->max * sizeof(*msgs->msgs)); } for (i = msgs->size - 1; i >= 0; i--)