diff options
author | Ian Fan <ianfan0@gmail.com> | 2019-01-22 10:43:48 +0000 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2019-01-22 13:10:25 +0100 |
commit | de9a357de84da4436b263ff6a969eb4ac753af0d (patch) | |
tree | 6a2f05fe18a6152335c832a20e1f7c543badcf48 /swaybar | |
parent | Remove assumption that noop output will be called NOOP-1 (diff) | |
download | sway-de9a357de84da4436b263ff6a969eb4ac753af0d.tar.gz sway-de9a357de84da4436b263ff6a969eb4ac753af0d.tar.zst sway-de9a357de84da4436b263ff6a969eb4ac753af0d.zip |
util.c: remove numlen function
Its uses have been replaced by snprintf, which is more in line with its usage.
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/ipc.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 29b782bb..dbb593fb 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #define _POSIX_C_SOURCE 200809 | 1 | #define _POSIX_C_SOURCE 200809 |
2 | #include <limits.h> | 2 | #include <limits.h> |
3 | #include <stdio.h> | ||
3 | #include <string.h> | 4 | #include <string.h> |
4 | #include <strings.h> | 5 | #include <strings.h> |
5 | #include <json-c/json.h> | 6 | #include <json-c/json.h> |
@@ -9,6 +10,7 @@ | |||
9 | #include "ipc-client.h" | 10 | #include "ipc-client.h" |
10 | #include "list.h" | 11 | #include "list.h" |
11 | #include "log.h" | 12 | #include "log.h" |
13 | #include "util.h" | ||
12 | 14 | ||
13 | void ipc_send_workspace_command(struct swaybar *bar, const char *ws) { | 15 | void ipc_send_workspace_command(struct swaybar *bar, const char *ws) { |
14 | const char *fmt = "workspace \"%s\""; | 16 | const char *fmt = "workspace \"%s\""; |
@@ -372,15 +374,14 @@ bool ipc_get_workspaces(struct swaybar *bar) { | |||
372 | ws->label = strdup(ws->name); | 374 | ws->label = strdup(ws->name); |
373 | // ws->num will be -1 if workspace name doesn't begin with int. | 375 | // ws->num will be -1 if workspace name doesn't begin with int. |
374 | if (ws->num != -1) { | 376 | if (ws->num != -1) { |
375 | size_t len_offset = numlen(ws->num); | 377 | size_t len_offset = snprintf(NULL, 0, "%d", ws->num); |
376 | if (bar->config->strip_workspace_name) { | 378 | if (bar->config->strip_workspace_name) { |
377 | free(ws->label); | 379 | free(ws->label); |
378 | ws->label = malloc(len_offset + 1 * sizeof(char)); | 380 | ws->label = malloc(len_offset + 1); |
379 | ws->label[len_offset] = '\0'; | 381 | snprintf(ws->label, len_offset + 1, "%d", ws->num); |
380 | strncpy(ws->label, ws->name, len_offset); | ||
381 | } else if (bar->config->strip_workspace_numbers) { | 382 | } else if (bar->config->strip_workspace_numbers) { |
382 | len_offset += ws->label[len_offset] == ':'; | 383 | len_offset += ws->label[len_offset] == ':'; |
383 | if (strlen(ws->name) > len_offset) { | 384 | if (ws->name[len_offset] != '\0') { |
384 | free(ws->label); | 385 | free(ws->label); |
385 | // Strip number prefix [1-?:] using len_offset. | 386 | // Strip number prefix [1-?:] using len_offset. |
386 | ws->label = strdup(ws->name + len_offset); | 387 | ws->label = strdup(ws->name + len_offset); |