diff options
| author | Craig Barnes <craigbarnes@protonmail.com> | 2024-01-23 20:33:46 +0000 |
|---|---|---|
| committer | Craig Barnes <craigbarnes@protonmail.com> | 2024-01-23 22:04:41 +0000 |
| commit | 6ed1c28d2c5209c0149ff222ec2f96369bab7308 (patch) | |
| tree | 0f129c41106e4603ccfbc0a717b62cbc192fbd28 /xmalloc.h | |
| parent | slave: fix typo (diff) | |
terminal: simplify some string-related code in reload_fonts()
Diffstat (limited to 'xmalloc.h')
| -rw-r--r-- | xmalloc.h | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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; +} |
