diff options
Diffstat (limited to 'src/util.c')
| -rw-r--r-- | src/util.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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)); +} |
