diff options
| author | Federico Angelilli <code@fedang.net> | 2024-07-10 23:49:13 +0200 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-07-10 23:49:13 +0200 |
| commit | 26aaffc0e7293e4d4e48362159572e205c082068 (patch) | |
| tree | cbc55034ab2c6756ee633da1c171209c0535ea81 /src/util.c | |
| parent | 6f7c05c10766be1e331a5668ef534f5e85cecace (diff) | |
Finish config reader
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)); +} |
