MCPcopy Index your code
hub / github.com/GJDuck/e9patch / vasprintf

Function vasprintf

examples/stdlib.c:4112–4130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4110}
4111
4112static int vasprintf(char **strp, const char *format, va_list ap)
4113{
4114 *strp = NULL;
4115 va_list aq;
4116 va_copy(aq, ap);
4117 int result = vsnprintf(NULL, SIZE_MAX, format, ap);
4118 if (result >= 0)
4119 {
4120 char *buf = (char *)malloc(result+1);
4121 result = (buf == NULL? -1: result);
4122 if (result >= 0)
4123 result = vsnprintf(buf, result+1, format, aq);
4124 else
4125 free(buf);
4126 *strp = (result >= 0? buf: NULL);
4127 }
4128 va_end(aq);
4129 return result;
4130}
4131
4132static int snprintf(char *str, size_t len, const char *format, ...)
4133{

Callers 1

asprintfFunction · 0.85

Calls 3

mallocFunction · 0.85
freeFunction · 0.85
vsnprintfFunction · 0.70

Tested by

no test coverage detected