diff options
author | Krzysztof Opasiak <k.opasiak@samsung.com> | 2016-12-16 12:59:09 +0100 |
---|---|---|
committer | Krzysztof Opasiak <k.opasiak@samsung.com> | 2017-03-03 14:02:27 +0100 |
commit | 784e693fe5b397516b8b8521386205512e989c70 (patch) | |
tree | d560c9e1add6a5497741d6be246d4adc7d17ecda | |
parent | 71f93716df8e3e93b5cdc307938a913e1a3058a5 (diff) | |
download | libusbg-784e693fe5b397516b8b8521386205512e989c70.tar.gz libusbg-784e693fe5b397516b8b8521386205512e989c70.tar.bz2 libusbg-784e693fe5b397516b8b8521386205512e989c70.zip |
libusbgx: common: Allow to export int attribute in hex format
Add a helper to export int attributes in hex format.
Now each function may decide which format should be used
(decimal or hex).
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r-- | include/usbg/usbg_internal.h | 3 | ||||
-rw-r--r-- | src/usbg_common.c | 19 |
2 files changed, 22 insertions, 0 deletions
diff --git a/include/usbg/usbg_internal.h b/include/usbg/usbg_internal.h index 2f59865..edfdccb 100644 --- a/include/usbg/usbg_internal.h +++ b/include/usbg/usbg_internal.h @@ -397,6 +397,9 @@ int usbg_get_config_node_ether_addr(config_setting_t *root, int usbg_set_config_node_int(config_setting_t *root, const char *node_name, void *val); +int usbg_set_config_node_int_hex(config_setting_t *root, + const char *node_name, void *val); + int usbg_set_config_node_bool(config_setting_t *root, const char *node_name, void *val); diff --git a/src/usbg_common.c b/src/usbg_common.c index 948cce8..d3040c8 100644 --- a/src/usbg_common.c +++ b/src/usbg_common.c @@ -451,6 +451,25 @@ int usbg_set_config_node_int(config_setting_t *root, return ret == CONFIG_TRUE ? 0 : USBG_ERROR_OTHER_ERROR; } +int usbg_set_config_node_int_hex(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_INT); + if (!node) + return USBG_ERROR_NO_MEM; + + ret = config_setting_set_format(node, CONFIG_FORMAT_HEX); + if (ret != CONFIG_TRUE) + return USBG_ERROR_OTHER_ERROR; + + ret = config_setting_set_int(node, *(int *)val); + + return ret == CONFIG_TRUE ? 0 : USBG_ERROR_OTHER_ERROR; +} + int usbg_set_config_node_bool(config_setting_t *root, const char *node_name, void *val) { |