diff options
author | Daniel Mack <daniel@zonque.org> | 2015-07-06 17:31:44 -0400 |
---|---|---|
committer | Daniel Mack <daniel@zonque.org> | 2015-07-06 17:31:44 -0400 |
commit | 40beecdb6d1c73e5acb62ebac2ccbfd7891f2418 (patch) | |
tree | 40626ff5f761e898e7343939878a10d87e9d29a8 /src/basic/fileio.c | |
parent | eff8efe671e9ffa81e80ad13f791a32262567dfe (diff) |
fileio: add 'enforce_newline' argument to write_string_stream()
Add a flag to control whether write_string_stream() should always enforce a
trailing newline character in the file.
Diffstat (limited to 'src/basic/fileio.c')
-rw-r--r-- | src/basic/fileio.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 00fb6f8b5c..82b40aa7da 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -27,14 +27,14 @@ #include "ctype.h" #include "fileio.h" -int write_string_stream(FILE *f, const char *line) { +int write_string_stream(FILE *f, const char *line, bool enforce_newline) { assert(f); assert(line); errno = 0; fputs(line, f); - if (!endswith(line, "\n")) + if (enforce_newline && !endswith(line, "\n")) fputc('\n', f); fflush(f); @@ -55,7 +55,7 @@ int write_string_file(const char *fn, const char *line) { if (!f) return -errno; - return write_string_stream(f, line); + return write_string_stream(f, line, true); } int write_string_file_no_create(const char *fn, const char *line) { @@ -77,7 +77,7 @@ int write_string_file_no_create(const char *fn, const char *line) { return -errno; } - return write_string_stream(f, line); + return write_string_stream(f, line, true); } int write_string_file_atomic(const char *fn, const char *line) { @@ -94,7 +94,7 @@ int write_string_file_atomic(const char *fn, const char *line) { fchmod_umask(fileno(f), 0644); - r = write_string_stream(f, line); + r = write_string_stream(f, line, true); if (r >= 0) { if (rename(p, fn) < 0) r = -errno; |