diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | include/util.h | 6 | ||||
-rw-r--r-- | src/util.c | 16 |
3 files changed, 23 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 397f273..e9bc4d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ set(SRC src/list.c src/main.c src/template.c + src/util.c ) add_executable(msg ${SRC}) diff --git a/include/util.h b/include/util.h new file mode 100644 index 0000000..58c1f58 --- /dev/null +++ b/include/util.h @@ -0,0 +1,6 @@ +#ifndef __UTIL_H +#define __UTIL_H + +void xstrcat(char *s1, char *s2); + +#endif diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..4863e29 --- /dev/null +++ b/src/util.c @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <util.h> + +void +xstrcat(char *s1, char *s2) +{ + size_t a = strlen(s1); + size_t b = strlen(s2); + size_t size_ab = a + b + 1; + + s1 = realloc(s1, size_ab); + + memcpy(s1 + a, s2, b + 1); +} |