]> diplodocus.org Git - nmh/blob - sbr/concat.c
Just reworded the bit about '%s' being safe not to quote (it's only safe not to
[nmh] / sbr / concat.c
1
2 /*
3 * concat.c -- concatenate a variable number (minimum of 1)
4 * of strings in managed memory
5 *
6 * $Id$
7 */
8
9 #include <h/mh.h>
10
11
12 char *
13 concat (char *s1, ...)
14 {
15 char *cp, *dp, *sp;
16 size_t len;
17 va_list list;
18
19 len = strlen (s1) + 1;
20 va_start(list, s1);
21 while ((cp = va_arg(list, char *)))
22 len += strlen (cp);
23 va_end(list);
24
25 if (!(dp = sp = malloc(len)))
26 adios (NULL, "unable to allocate string storage");
27
28 sp = copy(s1, sp);
29
30 va_start(list, s1);
31 while ((cp = va_arg (list, char *)))
32 sp = copy(cp, sp);
33 va_end(list);
34
35 return dp;
36 }