diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-09-22 17:55:53 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-09-25 14:40:23 +0200 |
commit | e269048bf8b638a5fa8451fdfae104d353a208be (patch) | |
tree | 413cdfb740b5bc2c6dad74b19d314fdc6be791c2 /src/basic/fileio.h | |
parent | 346e1907ca4800b8998c40138f9f2c1fcd53891b (diff) |
fileio: add new helper call read_line() as bounded getline() replacement
read_line() is much like getline(), and returns a line read from a
FILE*, of arbitrary sizes. In contrast to gets() it will grow the buffer
dynamically, and in contrast to getline() it will place a user-specified
boundary on the line.
Diffstat (limited to 'src/basic/fileio.h')
-rw-r--r-- | src/basic/fileio.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/basic/fileio.h b/src/basic/fileio.h index fa223fdf5..2ff3b434d 100644 --- a/src/basic/fileio.h +++ b/src/basic/fileio.h @@ -29,10 +29,11 @@ #include "time-util.h" 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, + WRITE_STRING_FILE_CREATE = 1<<0, + WRITE_STRING_FILE_ATOMIC = 1<<1, + WRITE_STRING_FILE_AVOID_NEWLINE = 1<<2, + WRITE_STRING_FILE_VERIFY_ON_FAILURE = 1<<3, + WRITE_STRING_FILE_SYNC = 1<<4, } WriteStringFileFlags; int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, struct timespec *ts); @@ -83,6 +84,7 @@ int search_and_fopen_nulstr(const char *path, const char *mode, const char *root } else int fflush_and_check(FILE *f); +int fflush_sync_and_check(FILE *f); int fopen_temporary(const char *path, FILE **_f, char **_temp_path); int mkostemp_safe(char *pattern); @@ -111,3 +113,5 @@ int read_nul_string(FILE *f, char **ret); int mkdtemp_malloc(const char *template, char **ret); #endif // 0 + +int read_line(FILE *f, size_t limit, char **ret); |