Go to the documentation of this file.00001
00007
00008
00009
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <string.h>
00013 #include <stdarg.h>
00014
00015 #include "utility.h"
00016 #include "xnprintf.h"
00017
00031 char *dstring_sprintf(const char *fmt, ...) {
00032 char *buf;
00033 int status;
00034 va_list ap;
00035
00036 va_start (ap, fmt);
00037 status = vasprintf (&buf, fmt, ap);
00038 va_end (ap);
00039
00040 return(buf);
00041 }
00042
00043 #define DO_FREE 1
00044 #define DO_NOT_FREE 0
00045
00058 char *dstring_append_common(char *s1, char* s2, int do_free)
00059 {
00060 if ((s1 = realloc(s1, strlen(s1)+strlen(s2)+1)) == NULL)
00061 return NULL;
00062 s1 = strcat(s1,s2);
00063 if (do_free && s2!=NULL) free(s2);
00064 return(s1);
00065 }
00066
00076 char *dstring_append(char *s1, char *s2)
00077 {
00078 return(dstring_append_common(s1,s2,DO_NOT_FREE));
00079 }
00080
00090 char *dstring_append_free(char *s1, char* s2)
00091 {
00092 return(dstring_append_common(s1,s2,DO_FREE));
00093 }