### Function

# GLib vsnprintf

since: 2.0

#### Declaration

    gint
    g_vsnprintf (
      gchar* string,
      gulong n,
      const gchar* format,
      va_list args
    )

#### Description

A safer form of the standard `vsprintf()` function. The output is guaranteed to not exceed `n` characters (including the terminating nul character), so it is easy to ensure that a buffer overflow cannot occur.

See also `g_strdup_vprintf()`.

In versions of GLib prior to 1.2.3, this function may return -1 if the output was truncated, and the truncated string may not be nul-terminated. In versions prior to 1.3.12, this function returns the length of the output string.

The return value of `g_vsnprintf()` conforms to the `vsnprintf()` function as standardized in ISO C99. Note that this is different from traditional `vsnprintf()`, which returns the length of the output string.

The format string may contain positional parameters, as specified in the Single Unix Specification.

Available since: 2.0

This function is not directly available to language bindings.

#### Parameters

`string`

  Type: `gchar*`

  The buffer to hold the output.

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

`n`

  Type: `gulong`

  The maximum number of bytes to produce (including the terminating nul character)

`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 which would be produced if the buffer was large enough.