summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-18 16:37:51 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-18 16:37:51 -0500
commita3adbe5ea6015a76a3df84ee5942b89fbb762947 (patch)
tree712d0fdfaf23818ebf2b361306dbb9d4452e6540 /util.c
parent37102a766e1913cd0548a981e5c601852ae47963 (diff)
opening files kinda working
Diffstat (limited to 'util.c')
-rw-r--r--util.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/util.c b/util.c
index 5bde9b6..1d6bb79 100644
--- a/util.c
+++ b/util.c
@@ -46,6 +46,15 @@ static bool streq(char const *a, char const *b) {
return strcmp(a, b) == 0;
}
+// duplicates a null-terminated string. the returned string should be passed to free()
+static char *str_dup(char const *src) {
+ size_t len = strlen(src);
+ char *ret = malloc(len + 1);
+ if (ret)
+ memcpy(ret, src, len + 1);
+ return ret;
+}
+
// like snprintf, but not screwed up on windows
#define str_printf(str, size, ...) (str)[(size) - 1] = '\0', snprintf((str), (size) - 1, __VA_ARGS__)
// like snprintf, but the size is taken to be the length of the array str.