Back to index

cell-binutils  2.17cvs20070401
Functions
snprintf.c File Reference
#include "ansidecl.h"
#include <stdarg.h>
#include <stddef.h>

Go to the source code of this file.

Functions

int vsnprintf (char *, size_t, const char *, va_list)
int snprintf (char *s, size_t n, const char *format,...)

Function Documentation

int snprintf ( char *  s,
size_t  n,
const char *  format,
  ... 
)

Definition at line 50 of file snprintf.c.

{
  int result;
  VA_OPEN (ap, format);
  VA_FIXEDARG (ap, char *, s);
  VA_FIXEDARG (ap, size_t, n);
  VA_FIXEDARG (ap, const char *, format);
  result = vsnprintf (s, n, format, ap);
  VA_CLOSE (ap);
  return result;
}

Here is the call graph for this function:

int vsnprintf ( char *  ,
size_t  ,
const char *  ,
va_list   
)

Definition at line 57 of file vsnprintf.c.

{
  char *buf = 0;
  int result = vasprintf (&buf, format, ap);

  if (!buf)
    return -1;
  if (result < 0)
    {
      free (buf);
      return -1;
    }

  result = strlen (buf);
  if (n > 0)
    {
      if ((long) n > result)
       memcpy (s, buf, result+1);
      else
        {
         memcpy (s, buf, n-1);
         s[n - 1] = 0;
       }
    }
  free (buf);
  return result;
}

Here is the call graph for this function: