aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 288fab6..b658769 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,4 +1,6 @@
#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
#include <stdio.h>
#include "util.h"
@@ -51,3 +53,22 @@ bool check_capsule(int px, int py, int x, int y, int w, int h)
|| check_rect(px, py, x + radius, y, w - 2 * radius, h);
}
+char *strslice(const char *string, size_t start, size_t end)
+{
+ if (string == NULL)
+ return NULL;
+
+ char *result = malloc(end - start + 1);
+ memcpy(result, string + start, end - start);
+ result[end - start] = '\0';
+
+ return result;
+}
+
+char *strcopy(const char *string)
+{
+ if (string == NULL)
+ return NULL;
+
+ return strslice(string, 0, strlen(string));
+}