summaryrefslogtreecommitdiffstats
path: root/pcilib/value.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2016-02-23 07:20:33 +0100
committerSuren A. Chilingaryan <csa@suren.me>2016-02-23 07:20:33 +0100
commita962c90543955bac98308c1b0d909048070d900a (patch)
tree70b06851187e6bf8cfd8ee28931bdea25ea92ac7 /pcilib/value.c
parent055279e09c3db9429e02874ec9620b9af357c80a (diff)
parent52eb7f4fb76ddf99dedf44332aae7af4df76ab36 (diff)
downloadpcitool-a962c90543955bac98308c1b0d909048070d900a.tar.gz
pcitool-a962c90543955bac98308c1b0d909048070d900a.tar.bz2
pcitool-a962c90543955bac98308c1b0d909048070d900a.tar.xz
pcitool-a962c90543955bac98308c1b0d909048070d900a.zip
Merge Python scripting support from Vasiliy Chernov
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;