aboutsummaryrefslogtreecommitdiff
path: root/xmalloc.h
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2024-08-14 09:59:23 +0000
committerDaniel Eklöf <daniel@ekloef.se>2024-08-14 09:59:23 +0000
commit54c1660a1e6834aaba9b86a5cca6d22eebc28a41 (patch)
treeba877ef70c20aa78b633af3c9fefff099d7bc2f1 /xmalloc.h
parentmeson: bump version to 1.18.0 (diff)
parentosc: regression: fix OSC-111 handling of alpha changes (diff)
Merge branch 'master' into releases/1.18
Diffstat (limited to 'xmalloc.h')
-rw-r--r--xmalloc.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/xmalloc.h b/xmalloc.h
index 76db7e1b..8a2c208f 100644
--- a/xmalloc.h
+++ b/xmalloc.h
@@ -25,16 +25,25 @@ xmemdup(const void *ptr, size_t size)
}
static inline char *
-xstrjoin(const char *s1, const char *s2, char delim)
+xstrjoin(const char *s1, const char *s2)
{
size_t n1 = strlen(s1);
- size_t n2 = delim > 0 ? 1 : 0;
- size_t n3 = strlen(s2);
+ size_t n2 = strlen(s2);
+ char *joined = xmalloc(n1 + n2 + 1);
+ memcpy(joined, s1, n1);
+ memcpy(joined + n1, s2, n2 + 1);
+ return joined;
+}
+static inline char *
+xstrjoin3(const char *s1, const char *s2, const char *s3)
+{
+ size_t n1 = strlen(s1);
+ size_t n2 = strlen(s2);
+ size_t n3 = strlen(s3);
char *joined = xmalloc(n1 + n2 + n3 + 1);
memcpy(joined, s1, n1);
- if (delim > 0)
- joined[n1] = delim;
- memcpy(joined + n1 + n2, s2, n3 + 1);
+ memcpy(joined + n1, s2, n2);
+ memcpy(joined + n1 + n2, s3, n3 + 1);
return joined;
}