diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-10-15 03:41:42 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-10-15 03:41:42 +0200 |
commit | 60723d736a361909b044ade5fda47283d30f020c (patch) | |
tree | c57d0c0c4ba9e5d0e3e57fd1e7418fb98c0db4cf /src | |
parent | 2205830e6787376e7e7b8e96e3fc3554ee57b360 (diff) | |
download | blogc-60723d736a361909b044ade5fda47283d30f020c.tar.gz blogc-60723d736a361909b044ade5fda47283d30f020c.tar.bz2 blogc-60723d736a361909b044ade5fda47283d30f020c.zip |
blogc: we still need to strip newlines from end of line
Diffstat (limited to 'src')
-rw-r--r-- | src/blogc/main.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/blogc/main.c b/src/blogc/main.c index 50123e1..8377ea5 100644 --- a/src/blogc/main.c +++ b/src/blogc/main.c @@ -110,10 +110,17 @@ blogc_read_stdin_to_list(bc_slist_t *l) { char buffer[4096]; while (NULL != fgets(buffer, 4096, stdin)) { - if (buffer[0] == '\0') + size_t len = strlen(buffer); + if (len == 0) continue; if (buffer[0] == '#') continue; + if (len >= 2 && (buffer[len - 2] == '\r') || (buffer[len - 2] == '\n')) + buffer[len - 2] = '\0'; + if ((buffer[len - 1] == '\r') || (buffer[len - 1] == '\n')) + buffer[len - 1] = '\0'; + if (strlen(buffer) == 0) + continue; l = bc_slist_append(l, bc_strdup(buffer)); } return l; |