diff options
author | Krzysztof Opasiak <k.opasiak@samsung.com> | 2015-12-22 23:36:59 +0100 |
---|---|---|
committer | Krzysztof Opasiak <k.opasiak@samsung.com> | 2015-12-23 00:49:03 +0100 |
commit | f029af5061f37c07b4dab138af907608e844272c (patch) | |
tree | 15708a55020c5f149a7021390667d931233552bf /src | |
parent | 66533cd7e1d4f4d80ba4e3cd43b086756c7b4563 (diff) | |
download | libusbg-f029af5061f37c07b4dab138af907608e844272c.tar.gz libusbg-f029af5061f37c07b4dab138af907608e844272c.tar.bz2 libusbg-f029af5061f37c07b4dab138af907608e844272c.zip |
libusbgx: common: Add helper for getting and setting string values
Add helper functions which allows to get and set string values
from both configfs and libconfig files.
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/usbg_common.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/usbg_common.c b/src/usbg_common.c index 1840445..7d9afca 100644 --- a/src/usbg_common.c +++ b/src/usbg_common.c @@ -284,6 +284,23 @@ int usbg_get_config_node_int(config_setting_t *root, return 1; } +int usbg_get_config_node_string(config_setting_t *root, + const char *node_name, void *val) +{ + config_setting_t *node; + + node = config_setting_get_member(root, node_name); + if (!node) + return 0; + + if (!usbg_config_is_string(node)) + return USBG_ERROR_INVALID_TYPE; + + *(const char **)val = config_setting_get_string(node); + + return 1; +} + int usbg_set_config_node_int(config_setting_t *root, const char *node_name, void *val) { @@ -299,3 +316,18 @@ int usbg_set_config_node_int(config_setting_t *root, return ret == CONFIG_TRUE ? 0 : USBG_ERROR_OTHER_ERROR; } +int usbg_set_config_node_string(config_setting_t *root, + const char *node_name, void *val) +{ + config_setting_t *node; + int ret = 0; + + node = config_setting_add(root, node_name, CONFIG_TYPE_STRING); + if (!node) + return USBG_ERROR_NO_MEM; + + ret = config_setting_set_string(node, *(char **)val); + + return ret == CONFIG_TRUE ? 0 : USBG_ERROR_OTHER_ERROR; +} + |