summaryrefslogtreecommitdiff
path: root/src/shared/fileio.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-11-06 21:21:39 +0100
committerLennart Poettering <lennart@poettering.net>2014-11-07 01:19:56 +0100
commitf2997962ff8aeea577bed878d3bc4e4f64784e45 (patch)
treebae0ee987eab225393c590001206e5cedb8b6441 /src/shared/fileio.c
parent84ee0960443b795936026239f8c0ff8429aed699 (diff)
fileio: simplify write_string_file_atomic() by reusing write_string_stream()
Diffstat (limited to 'src/shared/fileio.c')
-rw-r--r--src/shared/fileio.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/src/shared/fileio.c b/src/shared/fileio.c
index f4efc4c9f1..ff6b1a7ed7 100644
--- a/src/shared/fileio.c
+++ b/src/shared/fileio.c
@@ -66,7 +66,7 @@ int write_string_file_no_create(const char *fn, const char *line) {
assert(line);
/* We manually build our own version of fopen(..., "we") that
- * without O_CREAT */
+ * works without O_CREAT */
fd = open(fn, O_WRONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0)
return -errno;
@@ -94,20 +94,10 @@ int write_string_file_atomic(const char *fn, const char *line) {
fchmod_umask(fileno(f), 0644);
- errno = 0;
- fputs(line, f);
- if (!endswith(line, "\n"))
- fputc('\n', f);
-
- fflush(f);
-
- if (ferror(f))
- r = errno ? -errno : -EIO;
- else {
+ r = write_string_stream(f, line);
+ if (r >= 0) {
if (rename(p, fn) < 0)
r = -errno;
- else
- r = 0;
}
if (r < 0)