diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-08-05 19:23:03 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-08-05 20:06:23 (EDT) |
commit | 67b9820cde00b67d9268bf51f45231eef30ebefe (patch) | |
tree | e6b5b4e3674013521cd38780d64e67d0e96352da | |
parent | 371eed87471036c4ac4e5cf030869bdade8a7107 (diff) | |
download | mazefight-67b9820cde00b67d9268bf51f45231eef30ebefe.zip mazefight-67b9820cde00b67d9268bf51f45231eef30ebefe.tar.gz mazefight-67b9820cde00b67d9268bf51f45231eef30ebefe.tar.bz2 |
util: Add strdup function
-rw-r--r-- | src/util.c | 19 | ||||
-rw-r--r-- | src/util.h | 3 |
2 files changed, 22 insertions, 0 deletions
@@ -22,6 +22,25 @@ #include "util.h" char * +mf_strdup(const char *src) +{ + size_t len; + char *dst; + + len = strlen(src); + + dst = malloc(len + 1 * sizeof(*dst)); + if (dst == NULL) { + return NULL; + } + + memcpy(dst, src, len); + dst[len] = '\0'; + + return dst; +} + +char * mf_strcat(const char *str1, const char *str2) { size_t str1_len; @@ -21,6 +21,9 @@ #define MF_UTIL_H_ char * +mf_strdup(const char *src); + +char * mf_strcat(const char *str1, const char *str2); #endif /* MF_UTIL_H_ */ |