From 6db311fdc82f25bfdedd2b5f97a185f05ee10d09 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 25 Aug 2024 04:56:43 +0900 Subject: [PATCH] conf-parser: introduce config_parse_uint32_flag() This is not used currently, but will be used later. --- src/shared/conf-parser.c | 29 +++++++++++++++++++++++++++++ src/shared/conf-parser.h | 1 + 2 files changed, 30 insertions(+) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index d33ee8a9b0f..ac0df88b4d5 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -1008,6 +1008,35 @@ int config_parse_bool( return 1; /* set */ } +int config_parse_uint32_flag( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + uint32_t *flags = ASSERT_PTR(data); + int r; + + assert(ltype != 0); + + r = isempty(rvalue) ? 0 : parse_boolean(rvalue); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to parse %s=%s. Ignoring assignment: %m", + lvalue, rvalue); + return 0; + } + + SET_FLAG(*flags, ltype, r); + return 1; +} + int config_parse_id128( const char *unit, const char *filename, diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 94f81a3bd63..ad40c6224c5 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -254,6 +254,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_si_uint64); CONFIG_PARSER_PROTOTYPE(config_parse_iec_uint64); CONFIG_PARSER_PROTOTYPE(config_parse_iec_uint64_infinity); CONFIG_PARSER_PROTOTYPE(config_parse_bool); +CONFIG_PARSER_PROTOTYPE(config_parse_uint32_flag); CONFIG_PARSER_PROTOTYPE(config_parse_id128); CONFIG_PARSER_PROTOTYPE(config_parse_tristate); CONFIG_PARSER_PROTOTYPE(config_parse_string);