mhl and mhbuild ignore to long lines
[mmh] / sbr / concat.c
1 /*
2 ** concat.c -- concatenate a variable number (minimum of 1)
3 **             of strings in managed memory
4 **
5 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
6 ** COPYRIGHT file in the root directory of the nmh distribution for
7 ** complete copyright information.
8 */
9
10 #include <h/mh.h>
11 #include <h/utils.h>
12 #include <stdarg.h>
13
14
15 static char *
16 copy(char *from, char *to)
17 {
18         while ((*to = *from)) {
19                 to++;
20                 from++;
21         }
22         return (to);
23 }
24
25
26 char *
27 concat(char *s1, ...)
28 {
29         char *cp, *dp, *sp;
30         size_t len;
31         va_list list;
32
33         len = strlen(s1) + 1;
34         va_start(list, s1);
35         while ((cp = va_arg(list, char *)))
36                 len += strlen(cp);
37         va_end(list);
38
39         dp = sp = mh_xcalloc(len, sizeof(char));
40
41         sp = copy(s1, sp);
42
43         va_start(list, s1);
44         while ((cp = va_arg(list, char *)))
45                 sp = copy(cp, sp);
46         va_end(list);
47
48         return dp;
49 }