diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-12-27 02:34:24 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-01-19 06:57:59 +0100 |
commit | 307fe3cdf2d012c49b7bc39ea2d4251c6d44e93e (patch) | |
tree | 2c8fbdb318b1948cf032e7295fcfb978843e620d /src/shared/conf-parser.h | |
parent | network: sr-iov: add missing assertion (diff) | |
download | systemd-307fe3cdf2d012c49b7bc39ea2d4251c6d44e93e.tar.xz systemd-307fe3cdf2d012c49b7bc39ea2d4251c6d44e93e.zip |
network: rename NetworkConfigSection -> ConfigSection
And move it and relevant functions to conf-parser.[ch].
Diffstat (limited to '')
-rw-r--r-- | src/shared/conf-parser.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index d686665532..1e03f93bce 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -114,6 +114,43 @@ int config_parse_many( void *userdata, Hashmap **ret_stats_by_path); /* possibly NULL */ +typedef struct ConfigSection { + unsigned line; + bool invalid; + char filename[]; +} ConfigSection; + +static inline ConfigSection* config_section_free(ConfigSection *cs) { + return mfree(cs); +} +DEFINE_TRIVIAL_CLEANUP_FUNC(ConfigSection*, config_section_free); + +int config_section_new(const char *filename, unsigned line, ConfigSection **s); +extern const struct hash_ops config_section_hash_ops; +unsigned hashmap_find_free_section_line(Hashmap *hashmap); + +static inline bool section_is_invalid(ConfigSection *section) { + /* If this returns false, then it does _not_ mean the section is valid. */ + + if (!section) + return false; + + return section->invalid; +} + +#define DEFINE_SECTION_CLEANUP_FUNCTIONS(type, free_func) \ + static inline type* free_func##_or_set_invalid(type *p) { \ + assert(p); \ + \ + if (p->section) \ + p->section->invalid = true; \ + else \ + free_func(p); \ + return NULL; \ + } \ + DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func); \ + DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func##_or_set_invalid); + CONFIG_PARSER_PROTOTYPE(config_parse_int); CONFIG_PARSER_PROTOTYPE(config_parse_unsigned); CONFIG_PARSER_PROTOTYPE(config_parse_long); |