MCPcopy Create free account
hub / github.com/apache/nuttx / my_asprintf

Function my_asprintf

tools/incdir.c:224–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222}
223
224static int my_asprintf(char **strp, const char *fmt, ...)
225{
226 va_list ap;
227 ssize_t bufsize;
228 char *buffer;
229
230 /* Get the size of the buffer */
231
232 va_start(ap, fmt);
233 bufsize = vsnprintf(NULL, 0, fmt, ap);
234 va_end(ap);
235
236 if (bufsize <= 0)
237 {
238 fprintf(stderr, "ERROR: vsnprintf() failed.\n");
239 exit (EXIT_FAILURE);
240 }
241
242 buffer = malloc(bufsize + 1);
243 if (buffer == NULL)
244 {
245 fprintf(stderr, "ERROR: Failed allocated vsnprintf() buffer.\n");
246 exit (EXIT_FAILURE);
247 }
248
249 va_start(ap, fmt);
250 vsnprintf(buffer, bufsize + 1, fmt, ap);
251 va_end(ap);
252
253 *strp = buffer;
254 return bufsize;
255}
256
257/****************************************************************************
258 * Public Functions

Callers 1

mainFunction · 0.85

Calls 4

fprintfFunction · 0.85
exitFunction · 0.85
vsnprintfFunction · 0.50
mallocFunction · 0.50

Tested by

no test coverage detected