summaryrefslogtreecommitdiffstats
path: root/src/basic/fileio.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2020-03-31 09:49:07 +0200
committerVito Caputo <vcaputo@pengaru.com>2020-03-31 15:48:00 +0200
commit3ebbb6cb394f8a328a9bba782e3b1cbeac4d9a7b (patch)
tree6dbf669b9ba1637652f35bfeb088286f7237124b /src/basic/fileio.h
parenthome: narrow scope of 'size_t n' (diff)
downloadsystemd-3ebbb6cb394f8a328a9bba782e3b1cbeac4d9a7b.tar.xz
systemd-3ebbb6cb394f8a328a9bba782e3b1cbeac4d9a7b.zip
fileio: introduce take_fdopen{_unlocked}() variant
With the addition of _cleanup_close_ there's a repetitious pattern of assigning -1 to the fd after a successful fdopen to prevent its close on cleanup now that the FILE * owns the fd. This introduces a wrapper that instead takes a pointer to the fd being opened, and always overwrites the fd with -1 on success. A future commit will cleanup all the fdopen call sites to use the wrapper and elide the manual -1 fd assignment.
Diffstat (limited to 'src/basic/fileio.h')
-rw-r--r--src/basic/fileio.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/basic/fileio.h b/src/basic/fileio.h
index e6fea2afd4..525f6ac814 100644
--- a/src/basic/fileio.h
+++ b/src/basic/fileio.h
@@ -39,6 +39,8 @@ typedef enum {
int fopen_unlocked(const char *path, const char *options, FILE **ret);
int fdopen_unlocked(int fd, const char *options, FILE **ret);
+int take_fdopen_unlocked(int *fd, const char *options, FILE **ret);
+FILE* take_fdopen(int *fd, const char *options);
FILE* open_memstream_unlocked(char **ptr, size_t *sizeloc);
FILE* fmemopen_unlocked(void *buf, size_t size, const char *mode);