From 06692fdb5bf3d5e53f3f4847e1f8da18180075cb Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 8 Apr 2023 17:48:04 +0900 Subject: [PATCH] env-file: introduce parse_env_file_fdv() --- src/basic/env-file.c | 24 ++++++++++++++++++------ src/basic/env-file.h | 1 + 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/basic/env-file.c b/src/basic/env-file.c index 01ed443d5f4..7b3e209ddca 100644 --- a/src/basic/env-file.c +++ b/src/basic/env-file.c @@ -359,6 +359,23 @@ int parse_env_filev( return r; } +int parse_env_file_fdv(int fd, const char *fname, va_list ap) { + _cleanup_fclose_ FILE *f = NULL; + va_list aq; + int r; + + assert(fd >= 0); + + r = fdopen_independent(fd, "re", &f); + if (r < 0) + return r; + + va_copy(aq, ap); + r = parse_env_file_internal(f, fname, parse_env_file_push, &aq); + va_end(aq); + return r; +} + int parse_env_file_sentinel( FILE *f, const char *fname, @@ -381,18 +398,13 @@ int parse_env_file_fd_sentinel( const char *fname, /* only used for logging */ ...) { - _cleanup_fclose_ FILE *f = NULL; va_list ap; int r; assert(fd >= 0); - r = fdopen_independent(fd, "re", &f); - if (r < 0) - return r; - va_start(ap, fname); - r = parse_env_filev(f, fname, ap); + r = parse_env_file_fdv(fd, fname, ap); va_end(ap); return r; diff --git a/src/basic/env-file.h b/src/basic/env-file.h index fa22d2209c6..2465eeddf4d 100644 --- a/src/basic/env-file.h +++ b/src/basic/env-file.h @@ -8,6 +8,7 @@ #include "macro.h" int parse_env_filev(FILE *f, const char *fname, va_list ap); +int parse_env_file_fdv(int fd, 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_; -- 2.47.3