1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-05 06:52:22 +03:00

fileio: add take_fdopendir() variant

fdopendir() wrapper analogous to take_fdopen()
This commit is contained in:
Vito Caputo 2020-03-31 01:59:33 -07:00
parent 4fa744a35c
commit f61457b0fe
2 changed files with 13 additions and 0 deletions

View File

@ -80,6 +80,18 @@ FILE* take_fdopen(int *fd, const char *options) {
return f; 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* open_memstream_unlocked(char **ptr, size_t *sizeloc) {
FILE *f = open_memstream(ptr, sizeloc); FILE *f = open_memstream(ptr, sizeloc);
if (!f) if (!f)

View 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 fdopen_unlocked(int fd, const char *options, FILE **ret);
int take_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* take_fdopen(int *fd, const char *options);
DIR* take_fdopendir(int *dfd);
FILE* open_memstream_unlocked(char **ptr, size_t *sizeloc); FILE* open_memstream_unlocked(char **ptr, size_t *sizeloc);
FILE* fmemopen_unlocked(void *buf, size_t size, const char *mode); FILE* fmemopen_unlocked(void *buf, size_t size, const char *mode);