]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fileio: add take_fdopendir() variant
authorVito Caputo <vcaputo@pengaru.com>
Tue, 31 Mar 2020 08:59:33 +0000 (01:59 -0700)
committerVito Caputo <vcaputo@pengaru.com>
Tue, 31 Mar 2020 13:48:03 +0000 (06:48 -0700)
fdopendir() wrapper analogous to take_fdopen()

src/basic/fileio.c
src/basic/fileio.h

index c82a9d2c01dee6f704be0e54d37cf76246d1554f..4c365ad6fa9149355a7cc8a0530cd4868a419c5e 100644 (file)
@@ -80,6 +80,18 @@ FILE* take_fdopen(int *fd, const char *options) {
         return f;
 }
 
+DIR* take_fdopendir(int *dfd) {
+        assert(dfd);
+
+        DIR *d = fdopendir(*dfd);
+        if (!d)
+                return NULL;
+
+        *dfd = -1;
+
+        return d;
+}
+
 FILE* open_memstream_unlocked(char **ptr, size_t *sizeloc) {
         FILE *f = open_memstream(ptr, sizeloc);
         if (!f)
index 525f6ac814a1f48f51489ac5e91609c1532dffd8..58daabaa8ffdbe8eee2dbbf8e5fa300840097e89 100644 (file)
@@ -41,6 +41,7 @@ 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);
+DIR* take_fdopendir(int *dfd);
 FILE* open_memstream_unlocked(char **ptr, size_t *sizeloc);
 FILE* fmemopen_unlocked(void *buf, size_t size, const char *mode);