soap(): use xmlNewChild() instead of xmlNewNode() and xmlAddChild()
[libisds.git] / src / utils.c
blob2a55e8c5608b41ae6ae1dab3c7996c2334c30550
1 #include <string.h>
2 #include <stdlib.h>
3 #include "utils.h"
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;
12 char *buf;
14 first_len = (first) ? strlen(first) : 0;
15 second_len = (second) ? strlen(second) : 0;
16 buf = malloc(1 + first_len + second_len);
17 if (buf) {
18 buf[0] = '\0';
19 if (first) strcpy(buf, first);
20 if (second) strcpy(buf + first_len, second);
22 return buf;
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,
32 const char *third) {
33 size_t first_len, second_len, third_len;
34 char *buf, *next;
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);
40 if (buf) {
41 buf[0] = '\0';
42 next = buf;
43 if (first) {
44 strcpy(next, first);
45 next += first_len;
47 if (second) {
48 strcpy(next, second);
49 next += second_len;
51 if (third) {
52 strcpy(next, third);
55 return buf;