diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/util.c | 20 | ||||
-rw-r--r-- | src/util/util.h | 2 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/util/util.c b/src/util/util.c index 4f79870..c113377 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -64,6 +64,26 @@ size_t kai_text_to_longs(long *dest, const char *str, size_t count) } +size_t kai_text_to_uints(unsigned int *dest, const char *str, size_t count) +{ + char *nptr = (char*) str; + char *end; + + size_t result = count; + + int i; + for (i=0; i<count; i++) { + dest[i] = strtol(nptr, &end, 10); + if (nptr == end) { + result -= 1; + } + nptr = end; + } + + return result; +} + + void *kai_alloc(size_t size, const char *purpose) { void *buf = malloc(size); diff --git a/src/util/util.h b/src/util/util.h index d5fa636..67d3922 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -34,6 +34,8 @@ size_t kai_text_to_reals(ka_real_t *dest, const char *str, size_t count); size_t kai_text_to_longs(long *dest, const char *str, size_t count); +size_t kai_text_to_uints(unsigned int *dest, const char *str, size_t count); + void *kai_alloc(size_t size, const char *purpose); |