GLib.snprintf
Description: Reference for GLib.snprintf

### Function

# GLibsnprintf

#### Declaration [src]

    gint
    g_snprintf (
      gchar* string,
      gulong n,
      const gchar* format,
      ...
    )

#### Description [src]

A safer form of the standard `sprintf()` 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_printf()`.

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_snprintf()` conforms to the `snprintf()` function as standardized in ISO C99. Note that this is different from traditional `snprintf()`, which returns the length of the output string.

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

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.

`...`

  Type: ``

  The arguments to insert in the output.

#### Return value

Type: `gint`

The number of bytes which would be produced if the buffer was large enough.