Back to index

nagios-plugins  1.4.16
Functions
vsnprintf.c File Reference
#include <stdio.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "vasnprintf.h"

Go to the source code of this file.

Functions

int vsnprintf (char *str, size_t size, const char *format, va_list args)

Function Documentation

int vsnprintf ( char *  str,
size_t  size,
const char *  format,
va_list  args 
)

Definition at line 40 of file vsnprintf.c.

{
  char *output;
  size_t len;
  size_t lenbuf = size;

  output = vasnprintf (str, &lenbuf, format, args);
  len = lenbuf;

  if (!output)
    return -1;

  if (output != str)
    {
      if (size)
        {
          size_t pruned_len = (len < size ? len : size - 1);
          memcpy (str, output, pruned_len);
          str[pruned_len] = '\0';
        }

      free (output);
    }

  if (len > INT_MAX)
    {
      errno = EOVERFLOW;
      return -1;
    }

  return len;
}

Here is the call graph for this function: