1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

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".
This commit is contained in:
Peter Rajnoha 2013-03-05 17:10:30 +01:00
parent 386886f71c
commit 296385c0f3
2 changed files with 15 additions and 0 deletions

View File

@ -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);

View File

@ -928,6 +928,20 @@ int dm_config_find_bool(const struct dm_config_node *cn, const char *path, int f
return _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
**/