summaryrefslogtreecommitdiffstats
path: root/pcilib/value.c
diff options
context:
space:
mode:
authorVasilii Chernov <vchernov@inr.ru>2016-02-24 18:24:22 +0100
committerVasilii Chernov <vchernov@inr.ru>2016-02-24 18:24:22 +0100
commitb0a034e6ef4a958235a56ebde0831c0f30a84d30 (patch)
treea1f46d2d536c692edd6b17efc61ac9fefef2796b /pcilib/value.c
parentda842568b94b0e00c1709ae01f441a7424c15b87 (diff)
parent3ea1907f3169e0233d3a32a7d470af3c34b6f967 (diff)
downloadpcitool-b0a034e6ef4a958235a56ebde0831c0f30a84d30.tar.gz
pcitool-b0a034e6ef4a958235a56ebde0831c0f30a84d30.tar.bz2
pcitool-b0a034e6ef4a958235a56ebde0831c0f30a84d30.tar.xz
pcitool-b0a034e6ef4a958235a56ebde0831c0f30a84d30.zip
Merge with Suren branch. Fix memory leaks.
Diffstat (limited to 'pcilib/value.c')
-rw-r--r--pcilib/value.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/pcilib/value.c b/pcilib/value.c
index 6e65307..e8268e9 100644
--- a/pcilib/value.c
+++ b/pcilib/value.c
@@ -1,3 +1,4 @@
+#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -71,6 +72,27 @@ int pcilib_set_value_from_static_string(pcilib_t *ctx, pcilib_value_t *value, co
return 0;
}
+int pcilib_set_value_from_string(pcilib_t *ctx, pcilib_value_t *value, const char *str) {
+ size_t len;
+
+ pcilib_clean_value(ctx, value);
+
+ len = strlen(str) + 1;
+ if (len < sizeof(value->str)) {
+ memcpy(value->str, str, len);
+ value->sval = value->str;
+ } else {
+ value->data = (void*)strdup(str);
+ if (!value->data) return PCILIB_ERROR_MEMORY;
+
+ value->size = strlen(str) + 1;
+ value->sval = value->data;
+ }
+ value->type = PCILIB_TYPE_STRING;
+
+ return 0;
+}
+
double pcilib_get_value_as_float(pcilib_t *ctx, const pcilib_value_t *val, int *ret) {
int err;
double res;