7 FILE_LICENCE ( GPL2_OR_LATER
);
10 * Write a formatted string to newly allocated memory.
12 * @v strp Pointer to hold allocated string
13 * @v fmt Format string
14 * @v args Arguments corresponding to the format string
15 * @ret len Length of formatted string
17 int vasprintf ( char **strp
, const char *fmt
, va_list args
) {
21 /* Calculate length needed for string */
22 va_copy ( args_tmp
, args
);
23 len
= ( vsnprintf ( NULL
, 0, fmt
, args_tmp
) + 1 );
26 /* Allocate and fill string */
27 *strp
= malloc ( len
);
30 return vsnprintf ( *strp
, len
, fmt
, args
);
34 * Write a formatted string to newly allocated memory.
36 * @v strp Pointer to hold allocated string
37 * @v fmt Format string
38 * @v ... Arguments corresponding to the format string
39 * @ret len Length of formatted string
41 int asprintf ( char **strp
, const char *fmt
, ... ) {
45 va_start ( args
, fmt
);
46 len
= vasprintf ( strp
, fmt
, args
);