summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. 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)
commit67b9820cde00b67d9268bf51f45231eef30ebefe (patch)
treee6b5b4e3674013521cd38780d64e67d0e96352da /src
parent371eed87471036c4ac4e5cf030869bdade8a7107 (diff)
downloadmazefight-67b9820cde00b67d9268bf51f45231eef30ebefe.zip
mazefight-67b9820cde00b67d9268bf51f45231eef30ebefe.tar.gz
mazefight-67b9820cde00b67d9268bf51f45231eef30ebefe.tar.bz2
util: Add strdup function
Diffstat (limited to 'src')
-rw-r--r--src/util.c19
-rw-r--r--src/util.h3
2 files changed, 22 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 5e8effc..624b9f0 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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;
diff --git a/src/util.h b/src/util.h
index 47688e9..42b6475 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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_ */