libcfe  0.12.1
some useful C-functions
ascatprintf.c
Go to the documentation of this file.
1 #include "config.h"
2 #include "ascatprintf.h"
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <stdarg.h>
7 #include <string.h>
8 
9 size_t ascatprintf(char **string, size_t len, char *template, ...)
10 {
11  char *part = NULL;
12  va_list ap;
13  va_start(ap, template);
14  size_t part_len = vasprintf(&part, template, ap);
15  va_end(ap);
16  if(*string == NULL)
17  {
18  *string = part;
19  len = part_len;
20  }
21  else
22  {
23  *string = (char *)realloc(*string, (len += part_len) + 1);
24  strcat(*string, part);
25  free(part);
26  part = NULL;
27  }
28  return len;
29 }
size_t ascatprintf(char **string, size_t len, char *template,...)
Definition: ascatprintf.c:9