diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-18 16:37:51 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-18 16:37:51 -0500 |
commit | a3adbe5ea6015a76a3df84ee5942b89fbb762947 (patch) | |
tree | 712d0fdfaf23818ebf2b361306dbb9d4452e6540 /util.c | |
parent | 37102a766e1913cd0548a981e5c601852ae47963 (diff) |
opening files kinda working
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -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. |