Simplify split_args().
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 6 Feb 2019 16:37:25 +0000 (17:37 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 13 Oct 2019 03:58:52 +0000 (05:58 +0200)
Both callers pass the same value for the delimiters, so we can
remove the last argument of the function.

dss.c
exec.c
str.c
str.h

diff --git a/dss.c b/dss.c
index a219cfd37b4569fbc3aa67fb2d4443a950353197..217dfafd25c55741e564c0feb13c1ccfbad317d0 100644 (file)
--- 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));
 {
        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 *));
 
        n++;
        argv = dss_realloc(argv, (n + 1) * sizeof(char *));
diff --git a/exec.c b/exec.c
index 9e0565dc5e08cd0905fd70de01ca0c9b8a100a0e..ece7ec29aa233051cf10bd5c4f3b1b6adfd14cfe 100644 (file)
--- 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);
 
 {
        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);
        dss_exec(pid, argv[0], argv);
        free(argv);
        free(tmp);
diff --git a/str.c b/str.c
index 623def1fd9b7aa7ee72f221aa6759fcf74b70948..13776300d6ca1aa62479df6be4428a5ba8d836a0 100644 (file)
--- 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 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;
 {
        char *p;
        char **argv;
        size_t n = 0, i, j;
+       const char delim[] = " \t";
 
        p = args + strspn(args, delim);
        for (;;) {
 
        p = args + strspn(args, delim);
        for (;;) {
diff --git a/str.h b/str.h
index b7f26350ccb5941ced169d6b893ff18b38fcaee1..7b121efb00d1e19c5b92e1711b25c23cd29a8092 100644 (file)
--- 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);
 __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. */
 
 
 /** \cond LLONG_MAX and LLONG_LIN might not be defined. */