aboutsummaryrefslogtreecommitdiffstats
path: root/sway/stringop.c
diff options
context:
space:
mode:
authorLibravatar taiyu <taiyu.len@gmail.com>2015-09-07 15:03:04 -0700
committerLibravatar taiyu <taiyu.len@gmail.com>2015-09-07 15:03:04 -0700
commit3eb29ea7364724af99e4f4a5f7a6f633e17baf8d (patch)
tree8496fd8673d31bac1802d756885a8fc64245a552 /sway/stringop.c
parentput strip_whitespace back (diff)
downloadsway-3eb29ea7364724af99e4f4a5f7a6f633e17baf8d.tar.gz
sway-3eb29ea7364724af99e4f4a5f7a6f633e17baf8d.tar.zst
sway-3eb29ea7364724af99e4f4a5f7a6f633e17baf8d.zip
strdup + style
Diffstat (limited to 'sway/stringop.c')
-rw-r--r--sway/stringop.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/sway/stringop.c b/sway/stringop.c
index 77faf3f1..1ba54ec6 100644
--- a/sway/stringop.c
+++ b/sway/stringop.c
@@ -17,14 +17,13 @@ char *strip_whitespace(char *_str) {
17 while (*_str == ' ' || *_str == '\t') { 17 while (*_str == ' ' || *_str == '\t') {
18 _str++; 18 _str++;
19 } 19 }
20 char *str = malloc(strlen(_str) + 1); 20 char *str = strdup(_str);
21 strcpy(str, _str);
22 free(strold); 21 free(strold);
23 int i; 22 int i;
24 for (i = 0; str[i] != '\0'; ++i); 23 for (i = 0; str[i] != '\0'; ++i);
25 do { 24 do {
26 i--; 25 i--;
27 } while (i >= 0 && (str[i] == ' ' || str[i] == '\t')); 26 } while (i >= 0 && (str[i] == ' ' || str[i] == '\t'));
28 str[i + 1] = '\0'; 27 str[i + 1] = '\0';
29 return str; 28 return str;
30} 29}
@@ -76,9 +75,8 @@ void strip_quotes(char *str) {
76 75
77list_t *split_string(const char *str, const char *delims) { 76list_t *split_string(const char *str, const char *delims) {
78 list_t *res = create_list(); 77 list_t *res = create_list();
79 char *copy = malloc(strlen(str) + 1); 78 char *copy = strdup(str);
80 char *token; 79 char *token;
81 strcpy(copy, str);
82 80
83 token = strtok(copy, delims); 81 token = strtok(copy, delims);
84 while(token) { 82 while(token) {