#define READ_FULL_BYTES_MAX (4U*1024U*1024U)
-int write_string_stream(FILE *f, const char *line, bool enforce_newline) {
+int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, struct timespec *ts) {
assert(f);
assert(line);
if (enforce_newline && !endswith(line, "\n"))
fputc('\n', f);
+ if (ts) {
+ struct timespec twice[2] = {*ts, *ts};
+
+ if (futimens(fileno(f), twice) < 0)
+ return -errno;
+ }
+
return fflush_and_check(f);
}
return r;
}
-int write_string_file(const char *fn, const char *line, WriteStringFileFlags flags) {
+int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags flags, struct timespec *ts) {
_cleanup_fclose_ FILE *f = NULL;
int q, r;
goto fail;
return r;
- }
+ } else
+ assert(ts == NULL);
if (flags & WRITE_STRING_FILE_CREATE) {
f = fopen(fn, "we");
}
}
- r = write_string_stream(f, line, !(flags & WRITE_STRING_FILE_AVOID_NEWLINE));
+ r = write_string_stream_ts(f, line, !(flags & WRITE_STRING_FILE_AVOID_NEWLINE), ts);
if (r < 0)
goto fail;
return 0;
}
-#endif // 0
int read_nul_string(FILE *f, char **ret) {
_cleanup_free_ char *x = NULL;
*ret = p;
return 0;
}
+#endif // 0