]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/fileio.h
Merge pull request #5276 from poettering/resolved-cname
[thirdparty/systemd.git] / src / basic / fileio.h
CommitLineData
a5c32cff
HH
1#pragma once
2
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
0d39fa9c
LP
21
22#include <dirent.h>
23#include <stdbool.h>
a5c32cff 24#include <stddef.h>
b4bc041b 25#include <stdio.h>
0d39fa9c 26#include <sys/types.h>
b4bc041b 27
a5c32cff 28#include "macro.h"
33d52ab9 29#include "time-util.h"
a5c32cff 30
4c1fc3e4
DM
31typedef enum {
32 WRITE_STRING_FILE_CREATE = 1,
33 WRITE_STRING_FILE_ATOMIC = 2,
34 WRITE_STRING_FILE_AVOID_NEWLINE = 4,
eb3da901 35 WRITE_STRING_FILE_VERIFY_ON_FAILURE = 8,
4c1fc3e4
DM
36} WriteStringFileFlags;
37
40beecdb 38int write_string_stream(FILE *f, const char *line, bool enforce_newline);
4c1fc3e4 39int write_string_file(const char *fn, const char *line, WriteStringFileFlags flags);
b4bc041b 40
a5c32cff
HH
41int read_one_line_file(const char *fn, char **line);
42int read_full_file(const char *fn, char **contents, size_t *size);
717603e3 43int read_full_stream(FILE *f, char **contents, size_t *size);
a5c32cff 44
eb3da901 45int verify_file(const char *fn, const char *blob, bool accept_extra_nl);
15dee3f0 46
a5c32cff 47int parse_env_file(const char *fname, const char *separator, ...) _sentinel_;
717603e3
LP
48int load_env_file(FILE *f, const char *fname, const char *separator, char ***l);
49int load_env_file_pairs(FILE *f, const char *fname, const char *separator, char ***l);
50
a5c32cff 51int write_env_file(const char *fname, char **l);
68fee104
ZJS
52
53int executable_is_script(const char *path, char **interpreter);
69ab8088 54
c4cd1d4d 55int get_proc_field(const char *filename, const char *pattern, const char *terminator, char **field);
0d39fa9c
LP
56
57DIR *xopendirat(int dirfd, const char *name, int flags);
58
59int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f);
60int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f);
61
62#define FOREACH_LINE(line, f, on_error) \
63 for (;;) \
64 if (!fgets(line, sizeof(line), f)) { \
65 if (ferror(f)) { \
66 on_error; \
67 } \
68 break; \
69 } else
70
71int fflush_and_check(FILE *f);
72
73int fopen_temporary(const char *path, FILE **_f, char **_temp_path);
646853bd 74int mkostemp_safe(char *pattern);
0d39fa9c
LP
75
76int tempfn_xxxxxx(const char *p, const char *extra, char **ret);
77int tempfn_random(const char *p, const char *extra, char **ret);
78int tempfn_random_child(const char *p, const char *extra, char **ret);
33d52ab9
LP
79
80int write_timestamp_file_atomic(const char *fn, usec_t n);
81int read_timestamp_file(const char *fn, usec_t *ret);
d390f8ef
LP
82
83int fputs_with_space(FILE *f, const char *s, const char *separator, bool *space);
03532f0a
LP
84
85int open_tmpfile_unlinkable(const char *directory, int flags);
86int open_tmpfile_linkable(const char *target, int flags, char **ret_path);
87
88int link_tmpfile(int fd, const char *path, const char *target);
03c2b288
LP
89
90int read_nul_string(FILE *f, char **ret);
676bcb0f
LP
91
92int mkdtemp_malloc(const char *template, char **ret);