aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/set.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-03-10 23:41:24 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2017-03-10 23:41:24 -0500
commit9aed9d93596cdc72e305338d82ccc0dcaf85c6e2 (patch)
treeb5a3db4994970b2d0033e717771b24a92503ddac /sway/commands/set.c
parentFurther indentation corrections (diff)
downloadsway-9aed9d93596cdc72e305338d82ccc0dcaf85c6e2.tar.gz
sway-9aed9d93596cdc72e305338d82ccc0dcaf85c6e2.tar.zst
sway-9aed9d93596cdc72e305338d82ccc0dcaf85c6e2.zip
UnGNUify the codebase
Diffstat (limited to 'sway/commands/set.c')
-rw-r--r--sway/commands/set.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/sway/commands/set.c b/sway/commands/set.c
index 8b293825..1d6bce04 100644
--- a/sway/commands/set.c
+++ b/sway/commands/set.c
@@ -1,5 +1,7 @@
1#define _XOPEN_SOURCE 500
1#include <stdio.h> 2#include <stdio.h>
2#include <string.h> 3#include <string.h>
4#include <strings.h>
3#include "sway/commands.h" 5#include "sway/commands.h"
4#include "sway/config.h" 6#include "sway/config.h"
5#include "list.h" 7#include "list.h"
@@ -14,7 +16,6 @@ static int compare_set_qsort(const void *_l, const void *_r) {
14 16
15struct cmd_results *cmd_set(int argc, char **argv) { 17struct cmd_results *cmd_set(int argc, char **argv) {
16 char *tmp; 18 char *tmp;
17 int size;
18 struct cmd_results *error = NULL; 19 struct cmd_results *error = NULL;
19 if (!config->reading) return cmd_results_new(CMD_FAILURE, "set", "Can only be used in config file."); 20 if (!config->reading) return cmd_results_new(CMD_FAILURE, "set", "Can only be used in config file.");
20 if ((error = checkarg(argc, "set", EXPECTED_AT_LEAST, 2))) { 21 if ((error = checkarg(argc, "set", EXPECTED_AT_LEAST, 2))) {
@@ -24,13 +25,14 @@ struct cmd_results *cmd_set(int argc, char **argv) {
24 if (argv[0][0] != '$') { 25 if (argv[0][0] != '$') {
25 sway_log(L_INFO, "Warning: variable '%s' doesn't start with $", argv[0]); 26 sway_log(L_INFO, "Warning: variable '%s' doesn't start with $", argv[0]);
26 27
27 size = asprintf(&tmp, "%s%s", "$", argv[0]); 28 size_t size = snprintf(NULL, 0, "$%s", argv[0]);
28 if (size == -1) { 29 tmp = malloc(size + 1);
30 if (!tmp) {
29 return cmd_results_new(CMD_FAILURE, "set", "Not possible to create variable $'%s'", argv[0]); 31 return cmd_results_new(CMD_FAILURE, "set", "Not possible to create variable $'%s'", argv[0]);
30 } 32 }
33 snprintf(tmp, size, "$%s", argv[0]);
31 34
32 argv[0] = strdup(tmp); 35 argv[0] = tmp;
33 free(tmp);
34 } 36 }
35 37
36 struct sway_variable *var = NULL; 38 struct sway_variable *var = NULL;