diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-11-22 14:44:08 +0100 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-11-22 14:44:08 +0100 |
commit | 0368c71e7871209f1566b5a185d0840bb99d7794 (patch) | |
tree | a1ce9ab06dd45d796dcef8527a190f6eaa943982 /src/lib/dump_dir.c | |
parent | 4bb97934558b6b6a1aafdfe3bc56c38dc3b79c87 (diff) | |
download | abrt-0368c71e7871209f1566b5a185d0840bb99d7794.tar.gz abrt-0368c71e7871209f1566b5a185d0840bb99d7794.tar.xz abrt-0368c71e7871209f1566b5a185d0840bb99d7794.zip |
preraratory patch for database removal
I splitted bits from a large "database removal" patch which are simple
and non-contentiouns. They are in this change.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/lib/dump_dir.c')
-rw-r--r-- | src/lib/dump_dir.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c index 3778aa85..19c49ce7 100644 --- a/src/lib/dump_dir.c +++ b/src/lib/dump_dir.c @@ -378,16 +378,26 @@ static char *load_text_file(const char *path, unsigned flags) } struct strbuf *buf_content = strbuf_new(); + int oneline = 0; int ch; while ((ch = fgetc(fp)) != EOF) { + if (ch == '\n') + oneline = (oneline << 1) | 1; if (ch == '\0') - strbuf_append_char(buf_content, ' '); - else if (isspace(ch) || (isascii(ch) && !iscntrl(ch))) + ch = ' '; + if (isspace(ch) || (isascii(ch) && !iscntrl(ch))) 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'; + return strbuf_free_nobuf(buf_content); } |