[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/libio/vswprintf.c

Version: -  FREEBSD  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  FREEBSD22  -  cheribsd  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1  -  FREEBSD-LIBC  -  FREEBSD8-LIBC  -  FREEBSD7-LIBC  -  FREEBSD6-LIBC  -  GLIBC27 
SearchContext: -  none  -  3  -  10 

    1 /* Copyright (C) 1994, 1997, 1999-2002, 2004, 2005, 2006
    2    Free Software Foundation, Inc.
    3    This file is part of the GNU C Library.
    4 
    5    The GNU C Library is free software; you can redistribute it and/or
    6    modify it under the terms of the GNU Lesser General Public
    7    License as published by the Free Software Foundation; either
    8    version 2.1 of the License, or (at your option) any later version.
    9 
   10    The GNU C Library is distributed in the hope that it will be useful,
   11    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13    Lesser General Public License for more details.
   14 
   15    You should have received a copy of the GNU Lesser General Public
   16    License along with the GNU C Library; if not, write to the Free
   17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   18    02111-1307 USA.
   19 
   20    As a special exception, if you link the code in this file with
   21    files compiled with a GNU compiler to produce an executable,
   22    that does not cause the resulting executable to be covered by
   23    the GNU Lesser General Public License.  This exception does not
   24    however invalidate any other reasons why the executable file
   25    might be covered by the GNU Lesser General Public License.
   26    This exception applies to code released by its copyright holders
   27    in files containing the exception.  */
   28 
   29 #include "libioP.h"
   30 #include "strfile.h"
   31 
   32 
   33 static wint_t _IO_wstrn_overflow (_IO_FILE *fp, wint_t c) __THROW;
   34 
   35 static wint_t
   36 _IO_wstrn_overflow (fp, c)
   37      _IO_FILE *fp;
   38      wint_t c;
   39 {
   40   /* When we come to here this means the user supplied buffer is
   41      filled.  But since we must return the number of characters which
   42      would have been written in total we must provide a buffer for
   43      further use.  We can do this by writing on and on in the overflow
   44      buffer in the _IO_wstrnfile structure.  */
   45   _IO_wstrnfile *snf = (_IO_wstrnfile *) fp;
   46 
   47   if (fp->_wide_data->_IO_buf_base != snf->overflow_buf)
   48     {
   49       INTUSE(_IO_wsetb) (fp, snf->overflow_buf,
   50                          snf->overflow_buf + (sizeof (snf->overflow_buf)
   51                                               / sizeof (wchar_t)), 0);
   52 
   53       fp->_wide_data->_IO_write_base = snf->overflow_buf;
   54       fp->_wide_data->_IO_read_base = snf->overflow_buf;
   55       fp->_wide_data->_IO_read_ptr = snf->overflow_buf;
   56       fp->_wide_data->_IO_read_end = (snf->overflow_buf
   57                                       + (sizeof (snf->overflow_buf)
   58                                          / sizeof (wchar_t)));
   59     }
   60 
   61   fp->_wide_data->_IO_write_ptr = snf->overflow_buf;
   62   fp->_wide_data->_IO_write_end = snf->overflow_buf;
   63 
   64   /* Since we are not really interested in storing the characters
   65      which do not fit in the buffer we simply ignore it.  */
   66   return c;
   67 }
   68 
   69 
   70 const struct _IO_jump_t _IO_wstrn_jumps attribute_hidden =
   71 {
   72   JUMP_INIT_DUMMY,
   73   JUMP_INIT(finish, _IO_wstr_finish),
   74   JUMP_INIT(overflow, (_IO_overflow_t) _IO_wstrn_overflow),
   75   JUMP_INIT(underflow, (_IO_underflow_t) _IO_wstr_underflow),
   76   JUMP_INIT(uflow, (_IO_underflow_t) INTUSE(_IO_wdefault_uflow)),
   77   JUMP_INIT(pbackfail, (_IO_pbackfail_t) _IO_wstr_pbackfail),
   78   JUMP_INIT(xsputn, INTUSE(_IO_wdefault_xsputn)),
   79   JUMP_INIT(xsgetn, INTUSE(_IO_wdefault_xsgetn)),
   80   JUMP_INIT(seekoff, _IO_wstr_seekoff),
   81   JUMP_INIT(seekpos, _IO_default_seekpos),
   82   JUMP_INIT(setbuf, _IO_default_setbuf),
   83   JUMP_INIT(sync, _IO_default_sync),
   84   JUMP_INIT(doallocate, INTUSE(_IO_wdefault_doallocate)),
   85   JUMP_INIT(read, _IO_default_read),
   86   JUMP_INIT(write, _IO_default_write),
   87   JUMP_INIT(seek, _IO_default_seek),
   88   JUMP_INIT(close, _IO_default_close),
   89   JUMP_INIT(stat, _IO_default_stat),
   90   JUMP_INIT(showmanyc, _IO_default_showmanyc),
   91   JUMP_INIT(imbue, _IO_default_imbue)
   92 };
   93 
   94 
   95 int
   96 _IO_vswprintf (string, maxlen, format, args)
   97      wchar_t *string;
   98      _IO_size_t maxlen;
   99      const wchar_t *format;
  100      _IO_va_list args;
  101 {
  102   _IO_wstrnfile sf;
  103   int ret;
  104   struct _IO_wide_data wd;
  105 #ifdef _IO_MTSAFE_IO
  106   sf.f._sbf._f._lock = NULL;
  107 #endif
  108 
  109   if (maxlen == 0)
  110     /* Since we have to write at least the terminating L'\0' a buffer
  111        length of zero always makes the function fail.  */
  112     return -1;
  113 
  114   _IO_no_init (&sf.f._sbf._f, _IO_USER_LOCK, 0, &wd, &_IO_wstrn_jumps);
  115   _IO_fwide (&sf.f._sbf._f, 1);
  116   string[0] = L'\0';
  117   _IO_wstr_init_static (&sf.f._sbf._f, string, maxlen - 1, string);
  118   ret = _IO_vfwprintf ((_IO_FILE *) &sf.f._sbf, format, args);
  119 
  120   if (sf.f._sbf._f._wide_data->_IO_buf_base == sf.overflow_buf)
  121     /* ISO C99 requires swprintf/vswprintf to return an error if the
  122        output does not fit in the provided buffer.  */
  123     return -1;
  124 
  125   /* Terminate the string.  */
  126   *sf.f._sbf._f._wide_data->_IO_write_ptr = '\0';
  127 
  128   return ret;
  129 }
  130 weak_alias (_IO_vswprintf, __vswprintf)
  131 ldbl_weak_alias (_IO_vswprintf, vswprintf)

Cache object: 0d3738a272e51586a58fb43e4a3acf9a


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.