diff options
author | Simon Tatham <anakin@pobox.com> | 2017-05-18 07:03:04 +0100 |
---|---|---|
committer | Simon Tatham <anakin@pobox.com> | 2017-05-18 07:10:17 +0100 |
commit | 48919caa7b9fb99ba8196098c0ca2e1b3dae5160 (patch) | |
tree | 585312e8c0182016e99d8bb35ba12e1c1115ab09 /dupstr.c | |
parent | 69d886c5757e405785ce811d8622f4ff189a9514 (diff) | |
download | wix-on-linux-48919caa7b9fb99ba8196098c0ca2e1b3dae5160.tar.gz wix-on-linux-48919caa7b9fb99ba8196098c0ca2e1b3dae5160.tar.bz2 wix-on-linux-48919caa7b9fb99ba8196098c0ca2e1b3dae5160.zip |
Move dupcat out into its own file, and add dupstr.
Also a handy #define to replace all those tedious castings of NULL.
Diffstat (limited to 'dupstr.c')
-rw-r--r-- | dupstr.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/dupstr.c b/dupstr.c new file mode 100644 index 0000000..d3a5f53 --- /dev/null +++ b/dupstr.c | |||
@@ -0,0 +1,35 @@ | |||
1 | #include <stdarg.h> | ||
2 | #include <string.h> | ||
3 | |||
4 | #include "memory.h" | ||
5 | #include "dupstr.h" | ||
6 | |||
7 | char *dupcat(const char *str, ...) | ||
8 | { | ||
9 | va_list ap; | ||
10 | const char *p; | ||
11 | char *out, *outp; | ||
12 | size_t len; | ||
13 | |||
14 | len = 1; | ||
15 | va_start(ap, str); | ||
16 | for (p = str; p; p = va_arg(ap, const char *)) | ||
17 | len += strlen(p); | ||
18 | va_end(ap); | ||
19 | |||
20 | out = snewn(len, char); | ||
21 | outp = out; | ||
22 | va_start(ap, str); | ||
23 | for (p = str; p; p = va_arg(ap, const char *)) { | ||
24 | strcpy(outp, p); | ||
25 | outp += strlen(p); | ||
26 | } | ||
27 | va_end(ap); | ||
28 | |||
29 | return out; | ||
30 | } | ||
31 | |||
32 | char *dupstr(const char *str) | ||
33 | { | ||
34 | return dupcat(str, (const char *)NULL); | ||
35 | } | ||