5 /* Concatenate two strings into newly allocated buffer.
6 * You must free() them, when you don't need it anymore.
7 * Any of the arguments can be NULL meaning empty string.
8 * In case of error returns NULL.
9 * Empty string is always returned as allocated empty string. */
10 _hidden
char *astrcat(const char *first
, const char *second
) {
11 size_t first_len
, second_len
;
14 first_len
= (first
) ? strlen(first
) : 0;
15 second_len
= (second
) ? strlen(second
) : 0;
16 buf
= malloc(1 + first_len
+ second_len
);
19 if (first
) strcpy(buf
, first
);
20 if (second
) strcpy(buf
+ first_len
, second
);
26 /* Concatenate three strings into newly allocated buffer.
27 * You must free() them, when you don't need it anymore.
28 * Any of the arguments can be NULL meaning empty string.
29 * In case of error returns NULL.
30 * Empty string is always returned as allocated empty string. */
31 _hidden
char *astrcat3(const char *first
, const char *second
,
33 size_t first_len
, second_len
, third_len
;
36 first_len
= (first
) ? strlen(first
) : 0;
37 second_len
= (second
) ? strlen(second
) : 0;
38 third_len
= (third
) ? strlen(third
) : 0;
39 buf
= malloc(1 + first_len
+ second_len
+ third_len
);