diff options
-rw-r--r-- | src/basic/env-file.c | 29 | ||||
-rw-r--r-- | src/basic/env-file.h | 2 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/basic/env-file.c b/src/basic/env-file.c index af82ddfb63..5a4b21ee6a 100644 --- a/src/basic/env-file.c +++ b/src/basic/env-file.c @@ -376,6 +376,35 @@ int parse_env_file_sentinel( return r; } +int parse_env_file_fd_sentinel( + int fd, + const char *fname, /* only used for logging */ + ...) { + + _cleanup_close_ int fd_ro = -EBADFD; + _cleanup_fclose_ FILE *f = NULL; + va_list ap; + int r; + + assert(fd >= 0); + + fd_ro = fd_reopen(fd, O_CLOEXEC | O_RDONLY); + if (fd_ro < 0) + return fd_ro; + + f = fdopen(fd_ro, "re"); + if (!f) + return -errno; + + TAKE_FD(fd_ro); + + va_start(ap, fname); + r = parse_env_filev(f, fname, ap); + va_end(ap); + + return r; +} + static int load_env_file_push( const char *filename, unsigned line, const char *key, char *value, diff --git a/src/basic/env-file.h b/src/basic/env-file.h index 8da451c74a..2448d943cd 100644 --- a/src/basic/env-file.h +++ b/src/basic/env-file.h @@ -9,6 +9,8 @@ int parse_env_filev(FILE *f, const char *fname, va_list ap); int parse_env_file_sentinel(FILE *f, const char *fname, ...) _sentinel_; #define parse_env_file(f, fname, ...) parse_env_file_sentinel(f, fname, __VA_ARGS__, NULL) +int parse_env_file_fd_sentinel(int fd, const char *fname, ...) _sentinel_; +#define parse_env_file_fd(fd, fname, ...) parse_env_file_fd_sentinel(fd, fname, __VA_ARGS__, NULL) int load_env_file(FILE *f, const char *fname, char ***ret); int load_env_file_pairs(FILE *f, const char *fname, char ***ret); |