diff options
author | emersion <contact@emersion.fr> | 2019-01-08 10:05:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-08 10:05:37 +0100 |
commit | 140bc2dd5b81205df58bf06e695788e689fae397 (patch) | |
tree | 6a88913630734736763b12ec0b10da68ef413256 /swaylock/main.c | |
parent | 353d9ed74f3560e12500c08920cf8a1ca3344cc2 (diff) | |
parent | 5bef06adfdac4ce9940dcaf2d90a4bdffae7bba9 (diff) |
Merge pull request #3275 from ianyfan/remove-readline
Rewrite strip_whitespace and remove readline.c
Diffstat (limited to 'swaylock/main.c')
-rw-r--r-- | swaylock/main.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/swaylock/main.c b/swaylock/main.c index 9aeb4e64..9a4f3b58 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -23,7 +23,6 @@ #include "cairo.h" #include "log.h" #include "loop.h" -#include "readline.h" #include "stringop.h" #include "util.h" #include "wlr-input-inhibitor-unstable-v1-client-protocol.h" @@ -808,36 +807,32 @@ static int load_config(char *path, struct swaylock_state *state, wlr_log(WLR_ERROR, "Failed to read config. Running without it."); return 0; } - char *line; + char *line = NULL; + size_t line_size = 0; + ssize_t nread; int line_number = 0; - while (!feof(config)) { - line = read_line(config); - if (!line) { - continue; - } - + int result = 0; + while ((nread = getline(&line, &line_size, config)) != -1) { line_number++; - if (line[0] == '#') { - free(line); - continue; + + if (line[nread - 1] == '\n') { + line[--nread] = '\0'; } - if (strlen(line) == 0) { - free(line); + + if (!*line || line[0] == '#') { continue; } wlr_log(WLR_DEBUG, "Config Line #%d: %s", line_number, line); - char flag[strlen(line) + 3]; + char flag[nread + 3]; sprintf(flag, "--%s", line); char *argv[] = {"swaylock", flag}; - int result = parse_options(2, argv, state, line_mode, NULL); + result = parse_options(2, argv, state, line_mode, NULL); if (result != 0) { - free(line); - fclose(config); - return result; + break; } - free(line); } + free(line); fclose(config); return 0; } |