"Fossies" - the Fresh Open Source Software Archive 
Member "wrk-4.2.0/src/aprintf.c" (7 Feb 2021, 536 Bytes) of package /linux/www/wrk-4.2.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "aprintf.c" see the
Fossies "Dox" file reference documentation.
1 // Copyright (C) 2012 - Will Glozer. All rights reserved.
2
3 #include <stdarg.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7
8 char *aprintf(char **s, const char *fmt, ...) {
9 char *c = NULL;
10 int n, len;
11 va_list ap;
12
13 va_start(ap, fmt);
14 n = vsnprintf(NULL, 0, fmt, ap) + 1;
15 va_end(ap);
16
17 len = *s ? strlen(*s) : 0;
18
19 if ((*s = realloc(*s, (len + n) * sizeof(char)))) {
20 c = *s + len;
21 va_start(ap, fmt);
22 vsnprintf(c, n, fmt, ap);
23 va_end(ap);
24 }
25
26 return c;
27 }