Update.
[glibc.git] / libio / wfileops.c
blob3489b36fb11f71f83e8e576d606cbf37d92d9d58
1 /* Copyright (C) 1993, 1995, 1997, 1998, 1999 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;
63 _IO_size_t count = 0;
65 while (to_do > 0)
67 enum __codecvt_result result;
68 const wchar_t *new_data;
70 if (fp->_IO_write_end == fp->_IO_write_ptr)
72 _IO_new_file_overflow (fp, EOF);
73 assert (fp->_IO_write_end > fp->_IO_write_ptr);
76 /* Now convert from the internal format into the external buffer. */
77 result = (*cc->__codecvt_do_out) (cc, &fp->_wide_data->_IO_state,
78 data, data + to_do, &new_data,
79 fp->_IO_write_ptr,
80 fp->_IO_write_end,
81 &fp->_IO_write_ptr);
83 /* Write out what we produced so far. */
84 if (_IO_new_do_write (fp, fp->_IO_write_base,
85 fp->_IO_write_ptr - fp->_IO_write_base) == EOF)
86 /* Something went wrong. */
87 return EOF;
89 count += new_data - data;
90 to_do -= new_data - data;
91 data = new_data;
93 /* Next see whether we had problems during the conversion. If yes,
94 we cannot go on. */
95 if (result != __codecvt_ok)
96 break;
99 _IO_wsetg (fp, fp->_wide_data->_IO_buf_base, fp->_wide_data->_IO_buf_base,
100 fp->_wide_data->_IO_buf_base);
101 fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_write_ptr
102 = fp->_wide_data->_IO_buf_base;
103 fp->_wide_data->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
104 ? fp->_wide_data->_IO_buf_base
105 : fp->_wide_data->_IO_buf_end);
107 return count;
111 wint_t
112 _IO_wfile_underflow (fp)
113 _IO_FILE *fp;
115 struct _IO_codecvt *cd;
116 enum __codecvt_result status;
117 _IO_ssize_t count;
118 int tries;
119 const char *read_ptr_copy;
121 if (fp->_flags & _IO_NO_READS)
123 fp->_flags |= _IO_ERR_SEEN;
124 __set_errno (EBADF);
125 return WEOF;
127 if (fp->_wide_data->_IO_read_ptr < fp->_wide_data->_IO_read_end)
128 return *fp->_wide_data->_IO_read_ptr;
130 cd = &fp->_wide_data->_codecvt;
132 /* Maybe there is something left in the external buffer. */
133 if (fp->_IO_read_ptr < fp->_IO_read_end)
135 /* Convert it. */
136 size_t avail_bytes = fp->_IO_read_end - fp->_IO_read_ptr;
138 if (avail_bytes >= (*cd->__codecvt_do_max_length) (cd))
140 /* There is more in the external. */
141 const char *read_stop = (const char *) fp->_IO_read_ptr;
143 fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
144 status = (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
145 fp->_IO_read_ptr, fp->_IO_read_end,
146 &read_stop,
147 fp->_wide_data->_IO_read_end,
148 fp->_wide_data->_IO_buf_end,
149 &fp->_wide_data->_IO_read_end);
151 fp->_IO_read_ptr = (char *) read_stop;
153 /* If we managed to generate some text return the next character. */
154 if (fp->_wide_data->_IO_read_ptr < fp->_wide_data->_IO_read_end)
155 return *fp->_wide_data->_IO_read_ptr;
157 if (status == __codecvt_error)
159 __set_errno (EILSEQ);
160 fp->_flags |= _IO_ERR_SEEN;
161 return WEOF;
165 /* Move the remaining content of the read buffer to the beginning. */
166 memmove (fp->_IO_buf_base, fp->_IO_read_ptr,
167 fp->_IO_read_end - fp->_IO_read_ptr);
168 fp->_IO_read_end = (fp->_IO_buf_base
169 + (fp->_IO_read_end - fp->_IO_read_ptr));
170 fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base;
172 else
173 fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_read_end =
174 fp->_IO_buf_base;
176 fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end =
177 fp->_IO_buf_base;
179 if (fp->_IO_buf_base == NULL)
181 /* Maybe we already have a push back pointer. */
182 if (fp->_IO_save_base != NULL)
184 free (fp->_IO_save_base);
185 fp->_flags &= ~_IO_IN_BACKUP;
187 _IO_doallocbuf (fp);
190 if (fp->_wide_data->_IO_buf_base == NULL)
192 /* Maybe we already have a push back pointer. */
193 if (fp->_wide_data->_IO_save_base != NULL)
195 free (fp->_wide_data->_IO_save_base);
196 fp->_flags &= ~_IO_IN_BACKUP;
198 _IO_wdoallocbuf (fp);
201 /* Flush all line buffered files before reading. */
202 /* FIXME This can/should be moved to genops ?? */
203 if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))
204 _IO_flush_all_linebuffered ();
206 _IO_switch_to_get_mode (fp);
208 fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base;
209 fp->_IO_read_end = fp->_IO_buf_base;
210 fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
211 = fp->_IO_buf_base;
213 fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_read_ptr =
214 fp->_wide_data->_IO_buf_base;
215 fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_buf_base;
216 fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_write_ptr =
217 fp->_wide_data->_IO_write_end = fp->_wide_data->_IO_buf_base;
219 tries = 0;
220 again:
221 count = _IO_SYSREAD (fp, fp->_IO_read_end,
222 fp->_IO_buf_end - fp->_IO_read_end);
223 if (count <= 0)
225 if (count == 0 && tries == 0)
226 fp->_flags |= _IO_EOF_SEEN;
227 else
228 fp->_flags |= _IO_ERR_SEEN, count = 0;
230 fp->_IO_read_end += count;
231 if (count == 0)
233 if (tries != 0)
234 /* There are some bytes in the external buffer but they don't
235 convert to anything. */
236 __set_errno (EILSEQ);
237 return WEOF;
239 if (fp->_offset != _IO_pos_BAD)
240 _IO_pos_adjust (fp->_offset, count);
242 /* Now convert the read input. */
243 fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
244 fp->_IO_read_base = fp->_IO_read_ptr;
245 status = (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
246 fp->_IO_read_ptr, fp->_IO_read_end,
247 &read_ptr_copy,
248 fp->_wide_data->_IO_read_end,
249 fp->_wide_data->_IO_buf_end,
250 &fp->_wide_data->_IO_read_end);
252 fp->_IO_read_ptr = (char *) read_ptr_copy;
253 if (fp->_wide_data->_IO_read_end == fp->_wide_data->_IO_buf_base)
255 if (status == __codecvt_error || fp->_IO_read_end == fp->_IO_buf_end)
257 __set_errno (EILSEQ);
258 fp->_flags |= _IO_ERR_SEEN;
259 return WEOF;
262 /* The read bytes make no complete character. Try reading again. */
263 assert (status == __codecvt_partial);
264 ++tries;
265 goto again;
268 return *fp->_wide_data->_IO_read_ptr;
272 wint_t
273 _IO_wfile_overflow (f, wch)
274 _IO_FILE *f;
275 wint_t wch;
277 if (f->_flags & _IO_NO_WRITES) /* SET ERROR */
279 f->_flags |= _IO_ERR_SEEN;
280 __set_errno (EBADF);
281 return WEOF;
283 /* If currently reading or no buffer allocated. */
284 if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0)
286 /* Allocate a buffer if needed. */
287 if (f->_wide_data->_IO_write_base == 0)
289 _IO_wdoallocbuf (f);
290 _IO_wsetg (f, f->_wide_data->_IO_buf_base,
291 f->_wide_data->_IO_buf_base, f->_wide_data->_IO_buf_base);
293 else
295 /* Otherwise must be currently reading. If _IO_read_ptr
296 (and hence also _IO_read_end) is at the buffer end,
297 logically slide the buffer forwards one block (by setting
298 the read pointers to all point at the beginning of the
299 block). This makes room for subsequent output.
300 Otherwise, set the read pointers to _IO_read_end (leaving
301 that alone, so it can continue to correspond to the
302 external position). */
303 if (f->_wide_data->_IO_read_ptr == f->_wide_data->_IO_buf_end)
305 f->_IO_read_end = f->_IO_read_ptr = f->_IO_buf_base;
306 f->_wide_data->_IO_read_end = f->_wide_data->_IO_read_ptr =
307 f->_wide_data->_IO_buf_base;
310 f->_wide_data->_IO_write_ptr = f->_wide_data->_IO_read_ptr;
311 f->_wide_data->_IO_write_base = f->_wide_data->_IO_write_ptr;
312 f->_wide_data->_IO_write_end = f->_wide_data->_IO_buf_end;
313 f->_wide_data->_IO_read_base = f->_wide_data->_IO_read_ptr =
314 f->_wide_data->_IO_read_end;
316 f->_flags |= _IO_CURRENTLY_PUTTING;
317 if (f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
318 f->_wide_data->_IO_write_end = f->_wide_data->_IO_write_ptr;
320 if (wch == WEOF)
321 return _IO_do_flush (f);
322 if (f->_wide_data->_IO_write_ptr == f->_wide_data->_IO_buf_end )
323 /* Buffer is really full */
324 if (_IO_do_flush (f) == WEOF)
325 return WEOF;
326 *f->_wide_data->_IO_write_ptr++ = wch;
327 if ((f->_flags & _IO_UNBUFFERED)
328 || ((f->_flags & _IO_LINE_BUF) && wch == L'\n'))
329 if (_IO_do_flush (f) == WEOF)
330 return WEOF;
331 return wch;
334 wint_t
335 _IO_wfile_sync (fp)
336 _IO_FILE *fp;
338 _IO_ssize_t delta;
339 wint_t retval = 0;
341 /* char* ptr = cur_ptr(); */
342 if (fp->_wide_data->_IO_write_ptr > fp->_wide_data->_IO_write_base)
343 if (_IO_do_flush (fp))
344 return WEOF;
345 delta = fp->_wide_data->_IO_read_ptr - fp->_wide_data->_IO_read_end;
346 if (delta != 0)
348 /* We have to find out how many bytes we have to go back in the
349 external buffer. */
350 struct _IO_codecvt *cv = &fp->_wide_data->_codecvt;
351 _IO_off64_t new_pos;
353 int clen = (*cv->__codecvt_do_encoding) (cv);
355 if (clen > 0)
356 /* It is easy, a fixed number of input bytes are used for each
357 wide character. */
358 delta *= clen;
359 else
361 /* We have to find out the hard way how much to back off.
362 To do this we determine how much input we needed to
363 generate the wide characters up to the current reading
364 position. */
365 int nread;
367 fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state;
368 nread = (*cv->__codecvt_do_length) (cv, &fp->_wide_data->_IO_state,
369 fp->_IO_read_base,
370 fp->_IO_read_end, delta);
371 fp->_IO_read_ptr = fp->_IO_read_base + nread;
372 delta = -(fp->_IO_read_end - fp->_IO_read_base - nread);
375 new_pos = _IO_SYSSEEK (fp, delta, 1);
376 if (new_pos != (_IO_off64_t) EOF)
378 fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_read_ptr;
379 fp->_IO_read_end = fp->_IO_read_ptr;
381 #ifdef ESPIPE
382 else if (errno == ESPIPE)
383 ; /* Ignore error from unseekable devices. */
384 #endif
385 else
386 retval = WEOF;
388 if (retval != WEOF)
389 fp->_offset = _IO_pos_BAD;
390 /* FIXME: Cleanup - can this be shared? */
391 /* setg(base(), ptr, ptr); */
392 return retval;
395 _IO_off64_t
396 _IO_wfile_seekoff (fp, offset, dir, mode)
397 _IO_FILE *fp;
398 _IO_off64_t offset;
399 int dir;
400 int mode;
402 _IO_off64_t result;
403 _IO_off64_t delta, new_offset;
404 long int count;
405 /* POSIX.1 8.2.3.7 says that after a call the fflush() the file
406 offset of the underlying file must be exact. */
407 int must_be_exact = ((fp->_wide_data->_IO_read_base
408 == fp->_wide_data->_IO_read_end)
409 && (fp->_wide_data->_IO_write_base
410 == fp->_wide_data->_IO_write_ptr));
412 if (mode == 0)
413 dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */
415 /* Flush unwritten characters.
416 (This may do an unneeded write if we seek within the buffer.
417 But to be able to switch to reading, we would need to set
418 egptr to ptr. That can't be done in the current design,
419 which assumes file_ptr() is eGptr. Anyway, since we probably
420 end up flushing when we close(), it doesn't make much difference.)
421 FIXME: simulate mem-papped files. */
423 if (fp->_wide_data->_IO_write_ptr > fp->_wide_data->_IO_write_base
424 || _IO_in_put_mode (fp))
425 if (_IO_switch_to_wget_mode (fp))
426 return WEOF;
428 if (fp->_wide_data->_IO_buf_base == NULL)
430 /* It could be that we already have a pushback buffer. */
431 if (fp->_wide_data->_IO_read_base != NULL)
433 free (fp->_wide_data->_IO_read_base);
434 fp->_flags &= ~_IO_IN_BACKUP;
436 _IO_doallocbuf (fp);
437 _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
438 _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
439 _IO_wsetp (fp, fp->_wide_data->_IO_buf_base,
440 fp->_wide_data->_IO_buf_base);
441 _IO_wsetg (fp, fp->_wide_data->_IO_buf_base,
442 fp->_wide_data->_IO_buf_base, fp->_wide_data->_IO_buf_base);
445 switch (dir)
447 struct _IO_codecvt *cv;
448 int clen;
450 case _IO_seek_cur:
451 /* Adjust for read-ahead (bytes is buffer). To do this we must
452 find out which position in the external buffer corresponds to
453 the current position in the internal buffer. */
454 cv = &fp->_wide_data->_codecvt;
455 clen = (*cv->__codecvt_do_encoding) (cv);
457 if (clen > 0)
458 offset -= (fp->_wide_data->_IO_read_end
459 - fp->_wide_data->_IO_read_ptr) * clen;
460 else
462 int nread;
464 delta = fp->_wide_data->_IO_read_ptr - fp->_wide_data->_IO_read_end;
465 fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state;
466 nread = (*cv->__codecvt_do_length) (cv, &fp->_wide_data->_IO_state,
467 fp->_IO_read_base,
468 fp->_IO_read_end, delta);
469 fp->_IO_read_ptr = fp->_IO_read_base + nread;
470 offset -= fp->_IO_read_end - fp->_IO_read_base - nread;
473 if (fp->_offset == _IO_pos_BAD)
474 goto dumb;
475 /* Make offset absolute, assuming current pointer is file_ptr(). */
476 offset += fp->_offset;
478 dir = _IO_seek_set;
479 break;
480 case _IO_seek_set:
481 break;
482 case _IO_seek_end:
484 struct _G_stat64 st;
485 if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode))
487 offset += st.st_size;
488 dir = _IO_seek_set;
490 else
491 goto dumb;
494 /* At this point, dir==_IO_seek_set. */
496 /* If we are only interested in the current position we've found it now. */
497 if (mode == 0)
498 return offset;
500 /* If destination is within current buffer, optimize: */
501 if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
502 && !_IO_in_backup (fp))
504 /* Offset relative to start of main get area. */
505 _IO_off64_t rel_offset = (offset - fp->_offset
506 + (fp->_IO_read_end - fp->_IO_read_base));
507 if (rel_offset >= 0)
509 #if 0
510 if (_IO_in_backup (fp))
511 _IO_switch_to_main_get_area (fp);
512 #endif
513 if (rel_offset <= fp->_IO_read_end - fp->_IO_read_base)
515 fp->_IO_read_ptr = fp->_IO_read_base + rel_offset;
516 _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
518 /* Now set the pointer for the internal buffer. This
519 might be an iterative process. Though the read
520 pointer is somewhere in the current external buffer
521 this does not mean we can convert this whole buffer
522 at once fitting in the internal buffer. */
527 while (0);
529 _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
530 goto resync;
532 #ifdef TODO
533 /* If we have streammarkers, seek forward by reading ahead. */
534 if (_IO_have_markers (fp))
536 int to_skip = rel_offset
537 - (fp->_IO_read_ptr - fp->_IO_read_base);
538 if (ignore (to_skip) != to_skip)
539 goto dumb;
540 _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
541 goto resync;
543 #endif
545 #ifdef TODO
546 if (rel_offset < 0 && rel_offset >= Bbase () - Bptr ())
548 if (!_IO_in_backup (fp))
549 _IO_switch_to_backup_area (fp);
550 gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
551 _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
552 goto resync;
554 #endif
557 #ifdef TODO
558 _IO_unsave_markers (fp);
559 #endif
561 if (fp->_flags & _IO_NO_READS)
562 goto dumb;
564 /* Try to seek to a block boundary, to improve kernel page management. */
565 new_offset = offset & ~(fp->_IO_buf_end - fp->_IO_buf_base - 1);
566 delta = offset - new_offset;
567 if (delta > fp->_IO_buf_end - fp->_IO_buf_base)
569 new_offset = offset;
570 delta = 0;
572 result = _IO_SYSSEEK (fp, new_offset, 0);
573 if (result < 0)
574 return EOF;
575 if (delta == 0)
576 count = 0;
577 else
579 count = _IO_SYSREAD (fp, fp->_IO_buf_base,
580 (must_be_exact
581 ? delta : fp->_IO_buf_end - fp->_IO_buf_base));
582 if (count < delta)
584 /* We weren't allowed to read, but try to seek the remainder. */
585 offset = count == EOF ? delta : delta-count;
586 dir = _IO_seek_cur;
587 goto dumb;
590 _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + delta,
591 fp->_IO_buf_base + count);
592 _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
593 fp->_offset = result + count;
594 _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
595 return offset;
596 dumb:
598 _IO_unsave_markers (fp);
599 result = _IO_SYSSEEK (fp, offset, dir);
600 if (result != EOF)
602 _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
603 fp->_offset = result;
604 _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
605 _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
607 return result;
609 resync:
610 /* We need to do it since it is possible that the file offset in
611 the kernel may be changed behind our back. It may happen when
612 we fopen a file and then do a fork. One process may access the
613 the file and the kernel file offset will be changed. */
614 if (fp->_offset >= 0)
615 _IO_SYSSEEK (fp, fp->_offset, 0);
617 return offset;
621 _IO_size_t
622 _IO_wfile_xsputn (f, data, n)
623 _IO_FILE *f;
624 const void *data;
625 _IO_size_t n;
627 register const wchar_t *s = (const wchar_t *) data;
628 _IO_size_t to_do = n;
629 int must_flush = 0;
630 _IO_size_t count;
632 if (n <= 0)
633 return 0;
634 /* This is an optimized implementation.
635 If the amount to be written straddles a block boundary
636 (or the filebuf is unbuffered), use sys_write directly. */
638 /* First figure out how much space is available in the buffer. */
639 count = f->_wide_data->_IO_write_end - f->_wide_data->_IO_write_ptr;
640 if ((f->_flags & _IO_LINE_BUF) && (f->_flags & _IO_CURRENTLY_PUTTING))
642 count = f->_wide_data->_IO_buf_end - f->_wide_data->_IO_write_ptr;
643 if (count >= n)
645 register const wchar_t *p;
646 for (p = s + n; p > s; )
648 if (*--p == L'\n')
650 count = p - s + 1;
651 must_flush = 1;
652 break;
657 /* Then fill the buffer. */
658 if (count > 0)
660 if (count > to_do)
661 count = to_do;
662 if (count > 20)
664 #ifdef _LIBC
665 f->_wide_data->_IO_write_ptr =
666 __wmempcpy (f->_wide_data->_IO_write_ptr, s, count);
667 #else
668 wmemcpy (f->_wide_data->_IO_write_ptr, s, count);
669 f->_wide_data->_IO_write_ptr += count;
670 #endif
671 s += count;
673 else
675 register wchar_t *p = f->_wide_data->_IO_write_ptr;
676 register int i = (int) count;
677 while (--i >= 0)
678 *p++ = *s++;
679 f->_wide_data->_IO_write_ptr = p;
681 to_do -= count;
683 if (to_do > 0)
684 to_do -= _IO_wdefault_xsputn (f, s, to_do);
685 if (must_flush
686 && f->_wide_data->_IO_write_ptr != f->_wide_data->_IO_write_base)
687 _IO_wdo_write (f, f->_wide_data->_IO_write_base,
688 f->_wide_data->_IO_write_ptr
689 - f->_wide_data->_IO_write_base);
691 return n - to_do;
695 struct _IO_jump_t _IO_wfile_jumps =
697 JUMP_INIT_DUMMY,
698 JUMP_INIT(finish, _IO_new_file_finish),
699 JUMP_INIT(overflow, (_IO_overflow_t) _IO_wfile_overflow),
700 JUMP_INIT(underflow, (_IO_underflow_t) _IO_wfile_underflow),
701 JUMP_INIT(uflow, (_IO_underflow_t) _IO_wdefault_uflow),
702 JUMP_INIT(pbackfail, (_IO_pbackfail_t) _IO_wdefault_pbackfail),
703 JUMP_INIT(xsputn, _IO_wfile_xsputn),
704 JUMP_INIT(xsgetn, _IO_file_xsgetn),
705 JUMP_INIT(seekoff, _IO_wfile_seekoff),
706 JUMP_INIT(seekpos, _IO_default_seekpos),
707 JUMP_INIT(setbuf, _IO_new_file_setbuf),
708 JUMP_INIT(sync, (_IO_sync_t) _IO_wfile_sync),
709 JUMP_INIT(doallocate, _IO_wfile_doallocate),
710 JUMP_INIT(read, _IO_file_read),
711 JUMP_INIT(write, _IO_new_file_write),
712 JUMP_INIT(seek, _IO_file_seek),
713 JUMP_INIT(close, _IO_file_close),
714 JUMP_INIT(stat, _IO_file_stat),
715 JUMP_INIT(showmanyc, _IO_default_showmanyc),
716 JUMP_INIT(imbue, _IO_default_imbue)