fileio: add new read_boolean_file() helper

This commit is contained in:
Lennart Poettering
2026-05-11 12:04:02 +02:00
parent 1b8a2b6abe
commit db8046535b
3 changed files with 72 additions and 0 deletions
+14
View File
@@ -431,6 +431,20 @@ int read_one_line_file_at(int dir_fd, const char *filename, char **ret) {
return read_line(f, LONG_LINE_MAX, ret);
}
int read_boolean_file_at(int dir_fd, const char *filename) {
_cleanup_free_ char *s = NULL;
int r;
assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
assert(filename);
r = read_one_line_file_at(dir_fd, filename, &s);
if (r < 0)
return r;
return parse_boolean(s);
}
int verify_file_at(int dir_fd, const char *fn, const char *blob, bool accept_extra_nl) {
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *buf = NULL;
+4
View File
@@ -63,6 +63,10 @@ int read_one_line_file_at(int dir_fd, const char *filename, char **ret);
static inline int read_one_line_file(const char *filename, char **ret) {
return read_one_line_file_at(AT_FDCWD, filename, ret);
}
int read_boolean_file_at(int dir_fd, const char *filename);
static inline int read_boolean_file(const char *filename) {
return read_boolean_file_at(AT_FDCWD, filename);
}
int read_full_file_full(int dir_fd, const char *filename, uint64_t offset, size_t size, ReadFullFileFlags flags, const char *bind_name, char **ret_contents, size_t *ret_size);
static inline int read_full_file_at(int dir_fd, const char *filename, char **ret_contents, size_t *ret_size) {
return read_full_file_full(dir_fd, filename, UINT64_MAX, SIZE_MAX, 0, NULL, ret_contents, ret_size);