1 /* SPDX-License-Identifier: LGPL-2.1+ */
11 #include "time-util.h"
13 #define LONG_LINE_MAX (1U*1024U*1024U)
16 WRITE_STRING_FILE_CREATE
= 1 << 0,
17 WRITE_STRING_FILE_ATOMIC
= 1 << 1,
18 WRITE_STRING_FILE_AVOID_NEWLINE
= 1 << 2,
19 WRITE_STRING_FILE_VERIFY_ON_FAILURE
= 1 << 3,
20 WRITE_STRING_FILE_SYNC
= 1 << 4,
21 WRITE_STRING_FILE_DISABLE_BUFFER
= 1 << 5,
22 WRITE_STRING_FILE_NOFOLLOW
= 1 << 6,
24 /* And before you wonder, why write_string_file_atomic_label_ts() is a separate function instead of just one
25 more flag here: it's about linking: we don't want to pull -lselinux into all users of write_string_file()
28 } WriteStringFileFlags
;
30 int write_string_stream_ts(FILE *f
, const char *line
, WriteStringFileFlags flags
, struct timespec
*ts
);
31 static inline int write_string_stream(FILE *f
, const char *line
, WriteStringFileFlags flags
) {
32 return write_string_stream_ts(f
, line
, flags
, NULL
);
34 int write_string_file_ts(const char *fn
, const char *line
, WriteStringFileFlags flags
, struct timespec
*ts
);
35 static inline int write_string_file(const char *fn
, const char *line
, WriteStringFileFlags flags
) {
36 return write_string_file_ts(fn
, line
, flags
, NULL
);
39 int write_string_filef(const char *fn
, WriteStringFileFlags flags
, const char *format
, ...) _printf_(3, 4);
41 int read_one_line_file(const char *fn
, char **line
);
42 int read_full_file(const char *fn
, char **contents
, size_t *size
);
43 int read_full_stream(FILE *f
, char **contents
, size_t *size
);
45 int verify_file(const char *fn
, const char *blob
, bool accept_extra_nl
);
47 int executable_is_script(const char *path
, char **interpreter
);
49 int get_proc_field(const char *filename
, const char *pattern
, const char *terminator
, char **field
);
51 DIR *xopendirat(int dirfd
, const char *name
, int flags
);
53 int search_and_fopen(const char *path
, const char *mode
, const char *root
, const char **search
, FILE **_f
);
54 int search_and_fopen_nulstr(const char *path
, const char *mode
, const char *root
, const char *search
, FILE **_f
);
56 int fflush_and_check(FILE *f
);
57 int fflush_sync_and_check(FILE *f
);
59 int write_timestamp_file_atomic(const char *fn
, usec_t n
);
60 int read_timestamp_file(const char *fn
, usec_t
*ret
);
62 int fputs_with_space(FILE *f
, const char *s
, const char *separator
, bool *space
);
64 int read_nul_string(FILE *f
, char **ret
);
66 int read_line(FILE *f
, size_t limit
, char **ret
);