asprintf()

Write formatted output into an allocated string

Synopsis:

#include <stdio.h>

int asprintf( char **strp, 
              const char *format, 
              ... );

Arguments:

strp
A pointer to a location where the function can store a pointer to the allocated string.
format
A string that specifies the format of the output. The formatting string determines what additional arguments you need to provide. For more information, see printf().

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The asprintf() function formats data under control of the format control string. It's similar to sprintf(), except that asprintf() allocates a string for the formatted output. A null character is placed at the end of the generated character string. If asprintf() is successful, it sets *strp to point to the string.

You should call free() to free the string when you're finished with it.

Returns:

The number of characters written into the string, not counting the terminating null character, or a negative value if an error occurred (errno is set, and *strp is left unchanged). An error can occur while converting a value for output.

Classification:

Unix

Safety:  
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes