### Function

# GLib vasprintf

since: 2.4

#### Declaration [src]

    gint
    g_vasprintf (
      gchar** string,
      const gchar* format,
      va_list args
    )

#### Description [src]

An implementation of the GNU `vasprintf()` function which supports positional parameters, as specified in the Single Unix Specification. This function is similar to `g_vsprintf()`, except that it allocates a string to hold the output, instead of putting the output in a buffer you allocate in advance.

The returned value in `string` is guaranteed to be non-`NULL`, unless `format` contains `%lc` or `%ls` conversions, which can fail if no multibyte representation is available for the given character.

`glib/gprintf.h` must be explicitly included in order to use this function.

Available since: 2.4

This function is not directly available to language bindings.

#### Parameters

`string`

  Type: `gchar**`

  The return location for the newly-allocated string, which will be `NULL` if (and only if) this function fails.

  The argument will be set by the function.
  The caller of the function takes ownership of the returned data, and is responsible for freeing it.
  The value is a NUL terminated UTF-8 string.

`format`

  Type: `const gchar*`

  A standard `printf()` format string, but notice string precision pitfalls.

  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`args`

  Type: `va_list`

  The list of arguments to insert in the output.

#### Return value

Type: `gint`

The number of bytes printed, or -1 on failure.