No empty .Rs/.Re
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / concatenate.c
blobfc62fb92c6162c848b9ed26e04347c3e741789fa
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* concatenate 3
6 /* SUMMARY
7 /* concatenate strings
8 /* SYNOPSIS
9 /* #include <stringops.h>
11 /* char *concatenate(str, ...)
12 /* const char *str;
13 /* DESCRIPTION
14 /* The \fBconcatenate\fR routine concatenates a null-terminated
15 /* list of pointers to null-terminated character strings.
16 /* The result is dynamically allocated and should be passed to myfree()
17 /* when no longer needed.
18 /* LICENSE
19 /* .ad
20 /* .fi
21 /* The Secure Mailer license must be distributed with this software.
22 /* AUTHOR(S)
23 /* Wietse Venema
24 /* IBM T.J. Watson Research
25 /* P.O. Box 704
26 /* Yorktown Heights, NY 10598, USA
27 /*--*/
29 /* System library. */
31 #include <sys_defs.h>
32 #include <stdlib.h> /* 44BSD stdarg.h uses abort() */
33 #include <stdarg.h>
34 #include <string.h>
36 /* Utility library. */
38 #include "mymalloc.h"
39 #include "stringops.h"
41 /* concatenate - concatenate null-terminated list of strings */
43 char *concatenate(const char *arg0,...)
45 char *result;
46 va_list ap;
47 ssize_t len;
48 char *arg;
51 * Compute the length of the resulting string.
53 va_start(ap, arg0);
54 len = strlen(arg0);
55 while ((arg = va_arg(ap, char *)) != 0)
56 len += strlen(arg);
57 va_end(ap);
60 * Build the resulting string. Don't care about wasting a CPU cycle.
62 result = mymalloc(len + 1);
63 va_start(ap, arg0);
64 strcpy(result, arg0);
65 while ((arg = va_arg(ap, char *)) != 0)
66 strcat(result, arg);
67 va_end(ap);
68 return (result);