Mercurial
comparison third_party/wrk/src/aprintf.c @ 178:94705b5986b3
[ThirdParty] Added WRK and luajit for load testing.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Thu, 22 Jan 2026 20:10:30 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 177:24fe8ff94056 | 178:94705b5986b3 |
|---|---|
| 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 } |