Function

GLibvsnprintf

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.

Parameters

string gchar*
 

The buffer to hold the output.

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

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

format const gchar*
 

A standard printf() format string, but notice [string precision pitfalls][string-precision]

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

The list of arguments to insert in the output.

Return value

Returns: int
 

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