Back to index

glibc  2.9
vsnprintf.c File Reference
#include "libioP.h"
#include "strfile.h"

Go to the source code of this file.


static int _IO_strn_overflow (_IO_FILE *fp, int c) __THROW
int _IO_vsnprintf (char *string, _IO_size_t maxlen, const char *format, _IO_va_list args)

Function Documentation

static int _IO_strn_overflow ( _IO_FILE fp,
int  c 
) [static]

Definition at line 34 of file vsnprintf.c.

  /* When we come to here this means the user supplied buffer is
     filled.  But since we must return the number of characters which
     would have been written in total we must provide a buffer for
     further use.  We can do this by writing on and on in the overflow
     buffer in the _IO_strnfile structure.  */
  _IO_strnfile *snf = (_IO_strnfile *) fp;

  if (fp->_IO_buf_base != snf->overflow_buf)
      /* Terminate the string.  We know that there is room for at
        least one more character since we initialized the stream with
        a size to make this possible.  */
      *fp->_IO_write_ptr = '\0';

      INTUSE(_IO_setb) (fp, snf->overflow_buf,
                     snf->overflow_buf + sizeof (snf->overflow_buf), 0);

      fp->_IO_write_base = snf->overflow_buf;
      fp->_IO_read_base = snf->overflow_buf;
      fp->_IO_read_ptr = snf->overflow_buf;
      fp->_IO_read_end = snf->overflow_buf + sizeof (snf->overflow_buf);

  fp->_IO_write_ptr = snf->overflow_buf;
  fp->_IO_write_end = snf->overflow_buf;

  /* Since we are not really interested in storing the characters
     which do not fit in the buffer we simply ignore it.  */
  return c;

Here is the call graph for this function:

int _IO_vsnprintf ( char *  string,
_IO_size_t  maxlen,
const char *  format,
_IO_va_list  args 

Definition at line 96 of file vsnprintf.c.

  _IO_strnfile sf;
  int ret;
#ifdef _IO_MTSAFE_IO
  sf.f._sbf._f._lock = NULL;

  /* We need to handle the special case where MAXLEN is 0.  Use the
     overflow buffer right from the start.  */
  if (maxlen == 0)
      string = sf.overflow_buf;
      maxlen = sizeof (sf.overflow_buf);

  _IO_no_init (&sf.f._sbf._f, _IO_USER_LOCK, -1, NULL, NULL);
  _IO_JUMPS ((struct _IO_FILE_plus *) &sf.f._sbf) = &_IO_strn_jumps;
  string[0] = '\0';
  _IO_str_init_static_internal (&sf.f, string, maxlen - 1, string);
  ret = INTUSE(_IO_vfprintf) ((_IO_FILE *) &sf.f._sbf, format, args);

  if (sf.f._sbf._f._IO_buf_base != sf.overflow_buf)
    *sf.f._sbf._f._IO_write_ptr = '\0';
  return ret;

Here is the call graph for this function: