1 #include <sys/types.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <stdarg.h> 5 #include "Strn.h" 6 7 /*VARARGS*/ 8 char * 9 Dynscat(char **dst, ...) 10 { 11 va_list ap; 12 const char *src; 13 char *newdst, *dcp; 14 size_t curLen, catLen, srcLen; 15 16 if (dst == (char **) 0) 17 return NULL; 18 19 catLen = 0; 20 va_start(ap, dst); 21 src = va_arg(ap, char *); 22 while (src != NULL) { 23 catLen += strlen(src); 24 src = va_arg(ap, char *); 25 } 26 va_end(ap); 27 28 if ((*dst == NULL) || (**dst == '\0')) 29 curLen = 0; 30 else 31 curLen = strlen(*dst); 32 33 if (*dst == NULL) 34 newdst = malloc(curLen + catLen + 2); 35 else 36 newdst = realloc(*dst, curLen + catLen + 2); 37 if (newdst == NULL) 38 return NULL; 39 40 dcp = newdst + curLen; 41 va_start(ap, dst); 42 src = va_arg(ap, char *); 43 while (src != NULL) { 44 srcLen = strlen(src); 45 memcpy(dcp, src, srcLen); 46 dcp += srcLen; 47 src = va_arg(ap, char *); 48 } 49 va_end(ap); 50 *dcp = '\0'; 51 52 *dst = newdst; 53 return (newdst); 54 } /* Dynscat */ 55