vasprintf

Writes formatted output to a string dynamically allocated with malloc and stores the address of the string.

Library:LibC
Classification:Linux
Service:File and Directory I/O

Syntax

  #include <stdarg.h> 
  #include <stdio.h> 
   
  int vasprintf (
     char        **string,
     const char   *format,
     va_list       arg );
  

Parameters

string

(OUT) Points to the address of the null-terminated string. You are responsible for freeing the memory allocated for this string.

format

(IN) Points to the format control string. See Print Format Control Strings.

arg

(IN) Specifies a variable argument list. The number of arguments is determined by the format string.

Return Values

If successful, returns the number of characters written. Otherwise, returns -1 and sets errno.

Decimal

Constant

Description

5

ENOMEM

Insufficient storage space is available.

Remarks

The vfprintf function writes output to the file pointed to by fp under control of the format parameter. The vfprintf function is equivalent to fprintf, with the variable arguments replaced with arg, which has been initialized by the va_start macro.

See Also