From: Andre Noll Date: Wed, 6 Feb 2019 16:37:25 +0000 (+0100) Subject: Simplify split_args(). X-Git-Tag: v1.0.1~5 X-Git-Url: http://git.tuebingen.mpg.de/?p=dss.git;a=commitdiff_plain;h=c3ad4e36f7ee18ab6fab4595fa2728a47c1db761 Simplify split_args(). Both callers pass the same value for the delimiters, so we can remove the last argument of the function. --- diff --git a/dss.c b/dss.c index a219cfd..217dfaf 100644 --- a/dss.c +++ b/dss.c @@ -1567,7 +1567,7 @@ static void exit_hook(int exit_code) { pid_t pid; char **argv, *tmp = dss_strdup(OPT_STRING_VAL(DSS, EXIT_HOOK)); - unsigned n = split_args(tmp, &argv, " \t"); + unsigned n = split_args(tmp, &argv); n++; argv = dss_realloc(argv, (n + 1) * sizeof(char *)); diff --git a/exec.c b/exec.c index 9e0565d..ece7ec2 100644 --- a/exec.c +++ b/exec.c @@ -56,7 +56,7 @@ void dss_exec_cmdline_pid(pid_t *pid, const char *cmdline) { char **argv, *tmp = dss_strdup(cmdline); - split_args(tmp, &argv, " \t"); + split_args(tmp, &argv); dss_exec(pid, argv[0], argv); free(argv); free(tmp); diff --git a/str.c b/str.c index 623def1..1377630 100644 --- a/str.c +++ b/str.c @@ -212,20 +212,21 @@ __must_check __malloc char *dss_logname(void) * * \param args The string to be split. * \param argv_ptr Pointer to the list of substrings. - * \param delim Delimiter. * - * This function modifies \a args by replacing each occurrence of \a delim by - * zero. A \p NULL-terminated array of pointers to char* is allocated dynamically - * and these pointers are initialized to point to the broken-up substrings - * within \a args. A pointer to this array is returned via \a argv_ptr. + * This function modifies the string given by the first argument by replacing + * all occurrences of space and '\t' characters by '\0'. A NULL-terminated + * array of pointers to char * is allocated dynamically, and these pointers are + * initialized to point to the broken-up substrings. A pointer to this array + * is returned via the last argument. * - * \return The number of substrings found in \a args. + * \return The number of substrings found. */ -unsigned split_args(char *args, char *** const argv_ptr, const char *delim) +unsigned split_args(char *args, char *** const argv_ptr) { char *p; char **argv; size_t n = 0, i, j; + const char delim[] = " \t"; p = args + strspn(args, delim); for (;;) { diff --git a/str.h b/str.h index b7f2635..7b121ef 100644 --- a/str.h +++ b/str.h @@ -8,7 +8,7 @@ __must_check __malloc char *dss_strdup(const char *s); __must_check __malloc char *get_homedir(void); int dss_atoi64(const char *str, int64_t *value); __must_check __malloc char *dss_logname(void); -unsigned split_args(char *args, char *** const argv_ptr, const char *delim); +unsigned split_args(char *args, char *** const argv_ptr); /** \cond LLONG_MAX and LLONG_LIN might not be defined. */