~ubuntu-branches/ubuntu/hoary/postfix/hoary-security

« back to all changes in this revision

Viewing changes to src/util/concatenate.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-10-06 11:50:33 UTC
  • Revision ID: james.westby@ubuntu.com-20041006115033-ooo6yfg6kmoteu04
Tags: upstream-2.1.3
ImportĀ upstreamĀ versionĀ 2.1.3

Show diffs side-by-side

added added

removed removed

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