MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vasprintf

Function vasprintf

freebsd/libkern/asprintf.c:36–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34#include <machine/stdarg.h>
35
36int
37vasprintf(char **buf, struct malloc_type *mtp, const char *format, va_list va)
38{
39 int len, ret;
40 va_list tmp_va;
41 char dummy;
42
43 va_copy(tmp_va, va);
44 len = vsnprintf(&dummy, 0, format, tmp_va);
45 va_end(tmp_va);
46 if (len < 0) {
47 *buf = NULL;
48 return (len);
49 }
50
51 /* Account for null terminator. */
52 len += 1;
53 *buf = malloc(len, mtp, M_NOWAIT);
54 if (*buf == NULL)
55 return (-1);
56
57 ret = vsnprintf(*buf, len, format, va);
58 if (ret < 0) {
59 free(*buf, mtp);
60 *buf = NULL;
61 }
62
63 return (ret);
64}
65
66int
67asprintf(char **buf, struct malloc_type *mtp, const char *format, ...)

Callers 6

NgSendAsciiMsgFunction · 0.85
kmem_vasprintfFunction · 0.85
kmem_asprintfFunction · 0.85
zfs_asprintfFunction · 0.85
asprintfFunction · 0.85
metadata_printfFunction · 0.85

Calls 3

vsnprintfFunction · 0.85
mallocFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected