diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-08-01 22:55:20 -0400 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2018-08-01 22:55:20 -0400 |
commit | 26c5ef18ba295e016074c9d87affe5da44e71cb1 (patch) | |
tree | 7b45cf6cac4108eb7b3bb2407c90ad9b14f5af7a /swaynag/config.c | |
parent | 41d858b4397f1c89a13900f078854e28ea0ac45a (diff) |
swaynag: don't drop \n for first line
Diffstat (limited to 'swaynag/config.c')
-rw-r--r-- | swaynag/config.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/swaynag/config.c b/swaynag/config.c index 80c5ad88..d6c5739d 100644 --- a/swaynag/config.c +++ b/swaynag/config.c @@ -19,18 +19,14 @@ static char *read_from_stdin() { continue; } - if (!buffer) { - buffer = strdup(line); - } else { - buffer = realloc(buffer, strlen(buffer) + strlen(line) + 2); - strcat(buffer, line); - strcat(buffer, "\n"); - } + size_t curlen = buffer ? strlen(buffer) : 0; + buffer = realloc(buffer, curlen + strlen(line) + 2); + snprintf(buffer + curlen, strlen(line) + 2, "%s\n", line); free(line); } - if (buffer && buffer[strlen(buffer) - 1] == '\n') { + while (buffer && buffer[strlen(buffer) - 1] == '\n') { buffer[strlen(buffer) - 1] = '\0'; } |