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