summaryrefslogtreecommitdiff
path: root/src/shared/conf-parser.h
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-12-27 10:34:24 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-01-19 14:57:59 +0900
commit307fe3cdf2d012c49b7bc39ea2d4251c6d44e93e (patch)
tree2c8fbdb318b1948cf032e7295fcfb978843e620d /src/shared/conf-parser.h
parente5c4289a9dc08a3d28360e24bd326cca11c9b9d6 (diff)
downloadsystemd-307fe3cdf2d012c49b7bc39ea2d4251c6d44e93e.tar.gz
network: rename NetworkConfigSection -> ConfigSection
And move it and relevant functions to conf-parser.[ch].
Diffstat (limited to 'src/shared/conf-parser.h')
-rw-r--r--src/shared/conf-parser.h37
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);