1 /* @(#)string.c 1.17 09/07/11 Copyright 1985, 1999-2009 J. Schilling */
2 #include <schily/mconfig.h>
3 #ifndef lint
4 static UConst char sccsid[] =
5 "@(#)string.c 1.17 09/07/11 Copyright 1985, 1999-2009 J. Schilling";
6 #endif
7 /*
8 * A program to produce a static calltree for C-functions
9 *
10 * string handling and allocation
11 *
12 * Copyright (c) 1985, 1999-2009 J. Schilling
13 */
14 /*
15 * The contents of this file are subject to the terms of the
16 * Common Development and Distribution License, Version 1.0 only
17 * (the "License"). You may not use this file except in compliance
18 * with the License.
19 *
20 * See the file CDDL.Schily.txt in this distribution for details.
21 * A copy of the CDDL is also available via the Internet at
22 * http://www.opensource.org/licenses/cddl1.txt
23 *
24 * When distributing Covered Code, include this CDDL HEADER in each
25 * file and include the License file CDDL.Schily.txt from this distribution.
26 */
27
28 #include <schily/stdio.h>
29 #include <schily/standard.h>
30 #include <schily/stdlib.h>
31 #include <schily/string.h>
32 #include <schily/varargs.h>
33 #include <schily/schily.h>
34 #include "strsubs.h"
35
36 EXPORT char *xmalloc __PR((unsigned int amt, char *txt));
37 EXPORT char *concat __PR((char *first, ...));
38
39 EXPORT char *
xmalloc(amt,txt)40 xmalloc(amt, txt)
41 unsigned int amt;
42 char *txt;
43 {
44 char *ret;
45
46 if ((ret = (char *) malloc(amt)) == 0)
47 comerr("Can't alloc %d bytes for %s.\n", amt, txt);
48 return (ret);
49 }
50
51 /* VARARGS1 */
52 #ifdef PROTOTYPES
53 EXPORT char *
concat(char * first,...)54 concat(char *first, ...)
55 #else
56 EXPORT char *
57 concat(first, va_alist)
58 char *first;
59 va_dcl
60 #endif
61 {
62 va_list args;
63 char *ret;
64 register int i;
65 register unsigned len;
66 register int nstr;
67 register char *p1;
68 register char *p2;
69
70 #ifdef PROTOTYPES
71 va_start(args, first);
72 #else
73 va_start(args);
74 #endif
75 p1 = first;
76 for (nstr = 0, len = 0; p1 != NULL; nstr++, p1 = va_arg(args, char *)) {
77 len += strlen(p1);
78 }
79 va_end(args);
80
81 p2 = ret = xmalloc(len + 1, "string concat");
82
83 #ifdef PROTOTYPES
84 va_start(args, first);
85 #else
86 va_start(args);
87 #endif
88 p1 = first;
89 for (i = 0; i < nstr; i++) {
90 for (; (*p2 = *p1++) != '\0'; p2++);
91 p1 = va_arg(args, char *);
92 }
93 *p2 = '\0';
94 va_end(args);
95 return (ret);
96 }
97