diff options
author | Jiri Moskovcak <jmoskovc@redhat.com> | 2011-05-19 17:35:59 +0200 |
---|---|---|
committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2011-05-19 17:35:59 +0200 |
commit | 6b908263abc2552ef97711680ec420b509492349 (patch) | |
tree | 877c65b67ec470f36ef333c929c8a357008f7209 /src/lib | |
parent | 4d1a684b22d55bc0025115cd6ee21a24f4fe31c7 (diff) | |
parent | f3b32f8cb94bc83ded97bec478e666be6a07bf0d (diff) | |
download | abrt-6b908263abc2552ef97711680ec420b509492349.tar.gz abrt-6b908263abc2552ef97711680ec420b509492349.tar.xz abrt-6b908263abc2552ef97711680ec420b509492349.zip |
Merge branch 'master' of git://git.fedorahosted.org/git/abrt
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/dump_dir.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c index 0c6467f4..03097ce1 100644 --- a/src/lib/dump_dir.c +++ b/src/lib/dump_dir.c @@ -651,21 +651,37 @@ static char *load_text_file(const char *path, unsigned flags) int ch; while ((ch = fgetc(fp)) != EOF) { +//TODO? \r -> \n? +//TODO? strip trailing spaces/tabs? if (ch == '\n') oneline = (oneline << 1) | 1; if (ch == '\0') ch = ' '; - if (isspace(ch) || (isascii(ch) && !iscntrl(ch))) + if (isspace(ch) || ch >= ' ') /* used !iscntrl, but it failed on unicode */ strbuf_append_char(buf_content, ch); } fclose(fp); - /* If file contains exactly one '\n' and it is at the end, remove it. - * This enables users to use simple "echo blah >file" in order to create - * short string items in dump dirs. - */ - if (oneline == 1 && buf_content->buf[buf_content->len - 1] == '\n') - buf_content->buf[--buf_content->len] = '\0'; + char last = oneline != 0 ? buf_content->buf[buf_content->len - 1] : 0; + if (last == '\n') + { + /* If file contains exactly one '\n' and it is at the end, remove it. + * This enables users to use simple "echo blah >file" in order to create + * short string items in dump dirs. + */ + if (oneline == 1) + buf_content->buf[--buf_content->len] = '\0'; + } + else /* last != '\n' */ + { + /* Last line is unterminated, fix it */ + /* Cases: */ + /* oneline=0: "qwe" - DONT fix this! */ + /* oneline=1: "qwe\nrty" - two lines in fact */ + /* oneline>1: "qwe\nrty\uio" */ + if (oneline >= 1) + strbuf_append_char(buf_content, '\n'); + } return strbuf_free_nobuf(buf_content); } |