diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2011-01-17 19:22:53 +0000 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2011-01-17 19:29:45 +0000 |
commit | 2b7c2b8cf1248c5cea7c56ad1a3141973a34fe0a (patch) | |
tree | d06954d40aa8a2f2aefba84c9767f54cff98f2ce /src/librc/librc-misc.c | |
parent | 6e876bca1313d0cc2ef576da15124a9082f404db (diff) |
Bug #351570: Hidden function fixes: rc_conf_value.
Refactor rc_conf_value into librc for use in library context.
Also requires moving:
- rc_conf internal static
- Defines: PROFILE_ENV, SYS_WHITELIST, USR_WHITELIST, RC_PATH_PREFIX
moved to rc.h with new RC_ prefix added.
- Defines: RC_CONF, RC_CONF_OLD moved to rc.h.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Diffstat (limited to 'src/librc/librc-misc.c')
-rw-r--r-- | src/librc/librc-misc.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c index f83745f2..b7c4108e 100644 --- a/src/librc/librc-misc.c +++ b/src/librc/librc-misc.c @@ -218,3 +218,54 @@ rc_config_value(RC_STRINGLIST *list, const char *entry) return NULL; } librc_hidden_def(rc_config_value) + +/* Global for caching the strings loaded from rc.conf to avoid reparsing for + * each rc_conf_value call */ +static RC_STRINGLIST *rc_conf = NULL; + +char * +rc_conf_value(const char *setting) +{ + RC_STRINGLIST *old; + RC_STRING *s; + char *p; + + if (! rc_conf) { + rc_conf = rc_config_load(RC_CONF); +#ifdef DEBUG_MEMORY + atexit(_free_rc_conf); +#endif + + /* Support old configs */ + if (exists(RC_CONF_OLD)) { + old = rc_config_load(RC_CONF_OLD); + TAILQ_CONCAT(rc_conf, old, entries); +#ifdef DEBUG_MEMORY + free(old); +#endif + } + + /* Convert old uppercase to lowercase */ + TAILQ_FOREACH(s, rc_conf, entries) { + p = s->value; + while (p && *p && *p != '=') { + if (isupper((unsigned char)*p)) + *p = tolower((unsigned char)*p); + p++; + } + } + } + + return rc_config_value(rc_conf, setting); +} +librc_hidden_def(rc_conf_value) + +#ifdef DEBUG_MEMORY +static void +_free_rc_conf(void) +{ + rc_stringlist_free(rc_conf); +} +#endif + + |