aboutsummaryrefslogtreecommitdiff
path: root/xmalloc.h
diff options
context:
space:
mode:
Diffstat (limited to 'xmalloc.h')
-rw-r--r--xmalloc.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/xmalloc.h b/xmalloc.h
index 8a3098b8..74282f8f 100644
--- a/xmalloc.h
+++ b/xmalloc.h
@@ -2,6 +2,7 @@
#include <stdarg.h>
#include <stddef.h>
+#include <string.h>
#include <wchar.h>
#include <uchar.h>
@@ -16,3 +17,14 @@ char *xstrndup(const char *str, size_t n) XSTRDUP;
char *xasprintf(const char *format, ...) PRINTF(1) XMALLOC;
char *xvasprintf(const char *format, va_list va) VPRINTF(1) XMALLOC;
char32_t *xc32dup(const char32_t *str) XSTRDUP;
+
+static inline char *
+xstrjoin(const char *s1, const char *s2)
+{
+ size_t n1 = strlen(s1);
+ size_t n2 = strlen(s2);
+ char *joined = xmalloc(n1 + n2 + 1);
+ memcpy(joined, s1, n1);
+ memcpy(joined + n1, s2, n2 + 1);
+ return joined;
+}