Upgrade libgit2
[TortoiseGit.git] / src / TortoisePlink / utils / dupcat.c
blob555e73faf8c245aaa6c956574e83f535077c622e
1 /*
2 * Implementation function behind dupcat() in misc.h.
4 * This function is called with an arbitrary number of 'const char *'
5 * parameters, of which the last one is a null pointer. The wrapper
6 * macro puts on the null pointer itself, so normally callers don't
7 * have to.
8 */
10 #include <string.h>
11 #include <stdarg.h>
13 #include "defs.h"
14 #include "misc.h"
16 char *dupcat_fn(const char *s1, ...)
18 int len;
19 char *p, *q, *sn;
20 va_list ap;
22 len = strlen(s1);
23 va_start(ap, s1);
24 while (1) {
25 sn = va_arg(ap, char *);
26 if (!sn)
27 break;
28 len += strlen(sn);
30 va_end(ap);
32 p = snewn(len + 1, char);
33 strcpy(p, s1);
34 q = p + strlen(p);
36 va_start(ap, s1);
37 while (1) {
38 sn = va_arg(ap, char *);
39 if (!sn)
40 break;
41 strcpy(q, sn);
42 q += strlen(q);
44 va_end(ap);
46 return p;