diff options
Diffstat (limited to 'pcilib/value.c')
-rw-r--r-- | pcilib/value.c | 22 |
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; |