strsplit was used in only one place and did the same thing as strtok. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- src/pacman/pacman.c | 10 +++++----- src/pacman/util.c | 34 ---------------------------------- src/pacman/util.h | 1 - 3 files changed, 5 insertions(+), 40 deletions(-) diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 24fd57f..d2114e6 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -325,14 +325,14 @@ static void handler(int signum) static int parsearg_util_addlist(alpm_list_t **list) { - alpm_list_t *split, *item; + char *i, *save; check_optarg(); - split = strsplit(optarg, ','); - for(item = split; item; item = alpm_list_next(item)) { - *list = alpm_list_add(*list, item->data); + + for(i = strtok_r(optarg, ",", &save); i; i = strtok_r(NULL, ",", &save)) { + *list = alpm_list_add(*list, strdup(i)); } - alpm_list_free(split); + return 0; } diff --git a/src/pacman/util.c b/src/pacman/util.c index 6da1cd4..0e9a420 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -378,40 +378,6 @@ char *strreplace(const char *str, const char *needle, const char *replace) return newstr; } -/** Splits a string into a list of strings using the chosen character as - * a delimiter. - * - * @param str the string to split - * @param splitchar the character to split at - * - * @return a list containing the duplicated strings - */ -alpm_list_t *strsplit(const char *str, const char splitchar) -{ - alpm_list_t *list = NULL; - const char *prev = str; - char *dup = NULL; - - while((str = strchr(str, splitchar))) { - dup = strndup(prev, (size_t)(str - prev)); - if(dup == NULL) { - return NULL; - } - list = alpm_list_add(list, dup); - - str++; - prev = str; - } - - dup = strdup(prev); - if(dup == NULL) { - return NULL; - } - list = alpm_list_add(list, dup); - - return list; -} - static size_t string_length(const char *s) { int len; diff --git a/src/pacman/util.h b/src/pacman/util.h index 0a2a6f7..e2297f8 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -54,7 +54,6 @@ int rmrf(const char *path); void indentprint(const char *str, unsigned short indent, unsigned short cols); size_t strtrim(char *str); char *strreplace(const char *str, const char *needle, const char *replace); -alpm_list_t *strsplit(const char *str, const char splitchar); void string_display(const char *title, const char *string, unsigned short cols); double humanize_size(off_t bytes, const char target_unit, int precision, const char **label); -- 1.8.4