aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c17
1 files changed, 17 insertions, 0 deletions
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;
+}