master - libdevmapper: add dm_config_value_is_bool function
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=296385c0f3fa5176704c42f92210e7c5d38996ad Commit: 296385c0f3fa5176704c42f92210e7c5d38996ad Parent: 386886f71c3da0945f47edf1a7063a04ba9b56d1 Author: Peter Rajnoha <[email protected]> AuthorDate: Tue Mar 5 17:10:30 2013 +0100 Committer: Peter Rajnoha <[email protected]> CommitterDate: Wed Mar 6 10:14:33 2013 +0100
libdevmapper: add dm_config_value_is_bool function
Export this functionality from libdevmapper just for convenience and general use when reading boolean values which could be defined either in a numeric way with 0/1 or by using strings with "true"/"false", "yes"/"no", "on"/"off", "y"/"n".
--- libdm/libdevmapper.h | 1 + libdm/libdm-config.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 0 deletions(-)
libdm/libdevmapper.h +1 -0
@@ -1555,6 +1555,7 @@ int dm_config_tree_find_bool(const struct dm_config_tree *cft, const char *path,* off), (true, false). */ int dm_config_find_bool (const struct dm_config_node *cn,const char *path,int fail); +int dm_config_value_is_bool (const struct dm_config_value *v);int dm_config_get_uint32 (const struct dm_config_node *cn,const char *path,uint32_t *result);int dm_config_get_uint64 (const struct dm_config_node *cn,const char *path,uint64_t *result);
libdm/libdm-config.c +14 -0
@@ -928,6 +928,20 @@ int dm_config_find_bool(const struct dm_config_node *cn, const char *path, int freturn _find_config_bool (cn, _find_config_node, path, fail); } +int dm_config_value_is_bool (const struct dm_config_value *v) { +if (!v) +return 0 ; + +switch (v->type) { +case DM_CFG_INT : +return 1 ; +case DM_CFG_STRING : +return _str_to_bool (v->v.str,-1 ) !=-1 ; +default : +return 0 ; + } +} +/*********************************** * tree-based lookup **/