diff options
Diffstat (limited to 'common/stringop.c')
-rw-r--r-- | common/stringop.c | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/common/stringop.c b/common/stringop.c index d2c91c24..8af0d60f 100644 --- a/common/stringop.c +++ b/common/stringop.c | |||
@@ -1,4 +1,4 @@ | |||
1 | #define _XOPEN_SOURCE 700 | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <stdio.h> | 3 | #include <stdio.h> |
4 | #include <string.h> | 4 | #include <string.h> |
@@ -9,24 +9,17 @@ | |||
9 | #include "string.h" | 9 | #include "string.h" |
10 | #include "list.h" | 10 | #include "list.h" |
11 | 11 | ||
12 | const char whitespace[] = " \f\n\r\t\v"; | 12 | static const char whitespace[] = " \f\n\r\t\v"; |
13 | 13 | ||
14 | char *strip_whitespace(char *_str) { | 14 | void strip_whitespace(char *str) { |
15 | if (*_str == '\0') | 15 | size_t len = strlen(str); |
16 | return _str; | 16 | size_t start = strspn(str, whitespace); |
17 | char *strold = _str; | 17 | memmove(str, &str[start], len + 1 - start); |
18 | while (*_str == ' ' || *_str == '\t') { | 18 | |
19 | _str++; | 19 | if (*str) { |
20 | for (len -= start + 1; isspace(str[len]); --len) {} | ||
21 | str[len + 1] = '\0'; | ||
20 | } | 22 | } |
21 | char *str = strdup(_str); | ||
22 | free(strold); | ||
23 | int i; | ||
24 | for (i = 0; str[i] != '\0'; ++i); | ||
25 | do { | ||
26 | i--; | ||
27 | } while (i >= 0 && (str[i] == ' ' || str[i] == '\t')); | ||
28 | str[i + 1] = '\0'; | ||
29 | return str; | ||
30 | } | 23 | } |
31 | 24 | ||
32 | void strip_quotes(char *str) { | 25 | void strip_quotes(char *str) { |
@@ -97,14 +90,6 @@ list_t *split_string(const char *str, const char *delims) { | |||
97 | return res; | 90 | return res; |
98 | } | 91 | } |
99 | 92 | ||
100 | void free_flat_list(list_t *list) { | ||
101 | int i; | ||
102 | for (i = 0; i < list->length; ++i) { | ||
103 | free(list->items[i]); | ||
104 | } | ||
105 | list_free(list); | ||
106 | } | ||
107 | |||
108 | char **split_args(const char *start, int *argc) { | 93 | char **split_args(const char *start, int *argc) { |
109 | *argc = 0; | 94 | *argc = 0; |
110 | int alloc = 2; | 95 | int alloc = 2; |