diff options
Diffstat (limited to 'common/util.c')
-rw-r--r-- | common/util.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/common/util.c b/common/util.c index 0caafb39..d66058a6 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -1,4 +1,4 @@ | |||
1 | #define _XOPEN_SOURCE 700 | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <assert.h> | 2 | #include <assert.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <sys/stat.h> | 4 | #include <sys/stat.h> |
@@ -13,7 +13,6 @@ | |||
13 | #include <xkbcommon/xkbcommon-names.h> | 13 | #include <xkbcommon/xkbcommon-names.h> |
14 | #include <wlr/types/wlr_keyboard.h> | 14 | #include <wlr/types/wlr_keyboard.h> |
15 | #include "log.h" | 15 | #include "log.h" |
16 | #include "readline.h" | ||
17 | #include "util.h" | 16 | #include "util.h" |
18 | 17 | ||
19 | int wrap(int i, int max) { | 18 | int wrap(int i, int max) { |
@@ -24,7 +23,8 @@ int numlen(int n) { | |||
24 | if (n == 0) { | 23 | if (n == 0) { |
25 | return 1; | 24 | return 1; |
26 | } | 25 | } |
27 | return log10(n) + 1; | 26 | // Account for the '-' in negative numbers. |
27 | return log10(abs(n)) + (n > 0 ? 1 : 2); | ||
28 | } | 28 | } |
29 | 29 | ||
30 | static struct modifier_key { | 30 | static struct modifier_key { |
@@ -86,11 +86,12 @@ pid_t get_parent_pid(pid_t child) { | |||
86 | char *token = NULL; | 86 | char *token = NULL; |
87 | const char *sep = " "; | 87 | const char *sep = " "; |
88 | FILE *stat = NULL; | 88 | FILE *stat = NULL; |
89 | size_t buf_size = 0; | ||
89 | 90 | ||
90 | sprintf(file_name, "/proc/%d/stat", child); | 91 | sprintf(file_name, "/proc/%d/stat", child); |
91 | 92 | ||
92 | if ((stat = fopen(file_name, "r"))) { | 93 | if ((stat = fopen(file_name, "r"))) { |
93 | if ((buffer = read_line(stat))) { | 94 | if (getline(&buffer, &buf_size, stat) != -1) { |
94 | token = strtok(buffer, sep); // pid | 95 | token = strtok(buffer, sep); // pid |
95 | token = strtok(NULL, sep); // executable name | 96 | token = strtok(NULL, sep); // executable name |
96 | token = strtok(NULL, sep); // state | 97 | token = strtok(NULL, sep); // state |