From: Yu Watanabe Date: Wed, 28 Aug 2024 04:11:43 +0000 (+0900) Subject: conf-parser: introduce config_parse_uint32_invert_flag() X-Git-Tag: v257-rc1~544^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff616da45903bdbb21b886361a0f9d84678681e0;p=thirdparty%2Fsystemd.git conf-parser: introduce config_parse_uint32_invert_flag() It is similar to config_parse_uint32_flag(), but drops the specified flag when true. --- diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index d29d113bbc0..6db94317086 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -1061,6 +1061,31 @@ int config_parse_uint32_flag( return 1; } +int config_parse_uint32_invert_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) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); + + 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 bd7caf1f462..c542839a927 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -274,6 +274,7 @@ 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_uint32_invert_flag); CONFIG_PARSER_PROTOTYPE(config_parse_id128); CONFIG_PARSER_PROTOTYPE(config_parse_tristate); CONFIG_PARSER_PROTOTYPE(config_parse_string);