summaryrefslogtreecommitdiff
path: root/src/basic/fileio.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-13 00:54:56 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-13 13:02:49 +0100
commiteb3da9012f462da2451edeb8d67c5b67c833a0b1 (patch)
treec009896e29778ebe5ac2fdcb140f5fdb27aa2788 /src/basic/fileio.h
parent87fde73e185fabc346ee4d9c9befe972e3502dc3 (diff)
downloadsystemd-eb3da9012f462da2451edeb8d67c5b67c833a0b1.tar.gz
systemd-eb3da9012f462da2451edeb8d67c5b67c833a0b1.tar.bz2
systemd-eb3da9012f462da2451edeb8d67c5b67c833a0b1.zip
util-lib: optionally, when writing a string to a file, verify string on failure
With this change, the idiom: r = write_string_file(p, buf, 0); if (r < 0) { if (verify_one_line_file(p, buf) > 0) r = 0; } gets reduced to: r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE); i.e. when writing the string fails and the new flag WRITE_STRING_FILE_VERIFY_ON_FAILURE is specified we'll not return a failure immediately, but check the contents of the file. If it matches what we wanted to write we suppress the error and exit cleanly.
Diffstat (limited to 'src/basic/fileio.h')
-rw-r--r--src/basic/fileio.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/basic/fileio.h b/src/basic/fileio.h
index 5f2c941498..95e8698941 100644
--- a/src/basic/fileio.h
+++ b/src/basic/fileio.h
@@ -34,6 +34,7 @@ typedef enum {
WRITE_STRING_FILE_CREATE = 1,
WRITE_STRING_FILE_ATOMIC = 2,
WRITE_STRING_FILE_AVOID_NEWLINE = 4,
+ WRITE_STRING_FILE_VERIFY_ON_FAILURE = 8,
} WriteStringFileFlags;
int write_string_stream(FILE *f, const char *line, bool enforce_newline);
@@ -43,7 +44,7 @@ int read_one_line_file(const char *fn, char **line);
int read_full_file(const char *fn, char **contents, size_t *size);
int read_full_stream(FILE *f, char **contents, size_t *size);
-int verify_one_line_file(const char *fn, const char *line);
+int verify_file(const char *fn, const char *blob, bool accept_extra_nl);
int parse_env_file(const char *fname, const char *separator, ...) _sentinel_;
int load_env_file(FILE *f, const char *fname, const char *separator, char ***l);