]> diplodocus.org Git - nmh/blob - sbr/concat.c
Bring these changes over from the branch.
[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 * This code is Copyright (c) 2002, by the authors of nmh. See the
9 * COPYRIGHT file in the root directory of the nmh distribution for
10 * complete copyright information.
11 */
12
13 #include <h/mh.h>
14
15
16 char *
17 concat (char *s1, ...)
18 {
19 char *cp, *dp, *sp;
20 size_t len;
21 va_list list;
22
23 len = strlen (s1) + 1;
24 va_start(list, s1);
25 while ((cp = va_arg(list, char *)))
26 len += strlen (cp);
27 va_end(list);
28
29 if (!(dp = sp = malloc(len)))
30 adios (NULL, "unable to allocate string storage");
31
32 sp = copy(s1, sp);
33
34 va_start(list, s1);
35 while ((cp = va_arg (list, char *)))
36 sp = copy(cp, sp);
37 va_end(list);
38
39 return dp;
40 }