summaryrefslogtreecommitdiff
path: root/src/basic/fileio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic/fileio.c')
-rw-r--r--src/basic/fileio.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index e3f3b7fc3..404d79d18 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -51,13 +51,17 @@
#define READ_FULL_BYTES_MAX (4U*1024U*1024U)
-int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, struct timespec *ts) {
+int write_string_stream_ts(
+ FILE *f,
+ const char *line,
+ WriteStringFileFlags flags,
+ struct timespec *ts) {
assert(f);
assert(line);
fputs(line, f);
- if (enforce_newline && !endswith(line, "\n"))
+ if (!(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n"))
fputc('\n', f);
if (ts) {
@@ -73,8 +77,7 @@ int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, stru
static int write_string_file_atomic(
const char *fn,
const char *line,
- bool enforce_newline,
- bool do_fsync,
+ WriteStringFileFlags flags,
struct timespec *ts) {
_cleanup_fclose_ FILE *f = NULL;
@@ -90,8 +93,8 @@ static int write_string_file_atomic(
(void) fchmod_umask(fileno(f), 0644);
- r = write_string_stream_ts(f, line, enforce_newline, ts);
- if (r >= 0 && do_fsync)
+ r = write_string_stream_ts(f, line, flags, ts);
+ if (r >= 0 && (flags & WRITE_STRING_FILE_SYNC))
r = fflush_sync_and_check(f);
if (r >= 0) {
if (rename(p, fn) < 0)
@@ -104,7 +107,12 @@ static int write_string_file_atomic(
return r;
}
-int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags flags, struct timespec *ts) {
+int write_string_file_ts(
+ const char *fn,
+ const char *line,
+ WriteStringFileFlags flags,
+ struct timespec *ts) {
+
_cleanup_fclose_ FILE *f = NULL;
int q, r;
@@ -117,10 +125,7 @@ int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags
if (flags & WRITE_STRING_FILE_ATOMIC) {
assert(flags & WRITE_STRING_FILE_CREATE);
- r = write_string_file_atomic(fn,
- line,
- !(flags & WRITE_STRING_FILE_AVOID_NEWLINE),
- flags & WRITE_STRING_FILE_SYNC, ts);
+ r = write_string_file_atomic(fn, line, flags, ts);
if (r < 0)
goto fail;
@@ -153,7 +158,7 @@ int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags
}
}
- r = write_string_stream_ts(f, line, !(flags & WRITE_STRING_FILE_AVOID_NEWLINE), ts);
+ r = write_string_stream_ts(f, line, flags, ts);
if (r < 0)
goto fail;