aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-10-15 03:41:42 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-10-15 03:41:42 +0200
commit60723d736a361909b044ade5fda47283d30f020c (patch)
treec57d0c0c4ba9e5d0e3e57fd1e7418fb98c0db4cf
parent2205830e6787376e7e7b8e96e3fc3554ee57b360 (diff)
downloadblogc-60723d736a361909b044ade5fda47283d30f020c.tar.gz
blogc-60723d736a361909b044ade5fda47283d30f020c.tar.bz2
blogc-60723d736a361909b044ade5fda47283d30f020c.zip
blogc: we still need to strip newlines from end of line
-rw-r--r--src/blogc/main.c9
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;