64
66
} /* End ink_strncpy */
68
/*---------------------------------------------------------------------------*
70
char *ink_strncat(char *dest, char *src, int n)
72
This routine is a safer version of strncat which always NUL terminates
73
the destination string. Note that this routine has the SAME semantics
74
as strncat, such as concatinating exactly n bytes, padding dest with NULs
75
is necessary. Use ink_string_copy for a non-padding version.
77
*---------------------------------------------------------------------------*/
80
ink_strncat(char *dest, const char *src, int n)
82
if (likely(src && dest)) {
84
strncat(dest, src, (n - 1));
90
} /* End ink_strncat */
67
92
/*---------------------------------------------------------------------------*
190
215
/*---------------------------------------------------------------------------*
192
char *ink_string_duplicate(char *ptr)
194
This routine allocates memory for the string <ptr>, and copies the string
195
into the new buffer. The pointer to the new buffer is returned.
197
*---------------------------------------------------------------------------*/
200
ink_string_duplicate(char *ptr)
205
const size_t nSize = strlen(ptr) + 1;
206
n = (char *) ink_malloc(nSize);
207
ink_strncpy(n, ptr, nSize);
210
} /* End ink_string_duplicate */
213
/*---------------------------------------------------------------------------*
215
217
char *ink_string_find_dotted_extension(char *str, char *ext, int max_ext_len)
217
219
This routine takes a string <str>, copies the period-separated extension to
243
245
} /* End ink_string_find_dotted_extension */
245
/*---------------------------------------------------------------------------*
247
char *ink_string_mpath(int nstrings, char *str1, bool free1,
248
char *str2, bool free2, ...);
250
This routine joins multiple path components together to make
251
a new path. Each component can optionally start with a / in which
252
case all the preceeding components are ignored.
254
Each component can optionally be free()d.
256
Space is malloc()d to hold the resulting path.
258
*---------------------------------------------------------------------------*/
261
ink_string_mpath(int nstrings, ...)
265
char *e[INK_MAX_STRING_ARRAY_SIZE];
266
bool f[INK_MAX_STRING_ARRAY_SIZE];
267
size_t s[INK_MAX_STRING_ARRAY_SIZE];
274
if (likely(nstrings < INK_MAX_STRING_ARRAY_SIZE)) {
275
va_start(ap, nstrings);
277
for (i = 0; i < nstrings; i++) {
278
e[i] = va_arg(ap, char *);
279
f[i] = va_arg(ap, int);
282
for (i = nstrings - 1; i >= 0; i--) {
287
if (e[i][0] == '/') {
292
if ((slash == nstrings - 1) && f[slash]) {
293
for (i = 0; i < nstrings - 1; i++) {
300
const size_t nsSize = ts + 1;
301
p = (ns = (char *) xmalloc(nsSize));
303
for (i = slash; i < nstrings - 1; i++) {
304
ink_strncpy(p, e[i], (nsSize - (p - ns)));
308
ink_strncpy(p, e[nstrings - 1], (nsSize - (p - ns)));
310
for (i = 0; i < nstrings; i++) {
319
/*---------------------------------------------------------------------------*
321
char *ink_string_mcopy(char *source);
323
This simply makes a copy of a string into freshly malloc()ed space.
325
*---------------------------------------------------------------------------*/
328
ink_string_mcopy(char *source)
332
if (likely(source)) {
333
const size_t nSize = strlen(source) + 1;
334
n = (char *) xmalloc(nSize);
335
ink_strncpy(n, source, nSize);
340
/*---------------------------------------------------------------------------*
342
char *ink_string_mjoin(int nstrings, char *str1, bool free1,
343
char *str2, bool free2, ...);
345
This routine joins multiple strings components together to make
346
a new string. Each component can optionally be free()d.
348
Space is malloc()d to hold the resulting path.
350
*---------------------------------------------------------------------------*/
353
ink_string_mjoin(int nstrings, ...)
357
char *e[INK_MAX_STRING_ARRAY_SIZE];
358
bool f[INK_MAX_STRING_ARRAY_SIZE];
360
size_t s[INK_MAX_STRING_ARRAY_SIZE];
367
if (likely(nstrings < INK_MAX_STRING_ARRAY_SIZE)) {
368
va_start(ap, nstrings);
370
for (i = 0; i < nstrings; i++) {
371
e[i] = va_arg(ap, char *);
372
f[i] = va_arg(ap, int);
378
const size_t nsSize = ts + 1;
379
p = (ns = (char *) xmalloc(nsSize));
380
for (i = slash; i < nstrings - 1; i++) {
381
ink_strncpy(p, e[i], (nsSize - (p - ns)));
384
ink_strncpy(p, e[nstrings - 1], (nsSize - (p - ns)));
385
for (i = 0; i < nstrings; i++) {
396
ink_strndup(const char *str, size_t n)
401
size_t len = strlen(str);
402
cstr = (char *)xmalloc(len + 1);
405
memcpy(cstr, str, len);
412
248
#if !TS_HAS_STRLCPY