]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
a5c32cff HH |
2 | #pragma once |
3 | ||
0d39fa9c LP |
4 | #include <dirent.h> |
5 | #include <stdbool.h> | |
a5c32cff | 6 | #include <stddef.h> |
b4bc041b | 7 | #include <stdio.h> |
0d39fa9c | 8 | #include <sys/types.h> |
b4bc041b | 9 | |
a5c32cff | 10 | #include "macro.h" |
33d52ab9 | 11 | #include "time-util.h" |
a5c32cff | 12 | |
4c1fc3e4 | 13 | typedef enum { |
ef31828d LP |
14 | WRITE_STRING_FILE_CREATE = 1 << 0, |
15 | WRITE_STRING_FILE_ATOMIC = 1 << 1, | |
16 | WRITE_STRING_FILE_AVOID_NEWLINE = 1 << 2, | |
17 | WRITE_STRING_FILE_VERIFY_ON_FAILURE = 1 << 3, | |
18 | WRITE_STRING_FILE_SYNC = 1 << 4, | |
19 | WRITE_STRING_FILE_DISABLE_BUFFER = 1 << 5, | |
7d7a99ac LP |
20 | |
21 | /* And before you wonder, why write_string_file_atomic_label_ts() is a separate function instead of just one | |
22 | more flag here: it's about linking: we don't want to pull -lselinux into all users of write_string_file() | |
23 | and friends. */ | |
24 | ||
4c1fc3e4 DM |
25 | } WriteStringFileFlags; |
26 | ||
b1837133 LP |
27 | int write_string_stream_ts(FILE *f, const char *line, WriteStringFileFlags flags, struct timespec *ts); |
28 | static inline int write_string_stream(FILE *f, const char *line, WriteStringFileFlags flags) { | |
29 | return write_string_stream_ts(f, line, flags, NULL); | |
39c38d77 ZJS |
30 | } |
31 | int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags flags, struct timespec *ts); | |
32 | static inline int write_string_file(const char *fn, const char *line, WriteStringFileFlags flags) { | |
33 | return write_string_file_ts(fn, line, flags, NULL); | |
34 | } | |
b4bc041b | 35 | |
3130fca5 LP |
36 | int write_string_filef(const char *fn, WriteStringFileFlags flags, const char *format, ...) _printf_(3, 4); |
37 | ||
a5c32cff HH |
38 | int read_one_line_file(const char *fn, char **line); |
39 | int read_full_file(const char *fn, char **contents, size_t *size); | |
717603e3 | 40 | int read_full_stream(FILE *f, char **contents, size_t *size); |
a5c32cff | 41 | |
eb3da901 | 42 | int verify_file(const char *fn, const char *blob, bool accept_extra_nl); |
15dee3f0 | 43 | |
080dfda8 | 44 | int parse_env_filev(FILE *f, const char *fname, const char *separator, va_list ap); |
1a5a177e | 45 | int parse_env_file(FILE *f, const char *fname, const char *separator, ...) _sentinel_; |
717603e3 LP |
46 | int load_env_file(FILE *f, const char *fname, const char *separator, char ***l); |
47 | int load_env_file_pairs(FILE *f, const char *fname, const char *separator, char ***l); | |
48 | ||
37f3ffca RS |
49 | int merge_env_file(char ***env, FILE *f, const char *fname); |
50 | ||
a5c32cff | 51 | int write_env_file(const char *fname, char **l); |
68fee104 ZJS |
52 | |
53 | int executable_is_script(const char *path, char **interpreter); | |
69ab8088 | 54 | |
c4cd1d4d | 55 | int get_proc_field(const char *filename, const char *pattern, const char *terminator, char **field); |
0d39fa9c LP |
56 | |
57 | DIR *xopendirat(int dirfd, const char *name, int flags); | |
58 | ||
59 | int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f); | |
60 | int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f); | |
61 | ||
0d39fa9c | 62 | int fflush_and_check(FILE *f); |
0675e94a | 63 | int fflush_sync_and_check(FILE *f); |
0d39fa9c LP |
64 | |
65 | int fopen_temporary(const char *path, FILE **_f, char **_temp_path); | |
646853bd | 66 | int mkostemp_safe(char *pattern); |
d8351049 | 67 | int fmkostemp_safe(char *pattern, const char *mode, FILE**_f); |
0d39fa9c LP |
68 | |
69 | int tempfn_xxxxxx(const char *p, const char *extra, char **ret); | |
70 | int tempfn_random(const char *p, const char *extra, char **ret); | |
71 | int tempfn_random_child(const char *p, const char *extra, char **ret); | |
33d52ab9 LP |
72 | |
73 | int write_timestamp_file_atomic(const char *fn, usec_t n); | |
74 | int read_timestamp_file(const char *fn, usec_t *ret); | |
d390f8ef LP |
75 | |
76 | int fputs_with_space(FILE *f, const char *s, const char *separator, bool *space); | |
03532f0a LP |
77 | |
78 | int open_tmpfile_unlinkable(const char *directory, int flags); | |
79 | int open_tmpfile_linkable(const char *target, int flags, char **ret_path); | |
504afd7c | 80 | int open_serialization_fd(const char *ident); |
03532f0a LP |
81 | |
82 | int link_tmpfile(int fd, const char *path, const char *target); | |
03c2b288 LP |
83 | |
84 | int read_nul_string(FILE *f, char **ret); | |
676bcb0f LP |
85 | |
86 | int mkdtemp_malloc(const char *template, char **ret); | |
4f9a66a3 LP |
87 | |
88 | int read_line(FILE *f, size_t limit, char **ret); |