Back to index

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

Go to the source code of this file.


static wint_t _IO_wstrn_overflow (_IO_FILE *fp, wint_t c) __THROW
int _IO_vswprintf (wchar_t *string, _IO_size_t maxlen, const wchar_t *format, _IO_va_list args)

Function Documentation

int _IO_vswprintf ( wchar_t *  string,
_IO_size_t  maxlen,
const wchar_t *  format,
_IO_va_list  args 

Definition at line 96 of file vswprintf.c.

  _IO_wstrnfile sf;
  int ret;
  struct _IO_wide_data wd;
#ifdef _IO_MTSAFE_IO
  sf.f._sbf._f._lock = NULL;

  if (maxlen == 0)
    /* Since we have to write at least the terminating L'\0' a buffer
       length of zero always makes the function fail.  */
    return -1;

  _IO_no_init (&sf.f._sbf._f, _IO_USER_LOCK, 0, &wd, &_IO_wstrn_jumps);
  _IO_fwide (&sf.f._sbf._f, 1);
  string[0] = L'\0';
  _IO_wstr_init_static (&sf.f._sbf._f, string, maxlen - 1, string);
  ret = _IO_vfwprintf ((_IO_FILE *) &sf.f._sbf, format, args);

  if (sf.f._sbf._f._wide_data->_IO_buf_base == sf.overflow_buf)
    /* ISO C99 requires swprintf/vswprintf to return an error if the
       output does not fit in the provided buffer.  */
    return -1;

  /* Terminate the string.  */
  *sf.f._sbf._f._wide_data->_IO_write_ptr = '\0';

  return ret;

Here is the call graph for this function:

Here is the caller graph for this function:

static wint_t _IO_wstrn_overflow ( _IO_FILE fp,
wint_t  c 
) [static]

Definition at line 36 of file vswprintf.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_wstrnfile structure.  */
  _IO_wstrnfile *snf = (_IO_wstrnfile *) fp;

  if (fp->_wide_data->_IO_buf_base != snf->overflow_buf)
      INTUSE(_IO_wsetb) (fp, snf->overflow_buf,
                      snf->overflow_buf + (sizeof (snf->overflow_buf)
                                         / sizeof (wchar_t)), 0);

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

  fp->_wide_data->_IO_write_ptr = snf->overflow_buf;
  fp->_wide_data->_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: