* sysdeps/unix/sysv/linux/m68k/sysdep.h (INLINE_SYSCALL): Don't
[glibc.git] / libio / vswprintf.c
blob25274926f6556d2fc83c26cd777d2f7bb4b6d505
1 /* Copyright (C) 1994, 1997, 1999, 2000 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA.
19 As a special exception, if you link the code in this file with
20 files compiled with a GNU compiler to produce an executable,
21 that does not cause the resulting executable to be covered by
22 the GNU Lesser General Public License. This exception does not
23 however invalidate any other reasons why the executable file
24 might be covered by the GNU Lesser General Public License.
25 This exception applies to code released by its copyright holders
26 in files containing the exception. */
28 #include "libioP.h"
29 #include "strfile.h"
32 typedef struct
34 _IO_strfile f;
35 /* This is used for the characters which do not fit in the buffer
36 provided by the user. */
37 wchar_t overflow_buf[64];
38 } _IO_strnfile;
41 static wint_t _IO_wstrn_overflow __P ((_IO_FILE *fp, wint_t c));
43 static wint_t
44 _IO_wstrn_overflow (fp, c)
45 _IO_FILE *fp;
46 wint_t c;
48 /* When we come to here this means the user supplied buffer is
49 filled. But since we must return the number of characters which
50 would have been written in total we must provide a buffer for
51 further use. We can do this by writing on and on in the overflow
52 buffer in the _IO_strnfile structure. */
53 _IO_strnfile *snf = (_IO_strnfile *) fp;
55 if (fp->_wide_data->_IO_buf_base != snf->overflow_buf)
57 /* Terminate the string. We know that there is room for at
58 least one more character since we initialized the stream with
59 a size to make this possible. */
60 *fp->_wide_data->_IO_write_ptr = '\0';
62 _IO_wsetb (fp, snf->overflow_buf,
63 snf->overflow_buf + (sizeof (snf->overflow_buf)
64 / sizeof (wchar_t)), 0);
66 fp->_wide_data->_IO_write_base = snf->overflow_buf;
67 fp->_wide_data->_IO_read_base = snf->overflow_buf;
68 fp->_wide_data->_IO_read_ptr = snf->overflow_buf;
69 fp->_wide_data->_IO_read_end = (snf->overflow_buf
70 + (sizeof (snf->overflow_buf)
71 / sizeof (wchar_t)));
74 fp->_wide_data->_IO_write_ptr = snf->overflow_buf;
75 fp->_wide_data->_IO_write_end = snf->overflow_buf;
77 /* Since we are not really interested in storing the characters
78 which do not fit in the buffer we simply ignore it. */
79 return c;
83 static struct _IO_jump_t _IO_wstrn_jumps =
85 JUMP_INIT_DUMMY,
86 JUMP_INIT(finish, _IO_wstr_finish),
87 JUMP_INIT(overflow, (_IO_overflow_t) _IO_wstrn_overflow),
88 JUMP_INIT(underflow, (_IO_underflow_t) _IO_wstr_underflow),
89 JUMP_INIT(uflow, (_IO_underflow_t) _IO_wdefault_uflow),
90 JUMP_INIT(pbackfail, (_IO_pbackfail_t) _IO_wstr_pbackfail),
91 JUMP_INIT(xsputn, _IO_wdefault_xsputn),
92 JUMP_INIT(xsgetn, _IO_wdefault_xsgetn),
93 JUMP_INIT(seekoff, _IO_wstr_seekoff),
94 JUMP_INIT(seekpos, _IO_default_seekpos),
95 JUMP_INIT(setbuf, (_IO_setbuf_t) _IO_wdefault_setbuf),
96 JUMP_INIT(sync, _IO_default_sync),
97 JUMP_INIT(doallocate, _IO_wdefault_doallocate),
98 JUMP_INIT(read, _IO_default_read),
99 JUMP_INIT(write, _IO_default_write),
100 JUMP_INIT(seek, _IO_default_seek),
101 JUMP_INIT(close, _IO_default_close),
102 JUMP_INIT(stat, _IO_default_stat),
103 JUMP_INIT(showmanyc, _IO_default_showmanyc),
104 JUMP_INIT(imbue, _IO_default_imbue)
109 _IO_vswprintf (string, maxlen, format, args)
110 wchar_t *string;
111 _IO_size_t maxlen;
112 const wchar_t *format;
113 _IO_va_list args;
115 _IO_strnfile sf;
116 int ret;
117 struct _IO_wide_data wd;
118 #ifdef _IO_MTSAFE_IO
119 _IO_lock_t lock;
120 sf.f._sbf._f._lock = &lock;
121 #endif
123 /* We need to handle the special case where MAXLEN is 0. Use the
124 overflow buffer right from the start. */
125 if (maxlen == 0)
127 string = sf.overflow_buf;
128 maxlen = sizeof (sf.overflow_buf) / sizeof (wchar_t);
131 _IO_no_init (&sf.f._sbf._f, 0, 0, &wd, &_IO_wstrn_jumps);
132 _IO_fwide (&sf.f._sbf._f, 1);
133 string[0] = L'\0';
134 _IO_wstr_init_static (&sf.f._sbf._f, string, maxlen - 1, string);
135 ret = _IO_vfwprintf ((_IO_FILE *) &sf.f._sbf, format, args);
137 if (sf.f._sbf._f._wide_data->_IO_buf_base != sf.overflow_buf)
138 *sf.f._sbf._f._wide_data->_IO_write_ptr = '\0';
139 return ret;
142 #ifdef weak_alias
143 weak_alias (_IO_vswprintf, __vswprintf)
144 weak_alias (_IO_vswprintf, vswprintf)
145 #endif