From 338c3d50f45598418e0ed29fed542e76cf071e0f Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Wed, 19 Oct 2022 21:59:00 -0400 Subject: data: Fix deserialization turns out you need to pass pointers to functions that require pointers, who knew? --- src/util.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c index 328a9cc..1f86b03 100644 --- a/src/util.c +++ b/src/util.c @@ -36,3 +36,20 @@ char* trimwhitespace(char* str) { return str; } + +/* + * Remove given section from string. Negative len means remove + * everything up to the end. + * + * based on SO answer https://stackoverflow.com/a/20346241 + */ +int cut_str(char *str, int begin, int len) +{ + int l = strlen(str); + + if (len < 0) len = l - begin; + if (begin + len > l) len = l - begin; + memmove(str + begin, str + begin + len, l - len + 1); + + return len; +} -- cgit v1.2.3