From: Yu Watanabe Date: Sun, 4 Oct 2020 13:16:46 +0000 (+0900) Subject: network: introduce hashmap_find_free_section_line() X-Git-Tag: v247-rc1~117^2~59 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=833f3663a07a868a023579801afb08522e3ecf79;p=thirdparty%2Fsystemd.git network: introduce hashmap_find_free_section_line() --- diff --git a/src/network/networkd-util.c b/src/network/networkd-util.c index ce9319d942a..bae4ee5cbac 100644 --- a/src/network/networkd-util.c +++ b/src/network/networkd-util.c @@ -151,3 +151,15 @@ int network_config_section_new(const char *filename, unsigned line, NetworkConfi void network_config_section_free(NetworkConfigSection *cs) { free(cs); } + +unsigned hashmap_find_free_section_line(Hashmap *hashmap) { + NetworkConfigSection *cs; + unsigned n = 0; + void *entry; + + HASHMAP_FOREACH_KEY(entry, cs, hashmap) + if (n < cs->line) + n = cs->line; + + return n + 1; +} diff --git a/src/network/networkd-util.h b/src/network/networkd-util.h index 2b6541d57ed..ce169fa731b 100644 --- a/src/network/networkd-util.h +++ b/src/network/networkd-util.h @@ -5,7 +5,7 @@ #include "sd-netlink.h" #include "conf-parser.h" -#include "hash-funcs.h" +#include "hashmap.h" #include "log.h" #include "macro.h" #include "string-util.h" @@ -52,6 +52,7 @@ int network_config_section_new(const char *filename, unsigned line, NetworkConfi void network_config_section_free(NetworkConfigSection *network); DEFINE_TRIVIAL_CLEANUP_FUNC(NetworkConfigSection*, network_config_section_free); extern const struct hash_ops network_config_hash_ops; +unsigned hashmap_find_free_section_line(Hashmap *hashmap); static inline bool section_is_invalid(NetworkConfigSection *section) { /* If this returns false, then it does _not_ mean the section is valid. */