8 * Write a formatted string to newly allocated memory.
10 * @v strp Pointer to hold allocated string
11 * @v fmt Format string
12 * @v args Arguments corresponding to the format string
13 * @ret len Length of formatted string
15 int vasprintf ( char **strp
, const char *fmt
, va_list args
) {
19 /* Calculate length needed for string */
20 va_copy ( args_tmp
, args
);
21 len
= ( vsnprintf ( NULL
, 0, fmt
, args_tmp
) + 1 );
24 /* Allocate and fill string */
25 *strp
= malloc ( len
);
28 return vsnprintf ( *strp
, len
, fmt
, args
);
32 * Write a formatted string to newly allocated memory.
34 * @v strp Pointer to hold allocated string
35 * @v fmt Format string
36 * @v ... Arguments corresponding to the format string
37 * @ret len Length of formatted string
39 int asprintf ( char **strp
, const char *fmt
, ... ) {
43 va_start ( args
, fmt
);
44 len
= vasprintf ( strp
, fmt
, args
);