Update.
[glibc.git] / libio / wfileops.c
blob52368abb601a13b7d0b9aedd82480962837664df
1 /* Copyright (C) 1993, 95, 97, 98, 99, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU IO Library.
3 Written by Ulrich Drepper <drepper@cygnus.com>.
4 Based on the single byte version by Per Bothner <bothner@cygnus.com>.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2, or (at
9 your option) any later version.
11 This library is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this library; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 MA 02111-1307, USA.
21 As a special exception, if you link this library with files
22 compiled with a GNU compiler to produce an executable, this does
23 not cause the resulting executable to be covered by the GNU General
24 Public License. This exception does not however invalidate any
25 other reasons why the executable file might be covered by the GNU
26 General Public License. */
28 #include <assert.h>
29 #include <libioP.h>
30 #include <wchar.h>
31 #include <gconv.h>
32 #include <stdlib.h>
33 #include <string.h>
36 _IO_FILE *
37 _IO_wfile_setbuf (fp, p, len)
38 _IO_FILE *fp;
39 wchar_t *p;
40 _IO_ssize_t len;
42 if (_IO_wdefault_setbuf (fp, p, len) == NULL)
43 return NULL;
45 fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_write_ptr =
46 fp->_wide_data->_IO_write_end = fp->_wide_data->_IO_buf_base;
47 _IO_wsetg (fp, fp->_wide_data->_IO_buf_base, fp->_wide_data->_IO_buf_base,
48 fp->_wide_data->_IO_buf_base);
50 return fp;
54 /* Convert TO_DO wide character from DATA to FP.
55 Then mark FP as having empty buffers. */
56 int
57 _IO_wdo_write (fp, data, to_do)
58 _IO_FILE *fp;
59 const wchar_t *data;
60 _IO_size_t to_do;
62 struct _IO_codecvt *cc = &fp->_wide_data->_codecvt;
64 if (to_do > 0)
66 if (fp->_IO_write_end == fp->_IO_write_ptr
67 && fp->_IO_write_end != fp->_IO_write_base)
69 if (_IO_new_do_write (fp, fp->_IO_write_base,
70 fp->_IO_write_ptr - fp->_IO_write_base) == EOF)
71 return EOF;
76 enum __codecvt_result result;
77 const wchar_t *new_data;
79 /* Now convert from the internal format into the external buffer. */
80 result = (*cc->__codecvt_do_out) (cc, &fp->_wide_data->_IO_state,
81 data, data + to_do, &new_data,
82 fp->_IO_write_ptr,
83 fp->_IO_buf_end,
84 &fp->_IO_write_ptr);
86 /* Write out what we produced so far. */
87 if (_IO_new_do_write (fp, fp->_IO_write_base,
88 fp->_IO_write_ptr - fp->_IO_write_base) == EOF)
89 /* Something went wrong. */
90 return EOF;
92 to_do -= new_data - data;
94 /* Next see whether we had problems during the conversion. If yes,
95 we cannot go on. */
96 if (result != __codecvt_ok
97 && (result != __codecvt_partial || new_data - data == 0))
98 break;
100 data = new_data;
102 while (to_do > 0);
105 _IO_wsetg (fp, fp->_wide_data->_IO_buf_base, fp->_wide_data->_IO_buf_base,
106 fp->_wide_data->_IO_buf_base);
107 fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_write_ptr
108 = fp->_wide_data->_IO_buf_base;
109 fp->_wide_data->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
110 ? fp->_wide_data->_IO_buf_base
111 : fp->_wide_data->_IO_buf_end);
113 return to_do == 0 ? 0 : WEOF;
117 wint_t
118 _IO_wfile_underflow (fp)
119 _IO_FILE *fp;
121 struct _IO_codecvt *cd;
122 enum __codecvt_result status;
123 _IO_ssize_t count;
124 int tries;
125 const char *read_ptr_copy;
127 if (fp->_flags & _IO_NO_READS)
129 fp->_flags |= _IO_ERR_SEEN;
130 __set_errno (EBADF);
131 return WEOF;
133 if (fp->_wide_data->_IO_read_ptr < fp->_wide_data->_IO_read_end)
134 return *fp->_wide_data->_IO_read_ptr;
136 cd = &fp->_wide_data->_codecvt;
138 /* Maybe there is something left in the external buffer. */
139 if (fp->_IO_read_ptr < fp->_IO_read_end)
141 /* Convert it. */
142 size_t avail_bytes = fp->_IO_read_end - fp->_IO_read_ptr;
144 if (avail_bytes >= (*cd->__codecvt_do_max_length) (cd))
146 /* There is more in the external. */
147 const char *read_stop = (const char *) fp->_IO_read_ptr;
149 fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
150 status = (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
151 fp->_IO_read_ptr, fp->_IO_read_end,
152 &read_stop,
153 fp->_wide_data->_IO_read_end,
154 fp->_wide_data->_IO_buf_end,
155 &fp->_wide_data->_IO_read_end);
157 fp->_IO_read_ptr = (char *) read_stop;
159 /* If we managed to generate some text return the next character. */
160 if (fp->_wide_data->_IO_read_ptr < fp->_wide_data->_IO_read_end)
161 return *fp->_wide_data->_IO_read_ptr;
163 if (status == __codecvt_error)
165 __set_errno (EILSEQ);
166 fp->_flags |= _IO_ERR_SEEN;
167 return WEOF;
171 /* Move the remaining content of the read buffer to the beginning. */
172 memmove (fp->_IO_buf_base, fp->_IO_read_ptr,
173 fp->_IO_read_end - fp->_IO_read_ptr);
174 fp->_IO_read_end = (fp->_IO_buf_base
175 + (fp->_IO_read_end - fp->_IO_read_ptr));
176 fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base;
178 else
179 fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_read_end =
180 fp->_IO_buf_base;
182 fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end =
183 fp->_IO_buf_base;
185 if (fp->_IO_buf_base == NULL)
187 /* Maybe we already have a push back pointer. */
188 if (fp->_IO_save_base != NULL)
190 free (fp->_IO_save_base);
191 fp->_flags &= ~_IO_IN_BACKUP;
193 _IO_doallocbuf (fp);
196 if (fp->_wide_data->_IO_buf_base == NULL)
198 /* Maybe we already have a push back pointer. */
199 if (fp->_wide_data->_IO_save_base != NULL)
201 free (fp->_wide_data->_IO_save_base);
202 fp->_flags &= ~_IO_IN_BACKUP;
204 _IO_wdoallocbuf (fp);
207 /* Flush all line buffered files before reading. */
208 /* FIXME This can/should be moved to genops ?? */
209 if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))
210 _IO_flush_all_linebuffered ();
212 _IO_switch_to_get_mode (fp);
214 fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base;
215 fp->_IO_read_end = fp->_IO_buf_base;
216 fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
217 = fp->_IO_buf_base;
219 fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_read_ptr =
220 fp->_wide_data->_IO_buf_base;
221 fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_buf_base;
222 fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_write_ptr =
223 fp->_wide_data->_IO_write_end = fp->_wide_data->_IO_buf_base;
225 tries = 0;
226 again:
227 count = _IO_SYSREAD (fp, fp->_IO_read_end,
228 fp->_IO_buf_end - fp->_IO_read_end);
229 if (count <= 0)
231 if (count == 0 && tries == 0)
232 fp->_flags |= _IO_EOF_SEEN;
233 else
234 fp->_flags |= _IO_ERR_SEEN, count = 0;
236 fp->_IO_read_end += count;
237 if (count == 0)
239 if (tries != 0)
240 /* There are some bytes in the external buffer but they don't
241 convert to anything. */
242 __set_errno (EILSEQ);
243 return WEOF;
245 if (fp->_offset != _IO_pos_BAD)
246 _IO_pos_adjust (fp->_offset, count);
248 /* Now convert the read input. */
249 fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
250 fp->_IO_read_base = fp->_IO_read_ptr;
251 status = (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
252 fp->_IO_read_ptr, fp->_IO_read_end,
253 &read_ptr_copy,
254 fp->_wide_data->_IO_read_end,
255 fp->_wide_data->_IO_buf_end,
256 &fp->_wide_data->_IO_read_end);
258 fp->_IO_read_ptr = (char *) read_ptr_copy;
259 if (fp->_wide_data->_IO_read_end == fp->_wide_data->_IO_buf_base)
261 if (status == __codecvt_error || fp->_IO_read_end == fp->_IO_buf_end)
263 __set_errno (EILSEQ);
264 fp->_flags |= _IO_ERR_SEEN;
265 return WEOF;
268 /* The read bytes make no complete character. Try reading again. */
269 assert (status == __codecvt_partial);
270 ++tries;
271 goto again;
274 return *fp->_wide_data->_IO_read_ptr;
278 wint_t
279 _IO_wfile_overflow (f, wch)
280 _IO_FILE *f;
281 wint_t wch;
283 if (f->_flags & _IO_NO_WRITES) /* SET ERROR */
285 f->_flags |= _IO_ERR_SEEN;
286 __set_errno (EBADF);
287 return WEOF;
289 /* If currently reading or no buffer allocated. */
290 if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0)
292 /* Allocate a buffer if needed. */
293 if (f->_wide_data->_IO_write_base == 0)
295 _IO_wdoallocbuf (f);
296 _IO_wsetg (f, f->_wide_data->_IO_buf_base,
297 f->_wide_data->_IO_buf_base, f->_wide_data->_IO_buf_base);
299 if (f->_IO_write_base == NULL)
301 _IO_doallocbuf (f);
302 _IO_setg (f, f->_IO_buf_base, f->_IO_buf_base, f->_IO_buf_base);
305 else
307 /* Otherwise must be currently reading. If _IO_read_ptr
308 (and hence also _IO_read_end) is at the buffer end,
309 logically slide the buffer forwards one block (by setting
310 the read pointers to all point at the beginning of the
311 block). This makes room for subsequent output.
312 Otherwise, set the read pointers to _IO_read_end (leaving
313 that alone, so it can continue to correspond to the
314 external position). */
315 if (f->_wide_data->_IO_read_ptr == f->_wide_data->_IO_buf_end)
317 f->_IO_read_end = f->_IO_read_ptr = f->_IO_buf_base;
318 f->_wide_data->_IO_read_end = f->_wide_data->_IO_read_ptr =
319 f->_wide_data->_IO_buf_base;
322 f->_wide_data->_IO_write_ptr = f->_wide_data->_IO_read_ptr;
323 f->_wide_data->_IO_write_base = f->_wide_data->_IO_write_ptr;
324 f->_wide_data->_IO_write_end = f->_wide_data->_IO_buf_end;
325 f->_wide_data->_IO_read_base = f->_wide_data->_IO_read_ptr =
326 f->_wide_data->_IO_read_end;
328 f->_IO_write_ptr = f->_IO_read_ptr;
329 f->_IO_write_base = f->_IO_write_ptr;
330 f->_IO_write_end = f->_IO_buf_end;
331 f->_IO_read_base = f->_IO_read_ptr = f->_IO_read_end;
333 f->_flags |= _IO_CURRENTLY_PUTTING;
334 if (f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
335 f->_wide_data->_IO_write_end = f->_wide_data->_IO_write_ptr;
337 if (wch == WEOF)
338 return _IO_do_flush (f);
339 if (f->_wide_data->_IO_write_ptr == f->_wide_data->_IO_buf_end)
340 /* Buffer is really full */
341 if (_IO_do_flush (f) == WEOF)
342 return WEOF;
343 *f->_wide_data->_IO_write_ptr++ = wch;
344 if ((f->_flags & _IO_UNBUFFERED)
345 || ((f->_flags & _IO_LINE_BUF) && wch == L'\n'))
346 if (_IO_do_flush (f) == WEOF)
347 return WEOF;
348 return wch;
351 wint_t
352 _IO_wfile_sync (fp)
353 _IO_FILE *fp;
355 _IO_ssize_t delta;
356 wint_t retval = 0;
358 /* char* ptr = cur_ptr(); */
359 if (fp->_wide_data->_IO_write_ptr > fp->_wide_data->_IO_write_base)
360 if (_IO_do_flush (fp))
361 return WEOF;
362 delta = fp->_wide_data->_IO_read_ptr - fp->_wide_data->_IO_read_end;
363 if (delta != 0)
365 /* We have to find out how many bytes we have to go back in the
366 external buffer. */
367 struct _IO_codecvt *cv = &fp->_wide_data->_codecvt;
368 _IO_off64_t new_pos;
370 int clen = (*cv->__codecvt_do_encoding) (cv);
372 if (clen > 0)
373 /* It is easy, a fixed number of input bytes are used for each
374 wide character. */
375 delta *= clen;
376 else
378 /* We have to find out the hard way how much to back off.
379 To do this we determine how much input we needed to
380 generate the wide characters up to the current reading
381 position. */
382 int nread;
384 fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state;
385 nread = (*cv->__codecvt_do_length) (cv, &fp->_wide_data->_IO_state,
386 fp->_IO_read_base,
387 fp->_IO_read_end, delta);
388 fp->_IO_read_ptr = fp->_IO_read_base + nread;
389 delta = -(fp->_IO_read_end - fp->_IO_read_base - nread);
392 new_pos = _IO_SYSSEEK (fp, delta, 1);
393 if (new_pos != (_IO_off64_t) EOF)
395 fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_read_ptr;
396 fp->_IO_read_end = fp->_IO_read_ptr;
398 #ifdef ESPIPE
399 else if (errno == ESPIPE)
400 ; /* Ignore error from unseekable devices. */
401 #endif
402 else
403 retval = WEOF;
405 if (retval != WEOF)
406 fp->_offset = _IO_pos_BAD;
407 /* FIXME: Cleanup - can this be shared? */
408 /* setg(base(), ptr, ptr); */
409 return retval;
412 _IO_off64_t
413 _IO_wfile_seekoff (fp, offset, dir, mode)
414 _IO_FILE *fp;
415 _IO_off64_t offset;
416 int dir;
417 int mode;
419 _IO_off64_t result;
420 _IO_off64_t delta, new_offset;
421 long int count;
422 /* POSIX.1 8.2.3.7 says that after a call the fflush() the file
423 offset of the underlying file must be exact. */
424 int must_be_exact = ((fp->_wide_data->_IO_read_base
425 == fp->_wide_data->_IO_read_end)
426 && (fp->_wide_data->_IO_write_base
427 == fp->_wide_data->_IO_write_ptr));
429 if (mode == 0)
430 dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */
432 /* Flush unwritten characters.
433 (This may do an unneeded write if we seek within the buffer.
434 But to be able to switch to reading, we would need to set
435 egptr to ptr. That can't be done in the current design,
436 which assumes file_ptr() is eGptr. Anyway, since we probably
437 end up flushing when we close(), it doesn't make much difference.)
438 FIXME: simulate mem-papped files. */
440 if (fp->_wide_data->_IO_write_ptr > fp->_wide_data->_IO_write_base
441 || _IO_in_put_mode (fp))
442 if (_IO_switch_to_wget_mode (fp))
443 return WEOF;
445 if (fp->_wide_data->_IO_buf_base == NULL)
447 /* It could be that we already have a pushback buffer. */
448 if (fp->_wide_data->_IO_read_base != NULL)
450 free (fp->_wide_data->_IO_read_base);
451 fp->_flags &= ~_IO_IN_BACKUP;
453 _IO_doallocbuf (fp);
454 _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
455 _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
456 _IO_wsetp (fp, fp->_wide_data->_IO_buf_base,
457 fp->_wide_data->_IO_buf_base);
458 _IO_wsetg (fp, fp->_wide_data->_IO_buf_base,
459 fp->_wide_data->_IO_buf_base, fp->_wide_data->_IO_buf_base);
462 switch (dir)
464 struct _IO_codecvt *cv;
465 int clen;
467 case _IO_seek_cur:
468 /* Adjust for read-ahead (bytes is buffer). To do this we must
469 find out which position in the external buffer corresponds to
470 the current position in the internal buffer. */
471 cv = &fp->_wide_data->_codecvt;
472 clen = (*cv->__codecvt_do_encoding) (cv);
474 if (clen > 0)
475 offset -= (fp->_wide_data->_IO_read_end
476 - fp->_wide_data->_IO_read_ptr) * clen;
477 else
479 int nread;
481 delta = fp->_wide_data->_IO_read_ptr - fp->_wide_data->_IO_read_end;
482 fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state;
483 nread = (*cv->__codecvt_do_length) (cv, &fp->_wide_data->_IO_state,
484 fp->_IO_read_base,
485 fp->_IO_read_end, delta);
486 fp->_IO_read_ptr = fp->_IO_read_base + nread;
487 offset -= fp->_IO_read_end - fp->_IO_read_base - nread;
490 if (fp->_offset == _IO_pos_BAD)
491 goto dumb;
492 /* Make offset absolute, assuming current pointer is file_ptr(). */
493 offset += fp->_offset;
495 dir = _IO_seek_set;
496 break;
497 case _IO_seek_set:
498 break;
499 case _IO_seek_end:
501 struct _G_stat64 st;
502 if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode))
504 offset += st.st_size;
505 dir = _IO_seek_set;
507 else
508 goto dumb;
511 /* At this point, dir==_IO_seek_set. */
513 /* If we are only interested in the current position we've found it now. */
514 if (mode == 0)
515 return offset;
517 /* If destination is within current buffer, optimize: */
518 if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
519 && !_IO_in_backup (fp))
521 /* Offset relative to start of main get area. */
522 _IO_off64_t rel_offset = (offset - fp->_offset
523 + (fp->_IO_read_end - fp->_IO_read_base));
524 if (rel_offset >= 0)
526 #if 0
527 if (_IO_in_backup (fp))
528 _IO_switch_to_main_get_area (fp);
529 #endif
530 if (rel_offset <= fp->_IO_read_end - fp->_IO_read_base)
532 fp->_IO_read_ptr = fp->_IO_read_base + rel_offset;
533 _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
535 /* Now set the pointer for the internal buffer. This
536 might be an iterative process. Though the read
537 pointer is somewhere in the current external buffer
538 this does not mean we can convert this whole buffer
539 at once fitting in the internal buffer. */
544 while (0);
546 _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
547 goto resync;
549 #ifdef TODO
550 /* If we have streammarkers, seek forward by reading ahead. */
551 if (_IO_have_markers (fp))
553 int to_skip = rel_offset
554 - (fp->_IO_read_ptr - fp->_IO_read_base);
555 if (ignore (to_skip) != to_skip)
556 goto dumb;
557 _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
558 goto resync;
560 #endif
562 #ifdef TODO
563 if (rel_offset < 0 && rel_offset >= Bbase () - Bptr ())
565 if (!_IO_in_backup (fp))
566 _IO_switch_to_backup_area (fp);
567 gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
568 _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
569 goto resync;
571 #endif
574 #ifdef TODO
575 _IO_unsave_markers (fp);
576 #endif
578 if (fp->_flags & _IO_NO_READS)
579 goto dumb;
581 /* Try to seek to a block boundary, to improve kernel page management. */
582 new_offset = offset & ~(fp->_IO_buf_end - fp->_IO_buf_base - 1);
583 delta = offset - new_offset;
584 if (delta > fp->_IO_buf_end - fp->_IO_buf_base)
586 new_offset = offset;
587 delta = 0;
589 result = _IO_SYSSEEK (fp, new_offset, 0);
590 if (result < 0)
591 return EOF;
592 if (delta == 0)
593 count = 0;
594 else
596 count = _IO_SYSREAD (fp, fp->_IO_buf_base,
597 (must_be_exact
598 ? delta : fp->_IO_buf_end - fp->_IO_buf_base));
599 if (count < delta)
601 /* We weren't allowed to read, but try to seek the remainder. */
602 offset = count == EOF ? delta : delta-count;
603 dir = _IO_seek_cur;
604 goto dumb;
607 _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + delta,
608 fp->_IO_buf_base + count);
609 _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
610 fp->_offset = result + count;
611 _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
612 return offset;
613 dumb:
615 _IO_unsave_markers (fp);
616 result = _IO_SYSSEEK (fp, offset, dir);
617 if (result != EOF)
619 _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
620 fp->_offset = result;
621 _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
622 _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
624 return result;
626 resync:
627 /* We need to do it since it is possible that the file offset in
628 the kernel may be changed behind our back. It may happen when
629 we fopen a file and then do a fork. One process may access the
630 the file and the kernel file offset will be changed. */
631 if (fp->_offset >= 0)
632 _IO_SYSSEEK (fp, fp->_offset, 0);
634 return offset;
638 _IO_size_t
639 _IO_wfile_xsputn (f, data, n)
640 _IO_FILE *f;
641 const void *data;
642 _IO_size_t n;
644 register const wchar_t *s = (const wchar_t *) data;
645 _IO_size_t to_do = n;
646 int must_flush = 0;
647 _IO_size_t count;
649 if (n <= 0)
650 return 0;
651 /* This is an optimized implementation.
652 If the amount to be written straddles a block boundary
653 (or the filebuf is unbuffered), use sys_write directly. */
655 /* First figure out how much space is available in the buffer. */
656 count = f->_wide_data->_IO_write_end - f->_wide_data->_IO_write_ptr;
657 if ((f->_flags & _IO_LINE_BUF) && (f->_flags & _IO_CURRENTLY_PUTTING))
659 count = f->_wide_data->_IO_buf_end - f->_wide_data->_IO_write_ptr;
660 if (count >= n)
662 register const wchar_t *p;
663 for (p = s + n; p > s; )
665 if (*--p == L'\n')
667 count = p - s + 1;
668 must_flush = 1;
669 break;
674 /* Then fill the buffer. */
675 if (count > 0)
677 if (count > to_do)
678 count = to_do;
679 if (count > 20)
681 #ifdef _LIBC
682 f->_wide_data->_IO_write_ptr =
683 __wmempcpy (f->_wide_data->_IO_write_ptr, s, count);
684 #else
685 wmemcpy (f->_wide_data->_IO_write_ptr, s, count);
686 f->_wide_data->_IO_write_ptr += count;
687 #endif
688 s += count;
690 else
692 register wchar_t *p = f->_wide_data->_IO_write_ptr;
693 register int i = (int) count;
694 while (--i >= 0)
695 *p++ = *s++;
696 f->_wide_data->_IO_write_ptr = p;
698 to_do -= count;
700 if (to_do > 0)
701 to_do -= _IO_wdefault_xsputn (f, s, to_do);
702 if (must_flush
703 && f->_wide_data->_IO_write_ptr != f->_wide_data->_IO_write_base)
704 _IO_wdo_write (f, f->_wide_data->_IO_write_base,
705 f->_wide_data->_IO_write_ptr
706 - f->_wide_data->_IO_write_base);
708 return n - to_do;
712 struct _IO_jump_t _IO_wfile_jumps =
714 JUMP_INIT_DUMMY,
715 JUMP_INIT(finish, _IO_new_file_finish),
716 JUMP_INIT(overflow, (_IO_overflow_t) _IO_wfile_overflow),
717 JUMP_INIT(underflow, (_IO_underflow_t) _IO_wfile_underflow),
718 JUMP_INIT(uflow, (_IO_underflow_t) _IO_wdefault_uflow),
719 JUMP_INIT(pbackfail, (_IO_pbackfail_t) _IO_wdefault_pbackfail),
720 JUMP_INIT(xsputn, _IO_wfile_xsputn),
721 JUMP_INIT(xsgetn, _IO_file_xsgetn),
722 JUMP_INIT(seekoff, _IO_wfile_seekoff),
723 JUMP_INIT(seekpos, _IO_default_seekpos),
724 JUMP_INIT(setbuf, _IO_new_file_setbuf),
725 JUMP_INIT(sync, (_IO_sync_t) _IO_wfile_sync),
726 JUMP_INIT(doallocate, _IO_wfile_doallocate),
727 JUMP_INIT(read, _IO_file_read),
728 JUMP_INIT(write, _IO_new_file_write),
729 JUMP_INIT(seek, _IO_file_seek),
730 JUMP_INIT(close, _IO_file_close),
731 JUMP_INIT(stat, _IO_file_stat),
732 JUMP_INIT(showmanyc, _IO_default_showmanyc),
733 JUMP_INIT(imbue, _IO_default_imbue)