diff options
author | 2015-09-07 15:03:04 -0700 | |
---|---|---|
committer | 2015-09-07 15:03:04 -0700 | |
commit | 3eb29ea7364724af99e4f4a5f7a6f633e17baf8d (patch) | |
tree | 8496fd8673d31bac1802d756885a8fc64245a552 | |
parent | put strip_whitespace back (diff) | |
download | sway-3eb29ea7364724af99e4f4a5f7a6f633e17baf8d.tar.gz sway-3eb29ea7364724af99e4f4a5f7a6f633e17baf8d.tar.zst sway-3eb29ea7364724af99e4f4a5f7a6f633e17baf8d.zip |
strdup + style
-rw-r--r-- | sway/commands.c | 9 | ||||
-rw-r--r-- | sway/config.c | 3 | ||||
-rw-r--r-- | sway/stringop.c | 8 |
3 files changed, 7 insertions, 13 deletions
diff --git a/sway/commands.c b/sway/commands.c index 72d53ff0..e7ddfa71 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -383,9 +383,8 @@ static bool cmd_mode(int argc, char **argv) { | |||
383 | // Create mode if it doesnt exist | 383 | // Create mode if it doesnt exist |
384 | if (!mode && argc >= 2 && strncmp(argv[1],"{",1) == 0) { | 384 | if (!mode && argc >= 2 && strncmp(argv[1],"{",1) == 0) { |
385 | mode = malloc(sizeof*mode); | 385 | mode = malloc(sizeof*mode); |
386 | mode->name = malloc(strlen(mode_name) + 1); | 386 | mode->name = strdup(mode_name); |
387 | mode->bindings = create_list(); | 387 | mode->bindings = create_list(); |
388 | strcpy(mode->name, mode_name); | ||
389 | list_add(config->modes, mode); | 388 | list_add(config->modes, mode); |
390 | } | 389 | } |
391 | if (!mode) { | 390 | if (!mode) { |
@@ -834,10 +833,8 @@ static bool cmd_set(int argc, char **argv) { | |||
834 | return false; | 833 | return false; |
835 | } | 834 | } |
836 | struct sway_variable *var = malloc(sizeof(struct sway_variable)); | 835 | struct sway_variable *var = malloc(sizeof(struct sway_variable)); |
837 | var->name = malloc(strlen(argv[0]) + 1); | 836 | var->name = strdup(argv[0]); |
838 | strcpy(var->name, argv[0]); | 837 | var->value = strdup(argv[1]); |
839 | var->value = malloc(strlen(argv[1]) + 1); | ||
840 | strcpy(var->value, argv[1]); | ||
841 | list_add(config->symbols, var); | 838 | list_add(config->symbols, var); |
842 | return true; | 839 | return true; |
843 | } | 840 | } |
diff --git a/sway/config.c b/sway/config.c index 95cd8b0d..5ece2810 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -249,8 +249,7 @@ bool read_config(FILE *file, bool is_active) { | |||
249 | sway_log(L_ERROR, "Invalid command during config ``%s''", line); | 249 | sway_log(L_ERROR, "Invalid command during config ``%s''", line); |
250 | } else if (handler->config_type == CMD_COMPOSITOR_READY && !is_active) { | 250 | } else if (handler->config_type == CMD_COMPOSITOR_READY && !is_active) { |
251 | sway_log(L_DEBUG, "Deferring command ``%s''", line); | 251 | sway_log(L_DEBUG, "Deferring command ``%s''", line); |
252 | char *cmd = malloc(strlen(line) + 1); | 252 | char *cmd = strdup(line); |
253 | strcpy(cmd, line); | ||
254 | list_add(config->cmd_queue, cmd); | 253 | list_add(config->cmd_queue, cmd); |
255 | } else if (!handle_command(line)) { | 254 | } else if (!handle_command(line)) { |
256 | sway_log(L_DEBUG, "Config load failed for line ``%s''", line); | 255 | sway_log(L_DEBUG, "Config load failed for line ``%s''", line); |
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 | ||
77 | list_t *split_string(const char *str, const char *delims) { | 76 | list_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) { |