1 /* Copyright (C) 1993,95,97,98,99,2000,2001,2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Written by Ulrich Drepper <drepper@cygnus.com>.
4 Based on the single byte version by Per Bothner <bothner@cygnus.com>.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 As a special exception, if you link the code in this file with
22 files compiled with a GNU compiler to produce an executable,
23 that does not cause the resulting executable to be covered by
24 the GNU Lesser General Public License. This exception does not
25 however invalidate any other reasons why the executable file
26 might be covered by the GNU Lesser General Public License.
27 This exception applies to code released by its copyright holders
28 in files containing the exception. */
39 # define _IO_new_do_write _IO_do_write
40 # define _IO_new_file_attach _IO_file_attach
41 # define _IO_new_file_close_it _IO_file_close_it
42 # define _IO_new_file_finish _IO_file_finish
43 # define _IO_new_file_fopen _IO_file_fopen
44 # define _IO_new_file_init _IO_file_init
45 # define _IO_new_file_setbuf _IO_file_setbuf
46 # define _IO_new_file_sync _IO_file_sync
47 # define _IO_new_file_overflow _IO_file_overflow
48 # define _IO_new_file_seekoff _IO_file_seekoff
49 # define _IO_new_file_underflow _IO_file_underflow
50 # define _IO_new_file_write _IO_file_write
51 # define _IO_new_file_xsputn _IO_file_xsputn
55 /* Convert TO_DO wide character from DATA to FP.
56 Then mark FP as having empty buffers. */
58 _IO_wdo_write (fp
, data
, to_do
)
63 struct _IO_codecvt
*cc
= fp
->_codecvt
;
67 if (fp
->_IO_write_end
== fp
->_IO_write_ptr
68 && fp
->_IO_write_end
!= fp
->_IO_write_base
)
70 if (_IO_new_do_write (fp
, fp
->_IO_write_base
,
71 fp
->_IO_write_ptr
- fp
->_IO_write_base
) == EOF
)
77 enum __codecvt_result result
;
78 const wchar_t *new_data
;
80 /* Now convert from the internal format into the external buffer. */
81 result
= (*cc
->__codecvt_do_out
) (cc
, &fp
->_wide_data
->_IO_state
,
82 data
, data
+ to_do
, &new_data
,
87 /* Write out what we produced so far. */
88 if (_IO_new_do_write (fp
, fp
->_IO_write_base
,
89 fp
->_IO_write_ptr
- fp
->_IO_write_base
) == EOF
)
90 /* Something went wrong. */
93 to_do
-= new_data
- data
;
95 /* Next see whether we had problems during the conversion. If yes,
97 if (result
!= __codecvt_ok
98 && (result
!= __codecvt_partial
|| new_data
- data
== 0))
106 _IO_wsetg (fp
, fp
->_wide_data
->_IO_buf_base
, fp
->_wide_data
->_IO_buf_base
,
107 fp
->_wide_data
->_IO_buf_base
);
108 fp
->_wide_data
->_IO_write_base
= fp
->_wide_data
->_IO_write_ptr
109 = fp
->_wide_data
->_IO_buf_base
;
110 fp
->_wide_data
->_IO_write_end
= ((fp
->_flags
& (_IO_LINE_BUF
+_IO_UNBUFFERED
))
111 ? fp
->_wide_data
->_IO_buf_base
112 : fp
->_wide_data
->_IO_buf_end
);
114 return to_do
== 0 ? 0 : WEOF
;
116 INTDEF(_IO_wdo_write
)
120 _IO_wfile_underflow (fp
)
123 struct _IO_codecvt
*cd
;
124 enum __codecvt_result status
;
127 const char *read_ptr_copy
;
129 if (__builtin_expect (fp
->_flags
& _IO_NO_READS
, 0))
131 fp
->_flags
|= _IO_ERR_SEEN
;
135 if (fp
->_wide_data
->_IO_read_ptr
< fp
->_wide_data
->_IO_read_end
)
136 return *fp
->_wide_data
->_IO_read_ptr
;
140 /* Maybe there is something left in the external buffer. */
141 if (fp
->_IO_read_ptr
< fp
->_IO_read_end
)
143 /* There is more in the external. Convert it. */
144 const char *read_stop
= (const char *) fp
->_IO_read_ptr
;
146 fp
->_wide_data
->_IO_last_state
= fp
->_wide_data
->_IO_state
;
147 fp
->_wide_data
->_IO_read_base
= fp
->_wide_data
->_IO_read_ptr
=
148 fp
->_wide_data
->_IO_buf_base
;
149 status
= (*cd
->__codecvt_do_in
) (cd
, &fp
->_wide_data
->_IO_state
,
150 fp
->_IO_read_ptr
, fp
->_IO_read_end
,
152 fp
->_wide_data
->_IO_read_ptr
,
153 fp
->_wide_data
->_IO_buf_end
,
154 &fp
->_wide_data
->_IO_read_end
);
156 fp
->_IO_read_ptr
= (char *) read_stop
;
158 /* If we managed to generate some text return the next character. */
159 if (fp
->_wide_data
->_IO_read_ptr
< fp
->_wide_data
->_IO_read_end
)
160 return *fp
->_wide_data
->_IO_read_ptr
;
162 if (status
== __codecvt_error
)
164 __set_errno (EILSEQ
);
165 fp
->_flags
|= _IO_ERR_SEEN
;
169 /* Move the remaining content of the read buffer to the beginning. */
170 memmove (fp
->_IO_buf_base
, fp
->_IO_read_ptr
,
171 fp
->_IO_read_end
- fp
->_IO_read_ptr
);
172 fp
->_IO_read_end
= (fp
->_IO_buf_base
173 + (fp
->_IO_read_end
- fp
->_IO_read_ptr
));
174 fp
->_IO_read_base
= fp
->_IO_read_ptr
= fp
->_IO_buf_base
;
177 fp
->_IO_read_base
= fp
->_IO_read_ptr
= fp
->_IO_read_end
=
180 if (fp
->_IO_buf_base
== NULL
)
182 /* Maybe we already have a push back pointer. */
183 if (fp
->_IO_save_base
!= NULL
)
185 free (fp
->_IO_save_base
);
186 fp
->_flags
&= ~_IO_IN_BACKUP
;
188 INTUSE(_IO_doallocbuf
) (fp
);
190 fp
->_IO_read_base
= fp
->_IO_read_ptr
= fp
->_IO_read_end
=
194 fp
->_IO_write_base
= fp
->_IO_write_ptr
= fp
->_IO_write_end
=
197 if (fp
->_wide_data
->_IO_buf_base
== NULL
)
199 /* Maybe we already have a push back pointer. */
200 if (fp
->_wide_data
->_IO_save_base
!= NULL
)
202 free (fp
->_wide_data
->_IO_save_base
);
203 fp
->_flags
&= ~_IO_IN_BACKUP
;
205 INTUSE(_IO_wdoallocbuf
) (fp
);
208 /* Flush all line buffered files before reading. */
209 /* FIXME This can/should be moved to genops ?? */
210 if (fp
->_flags
& (_IO_LINE_BUF
|_IO_UNBUFFERED
))
213 INTUSE(_IO_flush_all_linebuffered
) ();
215 /* We used to flush all line-buffered stream. This really isn't
216 required by any standard. My recollection is that
217 traditional Unix systems did this for stdout. stderr better
218 not be line buffered. So we do just that here
219 explicitly. --drepper */
220 _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile
,
222 _IO_flockfile (_IO_stdout
);
224 if ((_IO_stdout
->_flags
& (_IO_LINKED
| _IO_NO_WRITES
| _IO_LINE_BUF
))
225 == (_IO_LINKED
| _IO_LINE_BUF
))
226 _IO_OVERFLOW (_IO_stdout
, EOF
);
228 _IO_funlockfile (_IO_stdout
);
229 _IO_cleanup_region_end (0);
233 INTUSE(_IO_switch_to_get_mode
) (fp
);
235 fp
->_wide_data
->_IO_read_base
= fp
->_wide_data
->_IO_read_ptr
=
236 fp
->_wide_data
->_IO_buf_base
;
237 fp
->_wide_data
->_IO_read_end
= fp
->_wide_data
->_IO_buf_base
;
238 fp
->_wide_data
->_IO_write_base
= fp
->_wide_data
->_IO_write_ptr
=
239 fp
->_wide_data
->_IO_write_end
= fp
->_wide_data
->_IO_buf_base
;
243 count
= _IO_SYSREAD (fp
, fp
->_IO_read_end
,
244 fp
->_IO_buf_end
- fp
->_IO_read_end
);
247 if (count
== 0 && tries
== 0)
248 fp
->_flags
|= _IO_EOF_SEEN
;
250 fp
->_flags
|= _IO_ERR_SEEN
, count
= 0;
252 fp
->_IO_read_end
+= count
;
256 /* There are some bytes in the external buffer but they don't
257 convert to anything. */
258 __set_errno (EILSEQ
);
261 if (fp
->_offset
!= _IO_pos_BAD
)
262 _IO_pos_adjust (fp
->_offset
, count
);
264 /* Now convert the read input. */
265 fp
->_wide_data
->_IO_last_state
= fp
->_wide_data
->_IO_state
;
266 fp
->_IO_read_base
= fp
->_IO_read_ptr
;
267 status
= (*cd
->__codecvt_do_in
) (cd
, &fp
->_wide_data
->_IO_state
,
268 fp
->_IO_read_ptr
, fp
->_IO_read_end
,
270 fp
->_wide_data
->_IO_read_end
,
271 fp
->_wide_data
->_IO_buf_end
,
272 &fp
->_wide_data
->_IO_read_end
);
274 fp
->_IO_read_ptr
= (char *) read_ptr_copy
;
275 if (fp
->_wide_data
->_IO_read_end
== fp
->_wide_data
->_IO_buf_base
)
277 if (status
== __codecvt_error
|| fp
->_IO_read_end
== fp
->_IO_buf_end
)
279 __set_errno (EILSEQ
);
280 fp
->_flags
|= _IO_ERR_SEEN
;
284 /* The read bytes make no complete character. Try reading again. */
285 assert (status
== __codecvt_partial
);
290 return *fp
->_wide_data
->_IO_read_ptr
;
292 INTDEF(_IO_wfile_underflow
)
296 _IO_wfile_underflow_mmap (_IO_FILE
*fp
)
298 struct _IO_codecvt
*cd
;
299 enum __codecvt_result status
;
300 const char *read_stop
;
302 if (__builtin_expect (fp
->_flags
& _IO_NO_READS
, 0))
304 fp
->_flags
|= _IO_ERR_SEEN
;
308 if (fp
->_wide_data
->_IO_read_ptr
< fp
->_wide_data
->_IO_read_end
)
309 return *fp
->_wide_data
->_IO_read_ptr
;
313 /* Maybe there is something left in the external buffer. */
314 if (fp
->_IO_read_ptr
>= fp
->_IO_read_end
315 /* No. But maybe the read buffer is not fully set up. */
316 && _IO_file_underflow_mmap (fp
) == EOF
)
317 /* Nothing available. _IO_file_underflow_mmap has set the EOF or error
318 flags as appropriate. */
321 /* There is more in the external. Convert it. */
322 read_stop
= (const char *) fp
->_IO_read_ptr
;
324 if (fp
->_wide_data
->_IO_buf_base
== NULL
)
326 /* Maybe we already have a push back pointer. */
327 if (fp
->_wide_data
->_IO_save_base
!= NULL
)
329 free (fp
->_wide_data
->_IO_save_base
);
330 fp
->_flags
&= ~_IO_IN_BACKUP
;
332 INTUSE(_IO_wdoallocbuf
) (fp
);
335 fp
->_wide_data
->_IO_last_state
= fp
->_wide_data
->_IO_state
;
336 fp
->_wide_data
->_IO_read_base
= fp
->_wide_data
->_IO_read_ptr
=
337 fp
->_wide_data
->_IO_buf_base
;
338 status
= (*cd
->__codecvt_do_in
) (cd
, &fp
->_wide_data
->_IO_state
,
339 fp
->_IO_read_ptr
, fp
->_IO_read_end
,
341 fp
->_wide_data
->_IO_read_ptr
,
342 fp
->_wide_data
->_IO_buf_end
,
343 &fp
->_wide_data
->_IO_read_end
);
345 fp
->_IO_read_ptr
= (char *) read_stop
;
347 /* If we managed to generate some text return the next character. */
348 if (fp
->_wide_data
->_IO_read_ptr
< fp
->_wide_data
->_IO_read_end
)
349 return *fp
->_wide_data
->_IO_read_ptr
;
351 /* There is some garbage at the end of the file. */
352 __set_errno (EILSEQ
);
353 fp
->_flags
|= _IO_ERR_SEEN
;
358 _IO_wfile_underflow_maybe_mmap (_IO_FILE
*fp
)
360 /* This is the first read attempt. Doing the underflow will choose mmap
361 or vanilla operations and then punt to the chosen underflow routine.
362 Then we can punt to ours. */
363 if (_IO_file_underflow_maybe_mmap (fp
) == EOF
)
366 return _IO_WUNDERFLOW (fp
);
371 _IO_wfile_overflow (f
, wch
)
375 if (f
->_flags
& _IO_NO_WRITES
) /* SET ERROR */
377 f
->_flags
|= _IO_ERR_SEEN
;
381 /* If currently reading or no buffer allocated. */
382 if ((f
->_flags
& _IO_CURRENTLY_PUTTING
) == 0)
384 /* Allocate a buffer if needed. */
385 if (f
->_wide_data
->_IO_write_base
== 0)
387 INTUSE(_IO_wdoallocbuf
) (f
);
388 _IO_wsetg (f
, f
->_wide_data
->_IO_buf_base
,
389 f
->_wide_data
->_IO_buf_base
, f
->_wide_data
->_IO_buf_base
);
391 if (f
->_IO_write_base
== NULL
)
393 INTUSE(_IO_doallocbuf
) (f
);
394 _IO_setg (f
, f
->_IO_buf_base
, f
->_IO_buf_base
, f
->_IO_buf_base
);
399 /* Otherwise must be currently reading. If _IO_read_ptr
400 (and hence also _IO_read_end) is at the buffer end,
401 logically slide the buffer forwards one block (by setting
402 the read pointers to all point at the beginning of the
403 block). This makes room for subsequent output.
404 Otherwise, set the read pointers to _IO_read_end (leaving
405 that alone, so it can continue to correspond to the
406 external position). */
407 if (f
->_wide_data
->_IO_read_ptr
== f
->_wide_data
->_IO_buf_end
)
409 f
->_IO_read_end
= f
->_IO_read_ptr
= f
->_IO_buf_base
;
410 f
->_wide_data
->_IO_read_end
= f
->_wide_data
->_IO_read_ptr
=
411 f
->_wide_data
->_IO_buf_base
;
414 f
->_wide_data
->_IO_write_ptr
= f
->_wide_data
->_IO_read_ptr
;
415 f
->_wide_data
->_IO_write_base
= f
->_wide_data
->_IO_write_ptr
;
416 f
->_wide_data
->_IO_write_end
= f
->_wide_data
->_IO_buf_end
;
417 f
->_wide_data
->_IO_read_base
= f
->_wide_data
->_IO_read_ptr
=
418 f
->_wide_data
->_IO_read_end
;
420 f
->_IO_write_ptr
= f
->_IO_read_ptr
;
421 f
->_IO_write_base
= f
->_IO_write_ptr
;
422 f
->_IO_write_end
= f
->_IO_buf_end
;
423 f
->_IO_read_base
= f
->_IO_read_ptr
= f
->_IO_read_end
;
425 f
->_flags
|= _IO_CURRENTLY_PUTTING
;
426 if (f
->_flags
& (_IO_LINE_BUF
+_IO_UNBUFFERED
))
427 f
->_wide_data
->_IO_write_end
= f
->_wide_data
->_IO_write_ptr
;
430 return _IO_do_flush (f
);
431 if (f
->_wide_data
->_IO_write_ptr
== f
->_wide_data
->_IO_buf_end
)
432 /* Buffer is really full */
433 if (_IO_do_flush (f
) == WEOF
)
435 *f
->_wide_data
->_IO_write_ptr
++ = wch
;
436 if ((f
->_flags
& _IO_UNBUFFERED
)
437 || ((f
->_flags
& _IO_LINE_BUF
) && wch
== L
'\n'))
438 if (_IO_do_flush (f
) == WEOF
)
442 INTDEF(_IO_wfile_overflow
)
451 /* char* ptr = cur_ptr(); */
452 if (fp
->_wide_data
->_IO_write_ptr
> fp
->_wide_data
->_IO_write_base
)
453 if (_IO_do_flush (fp
))
455 delta
= fp
->_wide_data
->_IO_read_ptr
- fp
->_wide_data
->_IO_read_end
;
458 /* We have to find out how many bytes we have to go back in the
460 struct _IO_codecvt
*cv
= fp
->_codecvt
;
463 int clen
= (*cv
->__codecvt_do_encoding
) (cv
);
466 /* It is easy, a fixed number of input bytes are used for each
471 /* We have to find out the hard way how much to back off.
472 To do this we determine how much input we needed to
473 generate the wide characters up to the current reading
477 fp
->_wide_data
->_IO_state
= fp
->_wide_data
->_IO_last_state
;
478 nread
= (*cv
->__codecvt_do_length
) (cv
, &fp
->_wide_data
->_IO_state
,
480 fp
->_IO_read_end
, delta
);
481 fp
->_IO_read_ptr
= fp
->_IO_read_base
+ nread
;
482 delta
= -(fp
->_IO_read_end
- fp
->_IO_read_base
- nread
);
485 new_pos
= _IO_SYSSEEK (fp
, delta
, 1);
486 if (new_pos
!= (_IO_off64_t
) EOF
)
488 fp
->_wide_data
->_IO_read_end
= fp
->_wide_data
->_IO_read_ptr
;
489 fp
->_IO_read_end
= fp
->_IO_read_ptr
;
492 else if (errno
== ESPIPE
)
493 ; /* Ignore error from unseekable devices. */
499 fp
->_offset
= _IO_pos_BAD
;
500 /* FIXME: Cleanup - can this be shared? */
501 /* setg(base(), ptr, ptr); */
504 INTDEF(_IO_wfile_sync
)
507 _IO_wfile_seekoff (fp
, offset
, dir
, mode
)
514 _IO_off64_t delta
, new_offset
;
516 /* POSIX.1 8.2.3.7 says that after a call the fflush() the file
517 offset of the underlying file must be exact. */
518 int must_be_exact
= ((fp
->_wide_data
->_IO_read_base
519 == fp
->_wide_data
->_IO_read_end
)
520 && (fp
->_wide_data
->_IO_write_base
521 == fp
->_wide_data
->_IO_write_ptr
));
525 /* XXX For wide stream with backup store it is not very
526 reasonable to determine the offset. The pushed-back
527 character might require a state change and we need not be
528 able to compute the initial state by reverse transformation
529 since there is no guarantee of symmetry. So we don't even
530 try and return an error. */
531 if (_IO_in_backup (fp
))
533 if (fp
->_wide_data
->_IO_read_ptr
< fp
->_wide_data
->_IO_read_end
)
535 __set_errno (EINVAL
);
539 /* There is no more data in the backup buffer. We can
541 INTUSE(_IO_switch_to_main_wget_area
) (fp
);
544 dir
= _IO_seek_cur
, offset
= 0; /* Don't move any pointers. */
547 /* Flush unwritten characters.
548 (This may do an unneeded write if we seek within the buffer.
549 But to be able to switch to reading, we would need to set
550 egptr to ptr. That can't be done in the current design,
551 which assumes file_ptr() is eGptr. Anyway, since we probably
552 end up flushing when we close(), it doesn't make much difference.)
553 FIXME: simulate mem-mapped files. */
555 if (fp
->_wide_data
->_IO_write_ptr
> fp
->_wide_data
->_IO_write_base
556 || _IO_in_put_mode (fp
))
557 if (INTUSE(_IO_switch_to_wget_mode
) (fp
))
560 if (fp
->_wide_data
->_IO_buf_base
== NULL
)
562 /* It could be that we already have a pushback buffer. */
563 if (fp
->_wide_data
->_IO_read_base
!= NULL
)
565 free (fp
->_wide_data
->_IO_read_base
);
566 fp
->_flags
&= ~_IO_IN_BACKUP
;
568 INTUSE(_IO_doallocbuf
) (fp
);
569 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
570 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
571 _IO_wsetp (fp
, fp
->_wide_data
->_IO_buf_base
,
572 fp
->_wide_data
->_IO_buf_base
);
573 _IO_wsetg (fp
, fp
->_wide_data
->_IO_buf_base
,
574 fp
->_wide_data
->_IO_buf_base
, fp
->_wide_data
->_IO_buf_base
);
579 struct _IO_codecvt
*cv
;
583 /* Adjust for read-ahead (bytes is buffer). To do this we must
584 find out which position in the external buffer corresponds to
585 the current position in the internal buffer. */
587 clen
= (*cv
->__codecvt_do_encoding
) (cv
);
590 offset
-= (fp
->_wide_data
->_IO_read_end
591 - fp
->_wide_data
->_IO_read_ptr
) * clen
;
596 delta
= fp
->_wide_data
->_IO_read_ptr
- fp
->_wide_data
->_IO_read_base
;
597 fp
->_wide_data
->_IO_state
= fp
->_wide_data
->_IO_last_state
;
598 nread
= (*cv
->__codecvt_do_length
) (cv
, &fp
->_wide_data
->_IO_state
,
600 fp
->_IO_read_end
, delta
);
601 fp
->_IO_read_ptr
= fp
->_IO_read_base
+ nread
;
602 fp
->_wide_data
->_IO_read_end
= fp
->_wide_data
->_IO_read_ptr
;
603 offset
-= fp
->_IO_read_end
- fp
->_IO_read_base
- nread
;
606 if (fp
->_offset
== _IO_pos_BAD
)
608 /* Make offset absolute, assuming current pointer is file_ptr(). */
609 offset
+= fp
->_offset
;
618 if (_IO_SYSSTAT (fp
, &st
) == 0 && S_ISREG (st
.st_mode
))
620 offset
+= st
.st_size
;
627 /* At this point, dir==_IO_seek_set. */
629 /* If we are only interested in the current position we've found it now. */
633 /* If destination is within current buffer, optimize: */
634 if (fp
->_offset
!= _IO_pos_BAD
&& fp
->_IO_read_base
!= NULL
635 && !_IO_in_backup (fp
))
637 /* Offset relative to start of main get area. */
638 _IO_off64_t rel_offset
= (offset
- fp
->_offset
639 + (fp
->_IO_read_end
- fp
->_IO_read_base
));
643 if (_IO_in_backup (fp
))
644 _IO_switch_to_main_get_area (fp
);
646 if (rel_offset
<= fp
->_IO_read_end
- fp
->_IO_read_base
)
648 enum __codecvt_result status
;
649 struct _IO_codecvt
*cd
= fp
->_codecvt
;
650 const char *read_ptr_copy
;
652 fp
->_IO_read_ptr
= fp
->_IO_read_base
+ rel_offset
;
653 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
655 /* Now set the pointer for the internal buffer. This
656 might be an iterative process. Though the read
657 pointer is somewhere in the current external buffer
658 this does not mean we can convert this whole buffer
659 at once fitting in the internal buffer. */
660 fp
->_wide_data
->_IO_state
= fp
->_wide_data
->_IO_last_state
;
661 read_ptr_copy
= fp
->_IO_read_base
;
662 fp
->_wide_data
->_IO_read_ptr
= fp
->_wide_data
->_IO_read_base
;
665 wchar_t buffer
[1024];
667 status
= (*cd
->__codecvt_do_in
) (cd
,
668 &fp
->_wide_data
->_IO_state
,
675 / sizeof (buffer
[0])),
677 if (status
!= __codecvt_ok
&& status
!= __codecvt_partial
)
679 fp
->_flags
|= _IO_ERR_SEEN
;
683 while (read_ptr_copy
!= fp
->_IO_read_ptr
);
685 fp
->_wide_data
->_IO_read_ptr
= fp
->_wide_data
->_IO_read_end
686 = fp
->_wide_data
->_IO_read_base
;
688 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
692 /* If we have streammarkers, seek forward by reading ahead. */
693 if (_IO_have_markers (fp
))
695 int to_skip
= rel_offset
696 - (fp
->_IO_read_ptr
- fp
->_IO_read_base
);
697 if (ignore (to_skip
) != to_skip
)
699 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
705 if (rel_offset
< 0 && rel_offset
>= Bbase () - Bptr ())
707 if (!_IO_in_backup (fp
))
708 _IO_switch_to_backup_area (fp
);
709 gbump (fp
->_IO_read_end
+ rel_offset
- fp
->_IO_read_ptr
);
710 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
717 INTUSE(_IO_unsave_markers
) (fp
);
720 if (fp
->_flags
& _IO_NO_READS
)
723 /* Try to seek to a block boundary, to improve kernel page management. */
724 new_offset
= offset
& ~(fp
->_IO_buf_end
- fp
->_IO_buf_base
- 1);
725 delta
= offset
- new_offset
;
726 if (delta
> fp
->_IO_buf_end
- fp
->_IO_buf_base
)
731 result
= _IO_SYSSEEK (fp
, new_offset
, 0);
738 count
= _IO_SYSREAD (fp
, fp
->_IO_buf_base
,
740 ? delta
: fp
->_IO_buf_end
- fp
->_IO_buf_base
));
743 /* We weren't allowed to read, but try to seek the remainder. */
744 offset
= count
== EOF
? delta
: delta
-count
;
749 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
+ delta
,
750 fp
->_IO_buf_base
+ count
);
751 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
752 fp
->_offset
= result
+ count
;
753 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
757 INTUSE(_IO_unsave_markers
) (fp
);
758 result
= _IO_SYSSEEK (fp
, offset
, dir
);
761 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
762 fp
->_offset
= result
;
763 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
764 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
765 _IO_wsetg (fp
, fp
->_wide_data
->_IO_buf_base
,
766 fp
->_wide_data
->_IO_buf_base
, fp
->_wide_data
->_IO_buf_base
);
767 _IO_wsetp (fp
, fp
->_wide_data
->_IO_buf_base
,
768 fp
->_wide_data
->_IO_buf_base
);
773 /* We need to do it since it is possible that the file offset in
774 the kernel may be changed behind our back. It may happen when
775 we fopen a file and then do a fork. One process may access the
776 the file and the kernel file offset will be changed. */
777 if (fp
->_offset
>= 0)
778 _IO_SYSSEEK (fp
, fp
->_offset
, 0);
782 INTDEF(_IO_wfile_seekoff
)
786 _IO_wfile_xsputn (f
, data
, n
)
791 register const wchar_t *s
= (const wchar_t *) data
;
792 _IO_size_t to_do
= n
;
798 /* This is an optimized implementation.
799 If the amount to be written straddles a block boundary
800 (or the filebuf is unbuffered), use sys_write directly. */
802 /* First figure out how much space is available in the buffer. */
803 count
= f
->_wide_data
->_IO_write_end
- f
->_wide_data
->_IO_write_ptr
;
804 if ((f
->_flags
& _IO_LINE_BUF
) && (f
->_flags
& _IO_CURRENTLY_PUTTING
))
806 count
= f
->_wide_data
->_IO_buf_end
- f
->_wide_data
->_IO_write_ptr
;
809 register const wchar_t *p
;
810 for (p
= s
+ n
; p
> s
; )
821 /* Then fill the buffer. */
829 f
->_wide_data
->_IO_write_ptr
=
830 __wmempcpy (f
->_wide_data
->_IO_write_ptr
, s
, count
);
832 wmemcpy (f
->_wide_data
->_IO_write_ptr
, s
, count
);
833 f
->_wide_data
->_IO_write_ptr
+= count
;
839 register wchar_t *p
= f
->_wide_data
->_IO_write_ptr
;
840 register int i
= (int) count
;
843 f
->_wide_data
->_IO_write_ptr
= p
;
848 to_do
-= INTUSE(_IO_wdefault_xsputn
) (f
, s
, to_do
);
850 && f
->_wide_data
->_IO_write_ptr
!= f
->_wide_data
->_IO_write_base
)
851 INTUSE(_IO_wdo_write
) (f
, f
->_wide_data
->_IO_write_base
,
852 f
->_wide_data
->_IO_write_ptr
853 - f
->_wide_data
->_IO_write_base
);
857 INTDEF(_IO_wfile_xsputn
)
860 struct _IO_jump_t _IO_wfile_jumps
=
863 JUMP_INIT(finish
, _IO_new_file_finish
),
864 JUMP_INIT(overflow
, (_IO_overflow_t
) INTUSE(_IO_wfile_overflow
)),
865 JUMP_INIT(underflow
, (_IO_underflow_t
) INTUSE(_IO_wfile_underflow
)),
866 JUMP_INIT(uflow
, (_IO_underflow_t
) INTUSE(_IO_wdefault_uflow
)),
867 JUMP_INIT(pbackfail
, (_IO_pbackfail_t
) INTUSE(_IO_wdefault_pbackfail
)),
868 JUMP_INIT(xsputn
, INTUSE(_IO_wfile_xsputn
)),
869 JUMP_INIT(xsgetn
, INTUSE(_IO_file_xsgetn
)),
870 JUMP_INIT(seekoff
, INTUSE(_IO_wfile_seekoff
)),
871 JUMP_INIT(seekpos
, _IO_default_seekpos
),
872 JUMP_INIT(setbuf
, _IO_new_file_setbuf
),
873 JUMP_INIT(sync
, (_IO_sync_t
) INTUSE(_IO_wfile_sync
)),
874 JUMP_INIT(doallocate
, _IO_wfile_doallocate
),
875 JUMP_INIT(read
, INTUSE(_IO_file_read
)),
876 JUMP_INIT(write
, _IO_new_file_write
),
877 JUMP_INIT(seek
, INTUSE(_IO_file_seek
)),
878 JUMP_INIT(close
, INTUSE(_IO_file_close
)),
879 JUMP_INIT(stat
, INTUSE(_IO_file_stat
)),
880 JUMP_INIT(showmanyc
, _IO_default_showmanyc
),
881 JUMP_INIT(imbue
, _IO_default_imbue
)
883 INTVARDEF(_IO_wfile_jumps
)
886 struct _IO_jump_t _IO_wfile_jumps_mmap
=
889 JUMP_INIT(finish
, _IO_new_file_finish
),
890 JUMP_INIT(overflow
, (_IO_overflow_t
) INTUSE(_IO_wfile_overflow
)),
891 JUMP_INIT(underflow
, (_IO_underflow_t
) _IO_wfile_underflow_mmap
),
892 JUMP_INIT(uflow
, (_IO_underflow_t
) INTUSE(_IO_wdefault_uflow
)),
893 JUMP_INIT(pbackfail
, (_IO_pbackfail_t
) INTUSE(_IO_wdefault_pbackfail
)),
894 JUMP_INIT(xsputn
, INTUSE(_IO_wfile_xsputn
)),
895 JUMP_INIT(xsgetn
, INTUSE(_IO_file_xsgetn
)),
896 JUMP_INIT(seekoff
, INTUSE(_IO_wfile_seekoff
)),
897 JUMP_INIT(seekpos
, _IO_default_seekpos
),
898 JUMP_INIT(setbuf
, _IO_file_setbuf_mmap
),
899 JUMP_INIT(sync
, (_IO_sync_t
) INTUSE(_IO_wfile_sync
)),
900 JUMP_INIT(doallocate
, _IO_wfile_doallocate
),
901 JUMP_INIT(read
, INTUSE(_IO_file_read
)),
902 JUMP_INIT(write
, _IO_new_file_write
),
903 JUMP_INIT(seek
, INTUSE(_IO_file_seek
)),
904 JUMP_INIT(close
, _IO_file_close_mmap
),
905 JUMP_INIT(stat
, INTUSE(_IO_file_stat
)),
906 JUMP_INIT(showmanyc
, _IO_default_showmanyc
),
907 JUMP_INIT(imbue
, _IO_default_imbue
)
910 struct _IO_jump_t _IO_wfile_jumps_maybe_mmap
=
913 JUMP_INIT(finish
, _IO_new_file_finish
),
914 JUMP_INIT(overflow
, (_IO_overflow_t
) INTUSE(_IO_wfile_overflow
)),
915 JUMP_INIT(underflow
, (_IO_underflow_t
) _IO_wfile_underflow_maybe_mmap
),
916 JUMP_INIT(uflow
, (_IO_underflow_t
) INTUSE(_IO_wdefault_uflow
)),
917 JUMP_INIT(pbackfail
, (_IO_pbackfail_t
) INTUSE(_IO_wdefault_pbackfail
)),
918 JUMP_INIT(xsputn
, INTUSE(_IO_wfile_xsputn
)),
919 JUMP_INIT(xsgetn
, INTUSE(_IO_file_xsgetn
)),
920 JUMP_INIT(seekoff
, INTUSE(_IO_wfile_seekoff
)),
921 JUMP_INIT(seekpos
, _IO_default_seekpos
),
922 JUMP_INIT(setbuf
, _IO_file_setbuf_mmap
),
923 JUMP_INIT(sync
, (_IO_sync_t
) INTUSE(_IO_wfile_sync
)),
924 JUMP_INIT(doallocate
, _IO_wfile_doallocate
),
925 JUMP_INIT(read
, INTUSE(_IO_file_read
)),
926 JUMP_INIT(write
, _IO_new_file_write
),
927 JUMP_INIT(seek
, INTUSE(_IO_file_seek
)),
928 JUMP_INIT(close
, INTUSE(_IO_file_close
)),
929 JUMP_INIT(stat
, INTUSE(_IO_file_stat
)),
930 JUMP_INIT(showmanyc
, _IO_default_showmanyc
),
931 JUMP_INIT(imbue
, _IO_default_imbue
)