aboutsummaryrefslogtreecommitdiff
path: root/xmalloc.h
diff options
context:
space:
mode:
authorCraig Barnes <craigbarnes@protonmail.com>2024-01-23 20:33:46 +0000
committerCraig Barnes <craigbarnes@protonmail.com>2024-01-23 22:04:41 +0000
commit6ed1c28d2c5209c0149ff222ec2f96369bab7308 (patch)
tree0f129c41106e4603ccfbc0a717b62cbc192fbd28 /xmalloc.h
parentslave: fix typo (diff)
terminal: simplify some string-related code in reload_fonts()
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;
+}