Debian Codegraph @

src/basic/tmpfile-util.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "basic-forward.h"
5
6 int fopen_temporary_at(int dir_fd, const char *path, FILE **ret_file, char **ret_path);
7 static inline int fopen_temporary(const char *path, FILE **ret_file, char **ret_path) {
8 return fopen_temporary_at(AT_FDCWD, path, ret_file, ret_path);
9 }
10
11 int fopen_temporary_child_at(int dir_fd, const char *path, FILE **ret_file, char **ret_path);
12 static inline int fopen_temporary_child(const char *path, FILE **ret_file, char **ret_path) {
13 return fopen_temporary_child_at(AT_FDCWD, path, ret_file, ret_path);
14 }
15
16 int mkostemp_safe(char *pattern);
17 int fmkostemp_safe(char *pattern, const char *mode, FILE**_f);
18
19 void unlink_tempfilep(char (*p)[]);
20
21 int tempfn_xxxxxx(const char *p, const char *extra, char **ret);
22 int tempfn_random(const char *p, const char *extra, char **ret);
23 int tempfn_random_child(const char *p, const char *extra, char **ret);
24
25 int open_tmpfile_unlinkable(const char *directory, int flags);
26 int open_tmpfile_linkable_at(int dir_fd, const char *target, int flags, char **ret_path);
27 static inline int open_tmpfile_linkable(const char *target, int flags, char **ret_path) {
28 return open_tmpfile_linkable_at(AT_FDCWD, target, flags, ret_path);
29 }
30 int fopen_tmpfile_linkable_at(int dir_fd, const char *target, int flags, char **ret_path, FILE **ret_file);
31 static inline int fopen_tmpfile_linkable(const char *target, int flags, char **ret_path, FILE **ret_file) {
32 return fopen_tmpfile_linkable_at(AT_FDCWD, target, flags, ret_path, ret_file);
33 }
34
35 typedef enum LinkTmpfileFlags {
36 LINK_TMPFILE_REPLACE = 1 << 0,
37 LINK_TMPFILE_SYNC = 1 << 1,
38 } LinkTmpfileFlags;
39
40 int link_tmpfile_at(int fd, int dir_fd, const char *path, const char *target, LinkTmpfileFlags flags);
41 static inline int link_tmpfile(int fd, const char *path, const char *target, LinkTmpfileFlags flags) {
42 return link_tmpfile_at(fd, AT_FDCWD, path, target, flags);
43 }
44 int flink_tmpfile_at(FILE *f, int dir_fd, const char *path, const char *target, LinkTmpfileFlags flags);
45 static inline int flink_tmpfile(FILE *f, const char *path, const char *target, LinkTmpfileFlags flags) {
46 return flink_tmpfile_at(f, AT_FDCWD, path, target, flags);
47 }
48
49 int mkdtemp_malloc(const char *template, char **ret);
50 int mkdtemp_open(const char *template, int flags, char **ret);
51
52 /* A helper for removing link_tmpfile_at() via _cleanup_() */
53 struct cleanup_tmpfile_data {
54 int *dir_fd;
55 char **filename;
56 };
57 void cleanup_tmpfile_data_done(struct cleanup_tmpfile_data *d);
58 #define _CLEANUP_TMPFILE_AT(u, dir_fd, filename) \
59 _unused_ _cleanup_(cleanup_tmpfile_data_done) struct cleanup_tmpfile_data UNIQ_T(cta, u) = { &(dir_fd), &(filename) }
60 #define CLEANUP_TMPFILE_AT(dir_fd, filename) \
61 _CLEANUP_TMPFILE_AT(UNIQ, dir_fd, filename)