This patch adds functions that will set and lock a certain value. The intended use of these methods is to give command line options priority over the configuration file.
Signed-off-by: Richard Cochran <richardcoch...@gmail.com> --- config.c | 28 ++++++++++++++++++++++++++++ config.h | 3 +++ 2 files changed, 31 insertions(+) diff --git a/config.c b/config.c index 9a240d7..817f625 100644 --- a/config.c +++ b/config.c @@ -1054,3 +1054,31 @@ unsigned int config_get_uint(struct config *cfg, const char *port, pr_debug("config item %s.%s is %u", port, option, ci->val.u); return ci->val.u; } + +int config_set_double(struct config *cfg, const char *option, double val) +{ + struct config_item *ci = config_find_item(cfg, NULL, option); + + if (!ci || ci->type != CFG_TYPE_DOUBLE) { + pr_err("bug: config option %s missing or invalid!", option); + return -1; + } + ci->flags |= CFG_ITEM_LOCKED; + ci->val.d = val; + pr_debug("config item global.%s locked as %f", option, ci->val.d); + return 0; +} + +int config_set_int(struct config *cfg, const char *option, int val) +{ + struct config_item *ci = config_find_item(cfg, NULL, option); + + if (!ci || ci->type != CFG_TYPE_INT) { + pr_err("bug: config option %s missing or invalid!", option); + return -1; + } + ci->flags |= CFG_ITEM_LOCKED; + ci->val.i = val; + pr_debug("config item global.%s locked as %d", option, ci->val.i); + return 0; +} diff --git a/config.h b/config.h index 1b9192d..dd45d7e 100644 --- a/config.h +++ b/config.h @@ -114,4 +114,7 @@ int config_get_int(struct config *cfg, const char *port, unsigned int config_get_uint(struct config *cfg, const char *port, const char *option); +int config_set_double(struct config *cfg, const char *option, double val); +int config_set_int(struct config *cfg, const char *option, int val); + #endif -- 2.1.4 ------------------------------------------------------------------------------ _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel