return 1;
}
if (strcasecmp(ctx->last_map_key, "min_width") == 0) {
- char *copy = (char *)smalloc(len + 1);
- strncpy(copy, (const char *)val, len);
- copy[len] = 0;
- ctx->block.min_width_str = copy;
+ sasprintf(&(ctx->block.min_width_str), "%.*s", len, val);
return 1;
}
if (strcasecmp(ctx->last_map_key, "name") == 0) {
- char *copy = (char *)smalloc(len + 1);
- strncpy(copy, (const char *)val, len);
- copy[len] = 0;
- ctx->block.name = copy;
+ sasprintf(&(ctx->block.name), "%.*s", len, val);
return 1;
}
if (strcasecmp(ctx->last_map_key, "instance") == 0) {
- char *copy = (char *)smalloc(len + 1);
- strncpy(copy, (const char *)val, len);
- copy[len] = 0;
- ctx->block.instance = copy;
+ sasprintf(&(ctx->block.instance), "%.*s", len, val);
return 1;
}
*/
static int config_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
FREE(cur_key);
-
- cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1));
- strncpy(cur_key, (const char *)keyVal, keyLen);
- cur_key[keyLen] = '\0';
+ sasprintf(&(cur_key), "%.*s", keyLen, keyVal);
if (strcmp(cur_key, "bindings") == 0)
parsing_bindings = true;
struct mode_json_params *params = (struct mode_json_params *)params_;
if (!strcmp(params->cur_key, "change")) {
- char *copy = smalloc(sizeof(const unsigned char) * (len + 1));
- strncpy(copy, (const char *)val, len);
- copy[len] = '\0';
-
- params->name = copy;
+ sasprintf(&(params->name), "%.*s", len, val);
FREE(params->cur_key);
return 1;
}
static int mode_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
struct mode_json_params *params = (struct mode_json_params *)params_;
FREE(params->cur_key);
-
- params->cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1));
- strncpy(params->cur_key, (const char *)keyVal, keyLen);
- params->cur_key[keyLen] = '\0';
-
+ sasprintf(&(params->cur_key), "%.*s", keyLen, keyVal);
return 1;
}
struct outputs_json_params *params = (struct outputs_json_params *)params_;
if (!strcmp(params->cur_key, "current_workspace")) {
- char *copy = smalloc(sizeof(const unsigned char) * (len + 1));
- strncpy(copy, (const char *)val, len);
- copy[len] = '\0';
+ char *copy = NULL;
+ sasprintf(©, "%.*s", len, val);
char *end;
errno = 0;
if (errno == 0 &&
(end && *end == '\0'))
params->outputs_walk->ws = parsed_num;
- free(copy);
+
+ FREE(copy);
FREE(params->cur_key);
return 1;
}
return 0;
}
- char *name = smalloc(sizeof(const unsigned char) * (len + 1));
- strncpy(name, (const char *)val, len);
- name[len] = '\0';
-
- params->outputs_walk->name = name;
+ sasprintf(&(params->outputs_walk->name), "%.*s", len, val);
FREE(params->cur_key);
-
return 1;
}
static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
struct outputs_json_params *params = (struct outputs_json_params *)params_;
FREE(params->cur_key);
-
- params->cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1));
- strncpy(params->cur_key, (const char *)keyVal, keyLen);
- params->cur_key[keyLen] = '\0';
-
+ sasprintf(&(params->cur_key), "%.*s", keyLen, keyVal);
return 1;
}
static int workspaces_string_cb(void *params_, const unsigned char *val, size_t len) {
struct workspaces_json_params *params = (struct workspaces_json_params *)params_;
- char *output_name;
-
if (!strcmp(params->cur_key, "name")) {
const char *ws_name = (const char *)val;
params->workspaces_walk->canonical_name = sstrndup(ws_name, len);
if (!strcmp(params->cur_key, "output")) {
/* We add the ws to the TAILQ of the output, it belongs to */
- output_name = smalloc(sizeof(const unsigned char) * (len + 1));
- strncpy(output_name, (const char *)val, len);
- output_name[len] = '\0';
+ char *output_name = NULL;
+ sasprintf(&output_name, "%.*s", len, val);
+
i3_output *target = get_output_by_name(output_name);
- if (target) {
+ if (target != NULL) {
params->workspaces_walk->output = target;
TAILQ_INSERT_TAIL(params->workspaces_walk->output->workspaces,
static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
struct workspaces_json_params *params = (struct workspaces_json_params *)params_;
FREE(params->cur_key);
-
- params->cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1));
- strncpy(params->cur_key, (const char *)keyVal, keyLen);
- params->cur_key[keyLen] = '\0';
-
+ sasprintf(&(params->cur_key), "%.*s", keyLen, keyVal);
return 1;
}