1 /* Copyright (C) 1993, 1995, 1997-2002, 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Written by Per Bothner <bothner@cygnus.com>.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 As a special exception, if you link the code in this file with
21 files compiled with a GNU compiler to produce an executable,
22 that does not cause the resulting executable to be covered by
23 the GNU Lesser General Public License. This exception does not
24 however invalidate any other reasons why the executable file
25 might be covered by the GNU Lesser General Public License.
26 This exception applies to code released by its copyright holders
27 in files containing the exception. */
31 # define _POSIX_SOURCE
36 #include <sys/param.h>
37 #include <sys/types.h>
47 /*# define open(Name, Flags, Prot) __open (Name, Flags, Prot)
48 # define close(FD) __close (FD)
49 # define lseek(FD, Offset, Whence) __lseek (FD, Offset, Whence)
50 # define read(FD, Buf, NBytes) __read (FD, Buf, NBytes)
51 # define write(FD, Buf, NBytes) __write (FD, Buf, NBytes)*/
52 # define _IO_do_write _IO_new_do_write /* For macro uses. */
54 # define _IO_new_do_write _IO_do_write
55 # define _IO_new_file_attach _IO_file_attach
56 # define _IO_new_file_close_it _IO_file_close_it
57 # define _IO_new_file_finish _IO_file_finish
58 # define _IO_new_file_fopen _IO_file_fopen
59 # define _IO_new_file_init _IO_file_init
60 # define _IO_new_file_setbuf _IO_file_setbuf
61 # define _IO_new_file_sync _IO_file_sync
62 # define _IO_new_file_overflow _IO_file_overflow
63 # define _IO_new_file_seekoff _IO_file_seekoff
64 # define _IO_new_file_underflow _IO_file_underflow
65 # define _IO_new_file_write _IO_file_write
66 # define _IO_new_file_xsputn _IO_file_xsputn
71 extern struct __gconv_trans_data __libio_translit attribute_hidden
;
75 /* An fstream can be in at most one of put mode, get mode, or putback mode.
76 Putback mode is a variant of get mode.
78 In a filebuf, there is only one current position, instead of two
79 separate get and put pointers. In get mode, the current position
80 is that of gptr(); in put mode that of pptr().
82 The position in the buffer that corresponds to the position
83 in external file system is normally _IO_read_end, except in putback
84 mode, when it is _IO_save_end.
85 If the field _fb._offset is >= 0, it gives the offset in
86 the file as a whole corresponding to eGptr(). (?)
89 If a filebuf is in put mode, then all of _IO_read_ptr, _IO_read_end,
90 and _IO_read_base are equal to each other. These are usually equal
91 to _IO_buf_base, though not necessarily if we have switched from
92 get mode to put mode. (The reason is to maintain the invariant
93 that _IO_read_end corresponds to the external file position.)
94 _IO_write_base is non-NULL and usually equal to _IO_base_base.
95 We also have _IO_write_end == _IO_buf_end, but only in fully buffered mode.
96 The un-flushed character are those between _IO_write_base and _IO_write_ptr.
99 If a filebuf is in get or putback mode, eback() != egptr().
100 In get mode, the unread characters are between gptr() and egptr().
101 The OS file position corresponds to that of egptr().
104 Putback mode is used to remember "excess" characters that have
105 been sputbackc'd in a separate putback buffer.
106 In putback mode, the get buffer points to the special putback buffer.
107 The unread characters are the characters between gptr() and egptr()
108 in the putback buffer, as well as the area between save_gptr()
109 and save_egptr(), which point into the original reserve buffer.
110 (The pointers save_gptr() and save_egptr() are the values
111 of gptr() and egptr() at the time putback mode was entered.)
112 The OS position corresponds to that of save_egptr().
114 LINE BUFFERED OUTPUT:
115 During line buffered output, _IO_write_base==base() && epptr()==base().
116 However, ptr() may be anywhere between base() and ebuf().
117 This forces a call to filebuf::overflow(int C) on every put.
118 If there is more space in the buffer, and C is not a '\n',
119 then C is inserted, and pptr() incremented.
122 If a filebuf is unbuffered(), the _shortbuf[1] is used as the buffer.
125 #define CLOSED_FILEBUF_FLAGS \
126 (_IO_IS_FILEBUF+_IO_NO_READS+_IO_NO_WRITES+_IO_TIED_PUT_GET)
130 _IO_new_file_init (fp
)
131 struct _IO_FILE_plus
*fp
;
133 /* POSIX.1 allows another file handle to be used to change the position
134 of our file descriptor. Hence we actually don't know the actual
135 position before we do the first fseek (and until a following fflush). */
136 fp
->file
._offset
= _IO_pos_BAD
;
137 fp
->file
._IO_file_flags
|= CLOSED_FILEBUF_FLAGS
;
139 INTUSE(_IO_link_in
) (fp
);
140 fp
->file
._fileno
= -1;
142 INTDEF2(_IO_new_file_init
, _IO_file_init
)
145 _IO_new_file_close_it (fp
)
148 int write_status
, close_status
;
149 if (!_IO_file_is_open (fp
))
152 if ((fp
->_flags
& _IO_NO_WRITES
) == 0
153 && (fp
->_flags
& _IO_CURRENTLY_PUTTING
) != 0)
154 write_status
= _IO_do_flush (fp
);
158 INTUSE(_IO_unsave_markers
) (fp
);
160 close_status
= _IO_SYSCLOSE (fp
);
165 INTUSE(_IO_setb
) (fp
, NULL
, NULL
, 0);
166 _IO_setg (fp
, NULL
, NULL
, NULL
);
167 _IO_setp (fp
, NULL
, NULL
);
169 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
172 if (_IO_have_wbackup (fp
))
173 INTUSE(_IO_free_wbackup_area
) (fp
);
174 INTUSE(_IO_wsetb
) (fp
, NULL
, NULL
, 0);
175 _IO_wsetg (fp
, NULL
, NULL
, NULL
);
176 _IO_wsetp (fp
, NULL
, NULL
);
180 INTUSE(_IO_un_link
) ((struct _IO_FILE_plus
*) fp
);
181 fp
->_flags
= _IO_MAGIC
|CLOSED_FILEBUF_FLAGS
;
183 fp
->_offset
= _IO_pos_BAD
;
185 return close_status
? close_status
: write_status
;
187 INTDEF2(_IO_new_file_close_it
, _IO_file_close_it
)
190 _IO_new_file_finish (fp
, dummy
)
194 if (_IO_file_is_open (fp
))
197 if (!(fp
->_flags
& _IO_DELETE_DONT_CLOSE
))
200 INTUSE(_IO_default_finish
) (fp
, 0);
202 INTDEF2(_IO_new_file_finish
, _IO_file_finish
)
204 #if defined __GNUC__ && __GNUC__ >= 2
208 _IO_file_open (fp
, filename
, posix_mode
, prot
, read_write
, is32not64
)
210 const char *filename
;
219 ? open (filename
, posix_mode
, prot
)
220 : _G_OPEN64 (filename
, posix_mode
, prot
));
222 fdesc
= open (filename
, posix_mode
, prot
);
227 _IO_mask_flags (fp
, read_write
,_IO_NO_READS
+_IO_NO_WRITES
+_IO_IS_APPENDING
);
228 if ((read_write
& _IO_IS_APPENDING
) && (read_write
& _IO_NO_READS
))
229 if (_IO_SEEKOFF (fp
, (_IO_off64_t
)0, _IO_seek_end
, _IOS_INPUT
|_IOS_OUTPUT
)
230 == _IO_pos_BAD
&& errno
!= ESPIPE
)
235 INTUSE(_IO_link_in
) ((struct _IO_FILE_plus
*) fp
);
238 libc_hidden_def (_IO_file_open
)
242 _IO_new_file_fopen(_IO_FILE
*fp
, const char *filename
, const char *mode
, int is32not64
)
244 int oflags
= 0, omode
;
251 const char *last_recognized
;
254 if (_IO_file_is_open (fp
))
260 read_write
= _IO_NO_WRITES
;
264 oflags
= O_CREAT
|O_TRUNC
;
265 read_write
= _IO_NO_READS
;
269 oflags
= O_CREAT
|O_APPEND
;
270 read_write
= _IO_NO_READS
|_IO_IS_APPENDING
;
273 __set_errno (EINVAL
);
277 last_recognized
= mode
;
279 for (i
= 1; i
< 5; ++i
)
287 read_write
&= _IO_IS_APPENDING
;
289 last_recognized
= mode
;
295 last_recognized
= mode
;
300 last_recognized
= mode
;
304 fp
->_flags2
|= _IO_FLAGS2_MMAP
;
313 result
= _IO_file_open (fp
, filename
, omode
|oflags
, oprot
, read_write
,
320 /* Test whether the mode string specifies the conversion. */
321 cs
= strstr (last_recognized
+ 1, ",ccs=");
324 /* Yep. Load the appropriate conversions and set the orientation
326 struct gconv_fcts fcts
;
327 struct _IO_codecvt
*cc
;
328 char *endp
= __strchrnul (cs
+ 5, ',');
329 char ccs
[endp
- (cs
+ 5) + 3];
331 *((char *) __mempcpy (ccs
, cs
+ 5, endp
- (cs
+ 5))) = '\0';
334 if (__wcsmbs_named_conv (&fcts
, ccs
[2] == '\0'
335 ? upstr (ccs
, cs
+ 5) : ccs
) != 0)
337 /* Something went wrong, we cannot load the conversion modules.
338 This means we cannot proceed since the user explicitly asked
340 (void) INTUSE(_IO_file_close_it
) (fp
);
341 __set_errno (EINVAL
);
345 assert (fcts
.towc_nsteps
== 1);
346 assert (fcts
.tomb_nsteps
== 1);
348 fp
->_wide_data
->_IO_read_ptr
= fp
->_wide_data
->_IO_read_end
;
349 fp
->_wide_data
->_IO_write_ptr
= fp
->_wide_data
->_IO_write_base
;
351 /* Clear the state. We start all over again. */
352 memset (&fp
->_wide_data
->_IO_state
, '\0', sizeof (__mbstate_t
));
353 memset (&fp
->_wide_data
->_IO_last_state
, '\0', sizeof (__mbstate_t
));
355 cc
= fp
->_codecvt
= &fp
->_wide_data
->_codecvt
;
357 /* The functions are always the same. */
358 *cc
= __libio_codecvt
;
360 cc
->__cd_in
.__cd
.__nsteps
= fcts
.towc_nsteps
;
361 cc
->__cd_in
.__cd
.__steps
= fcts
.towc
;
363 cc
->__cd_in
.__cd
.__data
[0].__invocation_counter
= 0;
364 cc
->__cd_in
.__cd
.__data
[0].__internal_use
= 1;
365 cc
->__cd_in
.__cd
.__data
[0].__flags
= __GCONV_IS_LAST
;
366 cc
->__cd_in
.__cd
.__data
[0].__statep
= &result
->_wide_data
->_IO_state
;
368 /* XXX For now no transliteration. */
369 cc
->__cd_in
.__cd
.__data
[0].__trans
= NULL
;
371 cc
->__cd_out
.__cd
.__nsteps
= fcts
.tomb_nsteps
;
372 cc
->__cd_out
.__cd
.__steps
= fcts
.tomb
;
374 cc
->__cd_out
.__cd
.__data
[0].__invocation_counter
= 0;
375 cc
->__cd_out
.__cd
.__data
[0].__internal_use
= 1;
376 cc
->__cd_out
.__cd
.__data
[0].__flags
= __GCONV_IS_LAST
;
377 cc
->__cd_out
.__cd
.__data
[0].__statep
=
378 &result
->_wide_data
->_IO_state
;
380 /* And now the transliteration. */
381 cc
->__cd_out
.__cd
.__data
[0].__trans
= &__libio_translit
;
383 /* Set the mode now. */
386 /* We don't need the step data structure anymore. */
387 __gconv_release_cache (fcts
.towc
, fcts
.towc_nsteps
);
388 __gconv_release_cache (fcts
.tomb
, fcts
.tomb_nsteps
);
391 #endif /* GNU libc */
396 INTDEF2(_IO_new_file_fopen
, _IO_file_fopen
)
399 _IO_new_file_attach (fp
, fd
)
403 if (_IO_file_is_open (fp
))
406 fp
->_flags
&= ~(_IO_NO_READS
+_IO_NO_WRITES
);
407 fp
->_flags
|= _IO_DELETE_DONT_CLOSE
;
408 /* Get the current position of the file. */
409 /* We have to do that since that may be junk. */
410 fp
->_offset
= _IO_pos_BAD
;
411 if (_IO_SEEKOFF (fp
, (_IO_off64_t
)0, _IO_seek_cur
, _IOS_INPUT
|_IOS_OUTPUT
)
412 == _IO_pos_BAD
&& errno
!= ESPIPE
)
416 INTDEF2(_IO_new_file_attach
, _IO_file_attach
)
419 _IO_new_file_setbuf (fp
, p
, len
)
424 if (_IO_default_setbuf (fp
, p
, len
) == NULL
)
427 fp
->_IO_write_base
= fp
->_IO_write_ptr
= fp
->_IO_write_end
429 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
433 INTDEF2(_IO_new_file_setbuf
, _IO_file_setbuf
)
437 _IO_file_setbuf_mmap(_IO_FILE
*fp
, char *p
, _IO_ssize_t len
)
441 /* Change the function table. */
442 _IO_JUMPS((struct _IO_FILE_plus
*)fp
) = &INTUSE(_IO_file_jumps
);
443 fp
->_wide_data
->_wide_vtable
= &_IO_wfile_jumps
;
445 /* And perform the normal operation. */
446 result
= _IO_new_file_setbuf(fp
, p
, len
);
449 /* If the call failed, restore to using mmap. */
450 if (result
== NULL
) {
451 _IO_JUMPS((struct _IO_FILE_plus
*)fp
) = &_IO_file_jumps_mmap
;
452 fp
->_wide_data
->_wide_vtable
= &_IO_wfile_jumps_mmap
;
459 static int new_do_write
__P ((_IO_FILE
*, const char *, _IO_size_t
));
461 /* Write TO_DO bytes from DATA to FP.
462 Then mark FP as having empty buffers. */
465 _IO_new_do_write (fp
, data
, to_do
)
471 || (_IO_size_t
) new_do_write (fp
, data
, to_do
) == to_do
) ? 0 : EOF
;
473 INTDEF2(_IO_new_do_write
, _IO_do_write
)
477 new_do_write (fp
, data
, to_do
)
483 if (fp
->_flags
& _IO_IS_APPENDING
)
484 /* On a system without a proper O_APPEND implementation,
485 you would need to sys_seek(0, SEEK_END) here, but is
486 is not needed nor desirable for Unix- or Posix-like systems.
487 Instead, just indicate that offset (before and after) is
489 fp
->_offset
= _IO_pos_BAD
;
490 else if (fp
->_IO_read_end
!= fp
->_IO_write_base
)
493 = _IO_SYSSEEK (fp
, fp
->_IO_write_base
- fp
->_IO_read_end
, 1);
494 if (new_pos
== _IO_pos_BAD
)
496 fp
->_offset
= new_pos
;
498 count
= _IO_SYSWRITE (fp
, data
, to_do
);
499 if (fp
->_cur_column
&& count
)
500 fp
->_cur_column
= INTUSE(_IO_adjust_column
) (fp
->_cur_column
- 1, data
,
502 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
503 fp
->_IO_write_base
= fp
->_IO_write_ptr
= fp
->_IO_buf_base
;
504 fp
->_IO_write_end
= (fp
->_mode
<= 0
505 && (fp
->_flags
& (_IO_LINE_BUF
+_IO_UNBUFFERED
))
506 ? fp
->_IO_buf_base
: fp
->_IO_buf_end
);
511 _IO_new_file_underflow (fp
)
516 /* SysV does not make this test; take it out for compatibility */
517 if (fp
->_flags
& _IO_EOF_SEEN
)
521 if (fp
->_flags
& _IO_NO_READS
)
523 fp
->_flags
|= _IO_ERR_SEEN
;
527 if (fp
->_IO_read_ptr
< fp
->_IO_read_end
)
528 return *(unsigned char *) fp
->_IO_read_ptr
;
530 if (fp
->_IO_buf_base
== NULL
)
532 /* Maybe we already have a push back pointer. */
533 if (fp
->_IO_save_base
!= NULL
)
535 free (fp
->_IO_save_base
);
536 fp
->_flags
&= ~_IO_IN_BACKUP
;
538 INTUSE(_IO_doallocbuf
) (fp
);
541 /* Flush all line buffered files before reading. */
542 /* FIXME This can/should be moved to genops ?? */
543 if (fp
->_flags
& (_IO_LINE_BUF
|_IO_UNBUFFERED
))
546 INTUSE(_IO_flush_all_linebuffered
) ();
548 /* We used to flush all line-buffered stream. This really isn't
549 required by any standard. My recollection is that
550 traditional Unix systems did this for stdout. stderr better
551 not be line buffered. So we do just that here
552 explicitly. --drepper */
553 _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile
,
555 _IO_flockfile (_IO_stdout
);
557 if ((_IO_stdout
->_flags
& (_IO_LINKED
| _IO_NO_WRITES
| _IO_LINE_BUF
))
558 == (_IO_LINKED
| _IO_LINE_BUF
))
559 _IO_OVERFLOW (_IO_stdout
, EOF
);
561 _IO_funlockfile (_IO_stdout
);
562 _IO_cleanup_region_end (0);
566 INTUSE(_IO_switch_to_get_mode
) (fp
);
568 /* This is very tricky. We have to adjust those
569 pointers before we call _IO_SYSREAD () since
570 we may longjump () out while waiting for
571 input. Those pointers may be screwed up. H.J. */
572 fp
->_IO_read_base
= fp
->_IO_read_ptr
= fp
->_IO_buf_base
;
573 fp
->_IO_read_end
= fp
->_IO_buf_base
;
574 fp
->_IO_write_base
= fp
->_IO_write_ptr
= fp
->_IO_write_end
577 count
= _IO_SYSREAD (fp
, fp
->_IO_buf_base
,
578 fp
->_IO_buf_end
- fp
->_IO_buf_base
);
582 fp
->_flags
|= _IO_EOF_SEEN
;
584 fp
->_flags
|= _IO_ERR_SEEN
, count
= 0;
586 fp
->_IO_read_end
+= count
;
589 if (fp
->_offset
!= _IO_pos_BAD
)
590 _IO_pos_adjust (fp
->_offset
, count
);
591 return *(unsigned char *) fp
->_IO_read_ptr
;
593 INTDEF2(_IO_new_file_underflow
, _IO_file_underflow
)
596 /* Guts of underflow callback if we mmap the file. This stats the file and
597 updates the stream state to match. In the normal case we return zero.
598 If the file is no longer eligible for mmap, its jump tables are reset to
599 the vanilla ones and we return nonzero. */
601 mmap_remap_check (_IO_FILE
*fp
)
605 if (_IO_SYSSTAT (fp
, &st
) == 0
606 && S_ISREG (st
.st_mode
) && st
.st_size
!= 0
607 /* Limit the file size to 1MB for 32-bit machines. */
608 && (sizeof (ptrdiff_t) > 4 || st
.st_size
< 1*1024*1024))
610 const size_t pagesize
= __getpagesize ();
611 # define ROUNDED(x) (((x) + pagesize - 1) & ~(pagesize - 1))
612 if (ROUNDED (st
.st_size
) < ROUNDED (fp
->_IO_buf_end
615 /* We can trim off some pages past the end of the file. */
616 (void) __munmap (fp
->_IO_buf_base
+ ROUNDED (st
.st_size
),
617 ROUNDED (fp
->_IO_buf_end
- fp
->_IO_buf_base
)
618 - ROUNDED (st
.st_size
));
619 fp
->_IO_buf_end
= fp
->_IO_buf_base
+ st
.st_size
;
621 else if (ROUNDED (st
.st_size
) > ROUNDED (fp
->_IO_buf_end
624 /* The file added some pages. We need to remap it. */
626 #if defined __linux__ /* XXX */
627 p
= __mremap (fp
->_IO_buf_base
, ROUNDED (fp
->_IO_buf_end
629 ROUNDED (st
.st_size
), MREMAP_MAYMOVE
);
632 (void) __munmap (fp
->_IO_buf_base
,
633 fp
->_IO_buf_end
- fp
->_IO_buf_base
);
637 (void) __munmap (fp
->_IO_buf_base
,
638 fp
->_IO_buf_end
- fp
->_IO_buf_base
);
640 p
= _G_MMAP64 (NULL
, st
.st_size
, PROT_READ
, MAP_SHARED
,
643 p
= __mmap (NULL
, st
.st_size
, PROT_READ
, MAP_SHARED
,
649 fp
->_IO_buf_base
= p
;
650 fp
->_IO_buf_end
= fp
->_IO_buf_base
+ st
.st_size
;
654 /* The number of pages didn't change. */
655 fp
->_IO_buf_end
= fp
->_IO_buf_base
+ st
.st_size
;
659 fp
->_offset
-= fp
->_IO_read_end
- fp
->_IO_read_ptr
;
660 _IO_setg (fp
, fp
->_IO_buf_base
,
661 fp
->_offset
< fp
->_IO_buf_end
- fp
->_IO_buf_base
662 ? fp
->_IO_buf_base
+ fp
->_offset
: fp
->_IO_buf_end
,
665 /* If we are already positioned at or past the end of the file, don't
666 change the current offset. If not, seek past what we have mapped,
667 mimicking the position left by a normal underflow reading into its
670 if (fp
->_offset
< fp
->_IO_buf_end
- fp
->_IO_buf_base
)
678 (fp
->_fileno
, fp
->_IO_buf_end
- fp
->_IO_buf_base
, SEEK_SET
)
679 != fp
->_IO_buf_end
- fp
->_IO_buf_base
)
680 fp
->_flags
|= _IO_ERR_SEEN
;
682 fp
->_offset
= fp
->_IO_buf_end
- fp
->_IO_buf_base
;
689 /* Life is no longer good for mmap. Punt it. */
690 __munmap (fp
->_IO_buf_base
, fp
->_IO_buf_end
- fp
->_IO_buf_base
);
693 fp
->_IO_buf_base
= fp
->_IO_buf_end
= NULL
;
694 _IO_setg (fp
, NULL
, NULL
, NULL
);
697 _IO_JUMPS((struct _IO_FILE_plus
*)fp
) = &INTUSE(_IO_file_jumps
);
699 _IO_JUMPS((struct _IO_FILE_plus
*)fp
) = &_IO_wfile_jumps
;
701 fp
->_wide_data
->_wide_vtable
= &_IO_wfile_jumps
;
708 /* Special callback replacing the underflow callbacks if we mmap the file. */
710 _IO_file_underflow_mmap (_IO_FILE
*fp
)
712 if (fp
->_IO_read_ptr
< fp
->_IO_read_end
)
713 return *(unsigned char *) fp
->_IO_read_ptr
;
715 if (__builtin_expect (mmap_remap_check (fp
), 0))
716 /* We punted to the regular file functions. */
717 return _IO_UNDERFLOW (fp
);
719 if (fp
->_IO_read_ptr
< fp
->_IO_read_end
)
720 return *(unsigned char *) fp
->_IO_read_ptr
;
722 fp
->_flags
|= _IO_EOF_SEEN
;
728 decide_maybe_mmap(_IO_FILE
*fp
)
730 /* We use the file in read-only mode. This could mean we can
731 * mmap the file and use it without any copying. But not all
732 * file descriptors are for mmap-able objects and on 32-bit
733 * machines we don't want to map files which are too large since
734 * this would require too much virtual memory.
738 if (_IO_SYSSTAT(fp
, &st
) == 0
739 && S_ISREG (st
.st_mode
) && st
.st_size
!= 0
740 /* Limit the file size to 1MB for 32-bit machines. */
741 && (sizeof(ptrdiff_t) > 4 || st
.st_size
< 1*1024*1024)
743 && (fp
->_offset
== _IO_pos_BAD
|| fp
->_offset
<= st
.st_size
))
745 /* Try to map the file. */
749 p
= _G_MMAP64(NULL
, st
.st_size
, PROT_READ
, MAP_SHARED
, fp
->_fileno
, 0);
751 p
= __mmap(NULL
, st
.st_size
, PROT_READ
, MAP_SHARED
, fp
->_fileno
, 0);
754 if (p
!= MAP_FAILED
) {
755 /* OK, we managed to map the file. Set the buffer up and use a
756 * special jump table with simplified underflow functions which
757 * never tries to read anything from the file.
766 (fp
->_fileno
, st
.st_size
, SEEK_SET
) != st
.st_size
) {
767 (void) __munmap (p
, st
.st_size
);
768 fp
->_offset
= _IO_pos_BAD
;
770 INTUSE(_IO_setb
) (fp
, p
, (char *) p
+ st
.st_size
, 0);
772 if (fp
->_offset
== _IO_pos_BAD
)
775 _IO_setg (fp
, p
, p
+ fp
->_offset
, p
+ st
.st_size
);
776 fp
->_offset
= st
.st_size
;
779 _IO_JUMPS((struct _IO_FILE_plus
*)fp
) = &_IO_file_jumps_mmap
;
781 _IO_JUMPS((struct _IO_FILE_plus
*)fp
) = &_IO_wfile_jumps_mmap
;
783 fp
->_wide_data
->_wide_vtable
= &_IO_wfile_jumps_mmap
;
790 /* We couldn't use mmap, so revert to the vanilla file operations. */
793 _IO_JUMPS((struct _IO_FILE_plus
*)fp
) = &INTUSE(_IO_file_jumps
);
795 _IO_JUMPS((struct _IO_FILE_plus
*)fp
) = &_IO_wfile_jumps
;
797 fp
->_wide_data
->_wide_vtable
= &_IO_wfile_jumps
;
802 _IO_file_underflow_maybe_mmap (_IO_FILE
*fp
)
804 /* This is the first read attempt. Choose mmap or vanilla operations
805 and then punt to the chosen underflow routine. */
806 decide_maybe_mmap (fp
);
807 return _IO_UNDERFLOW (fp
);
809 #endif /* HAVE_MMAP */
813 _IO_new_file_overflow (f
, ch
)
817 if (f
->_flags
& _IO_NO_WRITES
) /* SET ERROR */
819 f
->_flags
|= _IO_ERR_SEEN
;
823 /* If currently reading or no buffer allocated. */
824 if ((f
->_flags
& _IO_CURRENTLY_PUTTING
) == 0 || f
->_IO_write_base
== 0)
826 /* Allocate a buffer if needed. */
827 if (f
->_IO_write_base
== 0)
829 INTUSE(_IO_doallocbuf
) (f
);
830 _IO_setg (f
, f
->_IO_buf_base
, f
->_IO_buf_base
, f
->_IO_buf_base
);
832 /* Otherwise must be currently reading.
833 If _IO_read_ptr (and hence also _IO_read_end) is at the buffer end,
834 logically slide the buffer forwards one block (by setting the
835 read pointers to all point at the beginning of the block). This
836 makes room for subsequent output.
837 Otherwise, set the read pointers to _IO_read_end (leaving that
838 alone, so it can continue to correspond to the external position). */
839 if (f
->_IO_read_ptr
== f
->_IO_buf_end
)
840 f
->_IO_read_end
= f
->_IO_read_ptr
= f
->_IO_buf_base
;
841 f
->_IO_write_ptr
= f
->_IO_read_ptr
;
842 f
->_IO_write_base
= f
->_IO_write_ptr
;
843 f
->_IO_write_end
= f
->_IO_buf_end
;
844 f
->_IO_read_base
= f
->_IO_read_ptr
= f
->_IO_read_end
;
846 f
->_flags
|= _IO_CURRENTLY_PUTTING
;
847 if (f
->_mode
<= 0 && f
->_flags
& (_IO_LINE_BUF
+_IO_UNBUFFERED
))
848 f
->_IO_write_end
= f
->_IO_write_ptr
;
851 return INTUSE(_IO_do_write
) (f
, f
->_IO_write_base
,
852 f
->_IO_write_ptr
- f
->_IO_write_base
);
853 if (f
->_IO_write_ptr
== f
->_IO_buf_end
) /* Buffer is really full */
854 if (_IO_do_flush (f
) == EOF
)
856 *f
->_IO_write_ptr
++ = ch
;
857 if ((f
->_flags
& _IO_UNBUFFERED
)
858 || ((f
->_flags
& _IO_LINE_BUF
) && ch
== '\n'))
859 if (INTUSE(_IO_do_write
) (f
, f
->_IO_write_base
,
860 f
->_IO_write_ptr
- f
->_IO_write_base
) == EOF
)
862 return (unsigned char) ch
;
864 INTDEF2(_IO_new_file_overflow
, _IO_file_overflow
)
867 _IO_new_file_sync (fp
)
873 /* char* ptr = cur_ptr(); */
874 if (fp
->_IO_write_ptr
> fp
->_IO_write_base
)
875 if (_IO_do_flush(fp
)) return EOF
;
876 delta
= fp
->_IO_read_ptr
- fp
->_IO_read_end
;
880 if (_IO_in_backup (fp
))
881 delta
-= eGptr () - Gbase ();
883 _IO_off64_t new_pos
= _IO_SYSSEEK (fp
, delta
, 1);
884 if (new_pos
!= (_IO_off64_t
) EOF
)
885 fp
->_IO_read_end
= fp
->_IO_read_ptr
;
887 else if (errno
== ESPIPE
)
888 ; /* Ignore error from unseekable devices. */
894 fp
->_offset
= _IO_pos_BAD
;
895 /* FIXME: Cleanup - can this be shared? */
896 /* setg(base(), ptr, ptr); */
899 INTDEF2(_IO_new_file_sync
, _IO_file_sync
)
903 _IO_file_sync_mmap (_IO_FILE
*fp
)
905 if (fp
->_IO_read_ptr
!= fp
->_IO_read_end
)
908 if (_IO_in_backup (fp
))
909 delta
-= eGptr () - Gbase ();
917 (fp
->_fileno
, fp
->_IO_read_ptr
- fp
->_IO_buf_base
, SEEK_SET
)
918 != fp
->_IO_read_ptr
- fp
->_IO_buf_base
)
920 fp
->_flags
|= _IO_ERR_SEEN
;
924 fp
->_offset
= fp
->_IO_read_ptr
- fp
->_IO_buf_base
;
925 fp
->_IO_read_end
= fp
->_IO_read_ptr
= fp
->_IO_read_base
;
928 #endif /* HAVE_MMAP */
932 _IO_new_file_seekoff (fp
, offset
, dir
, mode
)
939 _IO_off64_t delta
, new_offset
;
941 /* POSIX.1 8.2.3.7 says that after a call the fflush() the file
942 offset of the underlying file must be exact. */
943 int must_be_exact
= (fp
->_IO_read_base
== fp
->_IO_read_end
944 && fp
->_IO_write_base
== fp
->_IO_write_ptr
);
947 dir
= _IO_seek_cur
, offset
= 0; /* Don't move any pointers. */
949 /* Flush unwritten characters.
950 (This may do an unneeded write if we seek within the buffer.
951 But to be able to switch to reading, we would need to set
952 egptr to ptr. That can't be done in the current design,
953 which assumes file_ptr() is eGptr. Anyway, since we probably
954 end up flushing when we close(), it doesn't make much difference.)
955 FIXME: simulate mem-papped files. */
957 if (fp
->_IO_write_ptr
> fp
->_IO_write_base
|| _IO_in_put_mode (fp
))
958 if (INTUSE(_IO_switch_to_get_mode
) (fp
))
961 if (fp
->_IO_buf_base
== NULL
)
963 /* It could be that we already have a pushback buffer. */
964 if (fp
->_IO_read_base
!= NULL
)
966 free (fp
->_IO_read_base
);
967 fp
->_flags
&= ~_IO_IN_BACKUP
;
969 INTUSE(_IO_doallocbuf
) (fp
);
970 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
971 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
977 /* Adjust for read-ahead (bytes is buffer). */
978 offset
-= fp
->_IO_read_end
- fp
->_IO_read_ptr
;
979 if (fp
->_offset
== _IO_pos_BAD
)
981 /* Make offset absolute, assuming current pointer is file_ptr(). */
982 offset
+= fp
->_offset
;
985 __set_errno (EINVAL
);
996 if (_IO_SYSSTAT (fp
, &st
) == 0 && S_ISREG (st
.st_mode
))
998 offset
+= st
.st_size
;
1005 /* At this point, dir==_IO_seek_set. */
1007 /* If we are only interested in the current position we've found it now. */
1011 /* If destination is within current buffer, optimize: */
1012 if (fp
->_offset
!= _IO_pos_BAD
&& fp
->_IO_read_base
!= NULL
1013 && !_IO_in_backup (fp
))
1015 /* Offset relative to start of main get area. */
1016 _IO_off64_t rel_offset
= (offset
- fp
->_offset
1017 + (fp
->_IO_read_end
- fp
->_IO_buf_base
));
1018 if (rel_offset
>= 0)
1021 if (_IO_in_backup (fp
))
1022 _IO_switch_to_main_get_area (fp
);
1024 if (rel_offset
<= fp
->_IO_read_end
- fp
->_IO_buf_base
)
1026 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
+ rel_offset
,
1028 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
1030 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
1035 /* If we have streammarkers, seek forward by reading ahead. */
1036 if (_IO_have_markers (fp
))
1038 int to_skip
= rel_offset
1039 - (fp
->_IO_read_ptr
- fp
->_IO_read_base
);
1040 if (ignore (to_skip
) != to_skip
)
1042 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
1048 if (rel_offset
< 0 && rel_offset
>= Bbase () - Bptr ())
1050 if (!_IO_in_backup (fp
))
1051 _IO_switch_to_backup_area (fp
);
1052 gbump (fp
->_IO_read_end
+ rel_offset
- fp
->_IO_read_ptr
);
1053 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
1060 INTUSE(_IO_unsave_markers
) (fp
);
1063 if (fp
->_flags
& _IO_NO_READS
)
1066 /* Try to seek to a block boundary, to improve kernel page management. */
1067 new_offset
= offset
& ~(fp
->_IO_buf_end
- fp
->_IO_buf_base
- 1);
1068 delta
= offset
- new_offset
;
1069 if (delta
> fp
->_IO_buf_end
- fp
->_IO_buf_base
)
1071 new_offset
= offset
;
1074 result
= _IO_SYSSEEK (fp
, new_offset
, 0);
1081 count
= _IO_SYSREAD (fp
, fp
->_IO_buf_base
,
1083 ? delta
: fp
->_IO_buf_end
- fp
->_IO_buf_base
));
1086 /* We weren't allowed to read, but try to seek the remainder. */
1087 offset
= count
== EOF
? delta
: delta
-count
;
1092 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
+ delta
,
1093 fp
->_IO_buf_base
+ count
);
1094 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
1095 fp
->_offset
= result
+ count
;
1096 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
1100 INTUSE(_IO_unsave_markers
) (fp
);
1101 result
= _IO_SYSSEEK (fp
, offset
, dir
);
1104 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
1105 fp
->_offset
= result
;
1106 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
1107 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
1112 /* We need to do it since it is possible that the file offset in
1113 the kernel may be changed behind our back. It may happen when
1114 we fopen a file and then do a fork. One process may access the
1115 the file and the kernel file offset will be changed. */
1116 if (fp
->_offset
>= 0)
1117 _IO_SYSSEEK (fp
, fp
->_offset
, 0);
1121 INTDEF2(_IO_new_file_seekoff
, _IO_file_seekoff
)
1124 _IO_file_seekoff_mmap (fp
, offset
, dir
, mode
)
1132 /* If we are only interested in the current position, calculate it and
1133 return right now. This calculation does the right thing when we are
1134 using a pushback buffer, but in the usual case has the same value as
1135 (fp->_IO_read_ptr - fp->_IO_buf_base). */
1137 return fp
->_offset
- (fp
->_IO_read_end
- fp
->_IO_read_ptr
);
1142 /* Adjust for read-ahead (bytes is buffer). */
1143 offset
+= fp
->_IO_read_ptr
- fp
->_IO_read_base
;
1148 offset
+= fp
->_IO_buf_end
- fp
->_IO_buf_base
;
1151 /* At this point, dir==_IO_seek_set. */
1155 /* No negative offsets are valid. */
1156 __set_errno (EINVAL
);
1160 result
= _IO_SYSSEEK (fp
, offset
, 0);
1164 if (offset
> fp
->_IO_buf_end
- fp
->_IO_buf_base
)
1165 /* One can fseek arbitrarily past the end of the file
1166 and it is meaningless until one attempts to read.
1167 Leave the buffer pointers in EOF state until underflow. */
1168 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_end
, fp
->_IO_buf_end
);
1170 /* Adjust the read pointers to match the file position,
1171 but so the next read attempt will call underflow. */
1172 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
+ offset
,
1173 fp
->_IO_buf_base
+ offset
);
1175 fp
->_offset
= result
;
1177 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
1184 _IO_file_seekoff_maybe_mmap (_IO_FILE
*fp
, _IO_off64_t offset
, int dir
,
1187 /* We only get here when we haven't tried to read anything yet.
1188 So there is nothing more useful for us to do here than just
1189 the underlying lseek call. */
1191 _IO_off64_t result
= _IO_SYSSEEK (fp
, offset
, dir
);
1195 fp
->_offset
= result
;
1198 #endif /* HAVE_MMAP */
1201 _IO_file_read (fp
, buf
, size
)
1206 return read (fp
->_fileno
, buf
, size
);
1208 INTDEF(_IO_file_read
)
1211 _IO_file_seek (fp
, offset
, dir
)
1217 return _G_LSEEK64 (fp
->_fileno
, offset
, dir
);
1219 return lseek (fp
->_fileno
, offset
, dir
);
1222 INTDEF(_IO_file_seek
)
1225 _IO_file_stat (fp
, st
)
1230 return _G_FSTAT64 (fp
->_fileno
, (struct _G_stat64
*) st
);
1232 return fstat (fp
->_fileno
, (struct stat
*) st
);
1235 INTDEF(_IO_file_stat
)
1239 _IO_file_close_mmap (fp
)
1242 /* In addition to closing the file descriptor we have to unmap the file. */
1243 (void) __munmap (fp
->_IO_buf_base
, fp
->_IO_buf_end
- fp
->_IO_buf_base
);
1244 fp
->_IO_buf_base
= fp
->_IO_buf_end
= NULL
;
1245 return close (fp
->_fileno
);
1253 return close (fp
->_fileno
);
1255 INTDEF(_IO_file_close
)
1258 _IO_new_file_write (f
, data
, n
)
1263 _IO_ssize_t to_do
= n
;
1266 _IO_ssize_t count
= write (f
->_fileno
, data
, to_do
);
1269 f
->_flags
|= _IO_ERR_SEEN
;
1273 data
= (void *) ((char *) data
+ count
);
1276 if (f
->_offset
>= 0)
1282 _IO_new_file_xsputn (f
, data
, n
)
1287 register const char *s
= (const char *) data
;
1288 _IO_size_t to_do
= n
;
1294 /* This is an optimized implementation.
1295 If the amount to be written straddles a block boundary
1296 (or the filebuf is unbuffered), use sys_write directly. */
1298 /* First figure out how much space is available in the buffer. */
1299 count
= f
->_IO_write_end
- f
->_IO_write_ptr
; /* Space available. */
1300 if ((f
->_flags
& _IO_LINE_BUF
) && (f
->_flags
& _IO_CURRENTLY_PUTTING
))
1302 count
= f
->_IO_buf_end
- f
->_IO_write_ptr
;
1305 register const char *p
;
1306 for (p
= s
+ n
; p
> s
; )
1317 /* Then fill the buffer. */
1325 f
->_IO_write_ptr
= __mempcpy (f
->_IO_write_ptr
, s
, count
);
1327 memcpy (f
->_IO_write_ptr
, s
, count
);
1328 f
->_IO_write_ptr
+= count
;
1334 register char *p
= f
->_IO_write_ptr
;
1335 register int i
= (int) count
;
1338 f
->_IO_write_ptr
= p
;
1342 if (to_do
+ must_flush
> 0)
1344 _IO_size_t block_size
, do_write
;
1345 /* Next flush the (full) buffer. */
1346 if (_IO_OVERFLOW (f
, EOF
) == EOF
)
1349 /* Try to maintain alignment: write a whole number of blocks.
1350 dont_write is what gets left over. */
1351 block_size
= f
->_IO_buf_end
- f
->_IO_buf_base
;
1352 do_write
= to_do
- (block_size
>= 128 ? to_do
% block_size
: 0);
1356 count
= new_do_write (f
, s
, do_write
);
1358 if (count
< do_write
)
1362 /* Now write out the remainder. Normally, this will fit in the
1363 buffer, but it's somewhat messier for line-buffered files,
1364 so we let _IO_default_xsputn handle the general case. */
1366 to_do
-= INTUSE(_IO_default_xsputn
) (f
, s
+do_write
, to_do
);
1370 INTDEF2(_IO_new_file_xsputn
, _IO_file_xsputn
)
1373 _IO_file_xsgetn (fp
, data
, n
)
1378 register _IO_size_t want
, have
;
1379 register _IO_ssize_t count
;
1380 register char *s
= data
;
1384 if (fp
->_IO_buf_base
== NULL
)
1386 /* Maybe we already have a push back pointer. */
1387 if (fp
->_IO_save_base
!= NULL
)
1389 free (fp
->_IO_save_base
);
1390 fp
->_flags
&= ~_IO_IN_BACKUP
;
1392 INTUSE(_IO_doallocbuf
) (fp
);
1397 have
= fp
->_IO_read_end
- fp
->_IO_read_ptr
;
1400 memcpy (s
, fp
->_IO_read_ptr
, want
);
1401 fp
->_IO_read_ptr
+= want
;
1409 s
= __mempcpy (s
, fp
->_IO_read_ptr
, have
);
1411 memcpy (s
, fp
->_IO_read_ptr
, have
);
1415 fp
->_IO_read_ptr
+= have
;
1418 /* Check for backup and repeat */
1419 if (_IO_in_backup (fp
))
1421 _IO_switch_to_main_get_area (fp
);
1425 /* If we now want less than a buffer, underflow and repeat
1426 the copy. Otherwise, _IO_SYSREAD directly to
1428 if (fp
->_IO_buf_base
1429 && want
< (size_t) (fp
->_IO_buf_end
- fp
->_IO_buf_base
))
1431 if (__underflow (fp
) == EOF
)
1437 /* These must be set before the sysread as we might longjmp out
1438 waiting for input. */
1439 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
1440 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
1442 /* Try to maintain alignment: read a whole number of blocks. */
1444 if (fp
->_IO_buf_base
)
1446 _IO_size_t block_size
= fp
->_IO_buf_end
- fp
->_IO_buf_base
;
1447 if (block_size
>= 128)
1448 count
-= want
% block_size
;
1451 count
= _IO_SYSREAD (fp
, s
, count
);
1455 fp
->_flags
|= _IO_EOF_SEEN
;
1457 fp
->_flags
|= _IO_ERR_SEEN
;
1464 if (fp
->_offset
!= _IO_pos_BAD
)
1465 _IO_pos_adjust (fp
->_offset
, count
);
1471 INTDEF(_IO_file_xsgetn
)
1474 static _IO_size_t _IO_file_xsgetn_mmap
__P ((_IO_FILE
*, void *, _IO_size_t
));
1476 _IO_file_xsgetn_mmap (fp
, data
, n
)
1481 register _IO_size_t have
;
1482 char *read_ptr
= fp
->_IO_read_ptr
;
1483 register char *s
= (char *) data
;
1485 have
= fp
->_IO_read_end
- fp
->_IO_read_ptr
;
1489 if (__builtin_expect (_IO_in_backup (fp
), 0))
1492 s
= __mempcpy (s
, read_ptr
, have
);
1494 memcpy (s
, read_ptr
, have
);
1498 _IO_switch_to_main_get_area (fp
);
1499 read_ptr
= fp
->_IO_read_ptr
;
1500 have
= fp
->_IO_read_end
- fp
->_IO_read_ptr
;
1505 /* Check that we are mapping all of the file, in case it grew. */
1506 if (__builtin_expect (mmap_remap_check (fp
), 0))
1507 /* We punted mmap, so complete with the vanilla code. */
1508 return s
- (char *) data
+ _IO_XSGETN (fp
, data
, n
);
1510 read_ptr
= fp
->_IO_read_ptr
;
1511 have
= fp
->_IO_read_end
- read_ptr
;
1516 fp
->_flags
|= _IO_EOF_SEEN
;
1520 have
= MIN (have
, n
);
1522 s
= __mempcpy (s
, read_ptr
, have
);
1524 memcpy (s
, read_ptr
, have
);
1527 fp
->_IO_read_ptr
= read_ptr
+ have
;
1530 return s
- (char *) data
;
1533 static _IO_size_t _IO_file_xsgetn_maybe_mmap
__P ((_IO_FILE
*, void *,
1536 _IO_file_xsgetn_maybe_mmap (fp
, data
, n
)
1541 /* We only get here if this is the first attempt to read something.
1542 Decide which operations to use and then punt to the chosen one. */
1544 decide_maybe_mmap (fp
);
1545 return _IO_XSGETN (fp
, data
, n
);
1547 #endif /* HAVE_MMAP */
1550 # undef _IO_do_write
1551 versioned_symbol (libc
, _IO_new_do_write
, _IO_do_write
, GLIBC_2_1
);
1552 versioned_symbol (libc
, _IO_new_file_attach
, _IO_file_attach
, GLIBC_2_1
);
1553 versioned_symbol (libc
, _IO_new_file_close_it
, _IO_file_close_it
, GLIBC_2_1
);
1554 versioned_symbol (libc
, _IO_new_file_finish
, _IO_file_finish
, GLIBC_2_1
);
1555 versioned_symbol (libc
, _IO_new_file_fopen
, _IO_file_fopen
, GLIBC_2_1
);
1556 versioned_symbol (libc
, _IO_new_file_init
, _IO_file_init
, GLIBC_2_1
);
1557 versioned_symbol (libc
, _IO_new_file_setbuf
, _IO_file_setbuf
, GLIBC_2_1
);
1558 versioned_symbol (libc
, _IO_new_file_sync
, _IO_file_sync
, GLIBC_2_1
);
1559 versioned_symbol (libc
, _IO_new_file_overflow
, _IO_file_overflow
, GLIBC_2_1
);
1560 versioned_symbol (libc
, _IO_new_file_seekoff
, _IO_file_seekoff
, GLIBC_2_1
);
1561 versioned_symbol (libc
, _IO_new_file_underflow
, _IO_file_underflow
, GLIBC_2_1
);
1562 versioned_symbol (libc
, _IO_new_file_write
, _IO_file_write
, GLIBC_2_1
);
1563 versioned_symbol (libc
, _IO_new_file_xsputn
, _IO_file_xsputn
, GLIBC_2_1
);
1566 struct _IO_jump_t _IO_file_jumps
=
1569 JUMP_INIT(finish
, INTUSE(_IO_file_finish
)),
1570 JUMP_INIT(overflow
, INTUSE(_IO_file_overflow
)),
1571 JUMP_INIT(underflow
, INTUSE(_IO_file_underflow
)),
1572 JUMP_INIT(uflow
, INTUSE(_IO_default_uflow
)),
1573 JUMP_INIT(pbackfail
, INTUSE(_IO_default_pbackfail
)),
1574 JUMP_INIT(xsputn
, INTUSE(_IO_file_xsputn
)),
1575 JUMP_INIT(xsgetn
, INTUSE(_IO_file_xsgetn
)),
1576 JUMP_INIT(seekoff
, _IO_new_file_seekoff
),
1577 JUMP_INIT(seekpos
, _IO_default_seekpos
),
1578 JUMP_INIT(setbuf
, _IO_new_file_setbuf
),
1579 JUMP_INIT(sync
, _IO_new_file_sync
),
1580 JUMP_INIT(doallocate
, INTUSE(_IO_file_doallocate
)),
1581 JUMP_INIT(read
, INTUSE(_IO_file_read
)),
1582 JUMP_INIT(write
, _IO_new_file_write
),
1583 JUMP_INIT(seek
, INTUSE(_IO_file_seek
)),
1584 JUMP_INIT(close
, INTUSE(_IO_file_close
)),
1585 JUMP_INIT(stat
, INTUSE(_IO_file_stat
)),
1586 JUMP_INIT(showmanyc
, _IO_default_showmanyc
),
1587 JUMP_INIT(imbue
, _IO_default_imbue
)
1589 INTVARDEF(_IO_file_jumps
)
1592 struct _IO_jump_t _IO_file_jumps_mmap
=
1595 JUMP_INIT(finish
, INTUSE(_IO_file_finish
)),
1596 JUMP_INIT(overflow
, INTUSE(_IO_file_overflow
)),
1597 JUMP_INIT(underflow
, _IO_file_underflow_mmap
),
1598 JUMP_INIT(uflow
, INTUSE(_IO_default_uflow
)),
1599 JUMP_INIT(pbackfail
, INTUSE(_IO_default_pbackfail
)),
1600 JUMP_INIT(xsputn
, _IO_new_file_xsputn
),
1601 JUMP_INIT(xsgetn
, _IO_file_xsgetn_mmap
),
1602 JUMP_INIT(seekoff
, _IO_file_seekoff_mmap
),
1603 JUMP_INIT(seekpos
, _IO_default_seekpos
),
1604 JUMP_INIT(setbuf
, (_IO_setbuf_t
) _IO_file_setbuf_mmap
),
1605 JUMP_INIT(sync
, _IO_file_sync_mmap
),
1606 JUMP_INIT(doallocate
, INTUSE(_IO_file_doallocate
)),
1607 JUMP_INIT(read
, INTUSE(_IO_file_read
)),
1608 JUMP_INIT(write
, _IO_new_file_write
),
1609 JUMP_INIT(seek
, INTUSE(_IO_file_seek
)),
1610 JUMP_INIT(close
, _IO_file_close_mmap
),
1611 JUMP_INIT(stat
, INTUSE(_IO_file_stat
)),
1612 JUMP_INIT(showmanyc
, _IO_default_showmanyc
),
1613 JUMP_INIT(imbue
, _IO_default_imbue
)
1616 struct _IO_jump_t _IO_file_jumps_maybe_mmap
=
1619 JUMP_INIT(finish
, INTUSE(_IO_file_finish
)),
1620 JUMP_INIT(overflow
, INTUSE(_IO_file_overflow
)),
1621 JUMP_INIT(underflow
, _IO_file_underflow_maybe_mmap
),
1622 JUMP_INIT(uflow
, INTUSE(_IO_default_uflow
)),
1623 JUMP_INIT(pbackfail
, INTUSE(_IO_default_pbackfail
)),
1624 JUMP_INIT(xsputn
, _IO_new_file_xsputn
),
1625 JUMP_INIT(xsgetn
, _IO_file_xsgetn_maybe_mmap
),
1626 JUMP_INIT(seekoff
, _IO_file_seekoff_maybe_mmap
),
1627 JUMP_INIT(seekpos
, _IO_default_seekpos
),
1628 JUMP_INIT(setbuf
, (_IO_setbuf_t
) _IO_file_setbuf_mmap
),
1629 JUMP_INIT(sync
, _IO_new_file_sync
),
1630 JUMP_INIT(doallocate
, INTUSE(_IO_file_doallocate
)),
1631 JUMP_INIT(read
, INTUSE(_IO_file_read
)),
1632 JUMP_INIT(write
, _IO_new_file_write
),
1633 JUMP_INIT(seek
, INTUSE(_IO_file_seek
)),
1634 JUMP_INIT(close
, _IO_file_close
),
1635 JUMP_INIT(stat
, INTUSE(_IO_file_stat
)),
1636 JUMP_INIT(showmanyc
, _IO_default_showmanyc
),
1637 JUMP_INIT(imbue
, _IO_default_imbue
)
1639 #endif /* HAVE_MMAP */