Subversion Repositories Kolibri OS

Rev

Rev 5191 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5191 Rev 6324
Line 1... Line 1...
1
/* Concatenate variable number of strings.
1
/* Concatenate variable number of strings.
2
   Copyright (C) 1991, 1994, 2001, 2011 Free Software Foundation, Inc.
2
   Copyright (C) 1991, 1994, 2001, 2011, 2013 Free Software Foundation, Inc.
3
   Written by Fred Fish @ Cygnus Support
3
   Written by Fred Fish @ Cygnus Support
Line 4... Line 4...
4
 
4
 
5
This file is part of the libiberty library.
5
This file is part of the libiberty library.
6
Libiberty is free software; you can redistribute it and/or
6
Libiberty is free software; you can redistribute it and/or
Line 23... Line 23...
23
 
23
 
24
@deftypefn Extension char* concat (const char *@var{s1}, const char *@var{s2}, @
24
@deftypefn Extension char* concat (const char *@var{s1}, const char *@var{s2}, @
Line 25... Line 25...
25
  @dots{}, @code{NULL})
25
  @dots{}, @code{NULL})
26
 
-
 
27
Concatenate zero or more of strings and return the result in freshly
26
 
28
@code{xmalloc}ed memory.  Returns @code{NULL} if insufficient memory is
27
Concatenate zero or more of strings and return the result in freshly
Line 29... Line 28...
29
available.  The argument list is terminated by the first @code{NULL}
28
@code{xmalloc}ed memory.  The argument list is terminated by the first
Line 30... Line -...
30
pointer encountered.  Pointers to empty strings are ignored.
-
 
31
 
-
 
32
@end deftypefn
-
 
33
 
-
 
34
NOTES
-
 
35
 
-
 
36
	This function uses xmalloc() which is expected to be a front end
-
 
37
	function to malloc() that deals with low memory situations.  In
-
 
38
	typical use, if malloc() returns NULL then xmalloc() diverts to an
-
 
39
	error handler routine which never returns, and thus xmalloc will
-
 
40
	never return a NULL pointer.  If the client application wishes to
-
 
41
	deal with low memory situations itself, it should supply an xmalloc
29
@code{NULL} pointer encountered.  Pointers to empty strings are ignored.
Line 42... Line 30...
42
	that just directly invokes malloc and blindly returns whatever
30
 
43
	malloc returns.
31
@end deftypefn
Line 100... Line 88...
100
 
88
 
101
unsigned long
89
unsigned long
102
concat_length (const char *first, ...)
90
concat_length (const char *first, ...)
103
{
91
{
-
 
92
  unsigned long length;
Line 104... Line 93...
104
  unsigned long length;
93
  va_list args;
105
 
-
 
106
  VA_OPEN (args, first);
94
 
107
  VA_FIXEDARG (args, const char *, first);
95
  va_start (args, first);
Line 108... Line 96...
108
  length = vconcat_length (first, args);
96
  length = vconcat_length (first, args);
109
  VA_CLOSE (args);
97
  va_end (args);
Line 110... Line 98...
110
 
98
 
Line 111... Line 99...
111
  return length;
99
  return length;
112
}
100
}
113
 
101
 
114
/* @undocumented concat_copy */
102
/* @undocumented concat_copy */
-
 
103
 
Line 115... Line 104...
115
 
104
char *
116
char *
-
 
117
concat_copy (char *dst, const char *first, ...)
-
 
118
{
105
concat_copy (char *dst, const char *first, ...)
119
  char *save_dst;
106
{
120
 
107
  char *save_dst;
Line 121... Line 108...
121
  VA_OPEN (args, first);
108
  va_list args;
122
  VA_FIXEDARG (args, char *, dst);
109
 
Line 123... Line 110...
123
  VA_FIXEDARG (args, const char *, first);
110
  va_start (args, first);
Line 139... Line 126...
139
/* @undocumented concat_copy2 */
126
/* @undocumented concat_copy2 */
Line 140... Line 127...
140
 
127
 
141
char *
128
char *
142
concat_copy2 (const char *first, ...)
129
concat_copy2 (const char *first, ...)
143
{
130
{
144
  VA_OPEN (args, first);
131
  va_list args;
145
  VA_FIXEDARG (args, const char *, first);
132
  va_start (args, first);
146
  vconcat_copy (libiberty_concat_ptr, first, args);
133
  vconcat_copy (libiberty_concat_ptr, first, args);
Line 147... Line 134...
147
  VA_CLOSE (args);
134
  va_end (args);
148
 
135
 
Line 149... Line 136...
149
  return libiberty_concat_ptr;
136
  return libiberty_concat_ptr;
150
}
137
}
151
 
138
 
152
char *
139
char *
-
 
140
concat (const char *first, ...)
Line 153... Line 141...
153
concat (const char *first, ...)
141
{
154
{
142
  char *newstr;
155
  char *newstr;
-
 
156
 
143
  va_list args;
157
  /* First compute the size of the result and get sufficient memory.  */
144
 
Line 158... Line 145...
158
  VA_OPEN (args, first);
145
  /* First compute the size of the result and get sufficient memory.  */
159
  VA_FIXEDARG (args, const char *, first);
146
  va_start (args, first);
160
  newstr = XNEWVEC (char, vconcat_length (first, args) + 1);
-
 
161
  VA_CLOSE (args);
147
  newstr = XNEWVEC (char, vconcat_length (first, args) + 1);
162
 
148
  va_end (args);
Line 163... Line 149...
163
  /* Now copy the individual pieces to the result string. */
149
 
164
  VA_OPEN (args, first);
150
  /* Now copy the individual pieces to the result string. */
Line 165... Line 151...
165
  VA_FIXEDARG (args, const char *, first);
151
  va_start (args, first);
Line 189... Line 175...
189
 
175
 
190
char *
176
char *
191
reconcat (char *optr, const char *first, ...)
177
reconcat (char *optr, const char *first, ...)
192
{
178
{
-
 
179
  char *newstr;
Line 193... Line 180...
193
  char *newstr;
180
  va_list args;
194
 
181
 
195
  /* First compute the size of the result and get sufficient memory.  */
-
 
196
  VA_OPEN (args, first);
-
 
197
  VA_FIXEDARG (args, char *, optr);
182
  /* First compute the size of the result and get sufficient memory.  */
198
  VA_FIXEDARG (args, const char *, first);
183
  va_start (args, first);
Line 199... Line 184...
199
  newstr = XNEWVEC (char, vconcat_length (first, args) + 1);
184
  newstr = XNEWVEC (char, vconcat_length (first, args) + 1);
200
  VA_CLOSE (args);
185
  va_end (args);
201
 
-
 
202
  /* Now copy the individual pieces to the result string. */
-
 
203
  VA_OPEN (args, first);
186
 
204
  VA_FIXEDARG (args, char *, optr);
187
  /* Now copy the individual pieces to the result string. */
205
  VA_FIXEDARG (args, const char *, first);
188
  va_start (args, first);
206
  vconcat_copy (newstr, first, args);
189
  vconcat_copy (newstr, first, args);
Line 207... Line 190...
207
  if (optr) /* Done before VA_CLOSE so optr stays in scope for K&R C.  */
190
  if (optr) /* Done before VA_CLOSE so optr stays in scope for K&R C.  */
208
    free (optr);
191
    free (optr);
Line 209... Line 192...
209
  VA_CLOSE (args);
192
  va_end (args);