aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-07-10 23:49:13 +0200
committerFederico Angelilli <code@fedang.net>2024-07-10 23:49:13 +0200
commit26aaffc0e7293e4d4e48362159572e205c082068 (patch)
treecbc55034ab2c6756ee633da1c171209c0535ea81 /src/util.c
parent6f7c05c10766be1e331a5668ef534f5e85cecace (diff)
Finish config reader
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));
+}