From 26aaffc0e7293e4d4e48362159572e205c082068 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Wed, 10 Jul 2024 23:49:13 +0200 Subject: Finish config reader --- src/util.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/util.c') 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 +#include +#include #include #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)); +} -- cgit v1.2.3