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 Per Bothner <bothner@cygnus.com>.
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2, or (at
8 your option) any later version.
10 This library is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this library; see the file COPYING. If not, write to
17 the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
20 As a special exception, if you link this library with files
21 compiled with a GNU compiler to produce an executable, this does
22 not cause the resulting executable to be covered by the GNU General
23 Public License. This exception does not however invalidate any
24 other reasons why the executable file might be covered by the GNU
25 General Public License. */
29 # define _POSIX_SOURCE
33 #include <sys/types.h>
44 # define __set_errno(Val) errno = (Val)
49 # define open(Name, Flags, Prot) __open (Name, Flags, Prot)
50 # define close(FD) __close (FD)
51 # define lseek(FD, Offset, Whence) __lseek (FD, Offset, Whence)
52 # define read(FD, Buf, NBytes) __read (FD, Buf, NBytes)
53 # define write(FD, Buf, NBytes) __write (FD, Buf, NBytes)
56 /* An fstream can be in at most one of put mode, get mode, or putback mode.
57 Putback mode is a variant of get mode.
59 In a filebuf, there is only one current position, instead of two
60 separate get and put pointers. In get mode, the current position
61 is that of gptr(); in put mode that of pptr().
63 The position in the buffer that corresponds to the position
64 in external file system is normally _IO_read_end, except in putback
65 mode, when it is _IO_save_end.
66 If the field _fb._offset is >= 0, it gives the offset in
67 the file as a whole corresponding to eGptr(). (?)
70 If a filebuf is in put mode, then all of _IO_read_ptr, _IO_read_end,
71 and _IO_read_base are equal to each other. These are usually equal
72 to _IO_buf_base, though not necessarily if we have switched from
73 get mode to put mode. (The reason is to maintain the invariant
74 that _IO_read_end corresponds to the external file position.)
75 _IO_write_base is non-NULL and usually equal to _IO_base_base.
76 We also have _IO_write_end == _IO_buf_end, but only in fully buffered mode.
77 The un-flushed character are those between _IO_write_base and _IO_write_ptr.
80 If a filebuf is in get or putback mode, eback() != egptr().
81 In get mode, the unread characters are between gptr() and egptr().
82 The OS file position corresponds to that of egptr().
85 Putback mode is used to remember "excess" characters that have
86 been sputbackc'd in a separate putback buffer.
87 In putback mode, the get buffer points to the special putback buffer.
88 The unread characters are the characters between gptr() and egptr()
89 in the putback buffer, as well as the area between save_gptr()
90 and save_egptr(), which point into the original reserve buffer.
91 (The pointers save_gptr() and save_egptr() are the values
92 of gptr() and egptr() at the time putback mode was entered.)
93 The OS position corresponds to that of save_egptr().
96 During line buffered output, _IO_write_base==base() && epptr()==base().
97 However, ptr() may be anywhere between base() and ebuf().
98 This forces a call to filebuf::overflow(int C) on every put.
99 If there is more space in the buffer, and C is not a '\n',
100 then C is inserted, and pptr() incremented.
103 If a filebuf is unbuffered(), the _shortbuf[1] is used as the buffer.
106 #define CLOSED_FILEBUF_FLAGS \
107 (_IO_IS_FILEBUF+_IO_NO_READS+_IO_NO_WRITES+_IO_TIED_PUT_GET)
111 _IO_new_file_init (fp
)
114 /* POSIX.1 allows another file handle to be used to change the position
115 of our file descriptor. Hence we actually don't know the actual
116 position before we do the first fseek (and until a following fflush). */
117 fp
->_offset
= _IO_pos_BAD
;
118 fp
->_IO_file_flags
|= CLOSED_FILEBUF_FLAGS
;
125 _IO_new_file_close_it (fp
)
128 int write_status
, close_status
;
129 if (!_IO_file_is_open (fp
))
132 write_status
= _IO_do_flush (fp
);
134 _IO_unsave_markers(fp
);
136 close_status
= _IO_SYSCLOSE (fp
);
141 _IO_setb (fp
, NULL
, NULL
, 0);
142 _IO_setg (fp
, NULL
, NULL
, NULL
);
143 _IO_setp (fp
, NULL
, NULL
);
147 _IO_wsetb (fp
, NULL
, NULL
, 0);
148 _IO_wsetg (fp
, NULL
, NULL
, NULL
);
149 _IO_wsetp (fp
, NULL
, NULL
);
153 fp
->_flags
= _IO_MAGIC
|CLOSED_FILEBUF_FLAGS
;
155 fp
->_offset
= _IO_pos_BAD
;
157 return close_status
? close_status
: write_status
;
161 _IO_new_file_finish (fp
, dummy
)
165 if (_IO_file_is_open (fp
))
168 if (!(fp
->_flags
& _IO_DELETE_DONT_CLOSE
))
171 _IO_default_finish (fp
, 0);
174 #if defined __GNUC__ && __GNUC__ >= 2
178 _IO_file_open (fp
, filename
, posix_mode
, prot
, read_write
, is32not64
)
180 const char *filename
;
189 ? open (filename
, posix_mode
, prot
)
190 : _G_OPEN64 (filename
, posix_mode
, prot
));
192 fdesc
= open (filename
, posix_mode
, prot
);
197 _IO_mask_flags (fp
, read_write
,_IO_NO_READS
+_IO_NO_WRITES
+_IO_IS_APPENDING
);
198 if (read_write
& _IO_IS_APPENDING
)
199 if (_IO_SEEKOFF (fp
, (_IO_off64_t
)0, _IO_seek_end
, _IOS_INPUT
|_IOS_OUTPUT
)
200 == _IO_pos_BAD
&& errno
!= ESPIPE
)
207 _IO_new_file_fopen (fp
, filename
, mode
, is32not64
)
209 const char *filename
;
213 int oflags
= 0, omode
;
217 if (_IO_file_is_open (fp
))
223 read_write
= _IO_NO_WRITES
;
227 oflags
= O_CREAT
|O_TRUNC
;
228 read_write
= _IO_NO_READS
;
232 oflags
= O_CREAT
|O_APPEND
;
233 read_write
= _IO_NO_READS
|_IO_IS_APPENDING
;
236 __set_errno (EINVAL
);
239 for (i
= 1; i
< 4; ++i
)
247 read_write
&= _IO_IS_APPENDING
;
260 return _IO_file_open (fp
, filename
, omode
|oflags
, oprot
, read_write
,
265 _IO_new_file_attach (fp
, fd
)
269 if (_IO_file_is_open (fp
))
272 fp
->_flags
&= ~(_IO_NO_READS
+_IO_NO_WRITES
);
273 fp
->_flags
|= _IO_DELETE_DONT_CLOSE
;
274 /* Get the current position of the file. */
275 /* We have to do that since that may be junk. */
276 fp
->_offset
= _IO_pos_BAD
;
277 if (_IO_SEEKOFF (fp
, (_IO_off64_t
)0, _IO_seek_cur
, _IOS_INPUT
|_IOS_OUTPUT
)
278 == _IO_pos_BAD
&& errno
!= ESPIPE
)
284 _IO_new_file_setbuf (fp
, p
, len
)
289 if (_IO_default_setbuf (fp
, p
, len
) == NULL
)
292 fp
->_IO_write_base
= fp
->_IO_write_ptr
= fp
->_IO_write_end
294 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
299 static int new_do_write
__P ((_IO_FILE
*, const char *, _IO_size_t
));
301 /* Write TO_DO bytes from DATA to FP.
302 Then mark FP as having empty buffers. */
305 _IO_new_do_write (fp
, data
, to_do
)
310 return (to_do
== 0 || new_do_write (fp
, data
, to_do
) == to_do
)
316 new_do_write (fp
, data
, to_do
)
322 if (fp
->_flags
& _IO_IS_APPENDING
)
323 /* On a system without a proper O_APPEND implementation,
324 you would need to sys_seek(0, SEEK_END) here, but is
325 is not needed nor desirable for Unix- or Posix-like systems.
326 Instead, just indicate that offset (before and after) is
328 fp
->_offset
= _IO_pos_BAD
;
329 else if (fp
->_IO_read_end
!= fp
->_IO_write_base
)
332 = _IO_SYSSEEK (fp
, fp
->_IO_write_base
- fp
->_IO_read_end
, 1);
333 if (new_pos
== _IO_pos_BAD
)
335 fp
->_offset
= new_pos
;
337 count
= _IO_SYSWRITE (fp
, data
, to_do
);
338 if (fp
->_cur_column
&& count
)
339 fp
->_cur_column
= _IO_adjust_column (fp
->_cur_column
- 1, data
, count
) + 1;
340 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
341 fp
->_IO_write_base
= fp
->_IO_write_ptr
= fp
->_IO_buf_base
;
342 fp
->_IO_write_end
= (fp
->_mode
< 0
343 && (fp
->_flags
& (_IO_LINE_BUF
+_IO_UNBUFFERED
))
344 ? fp
->_IO_buf_base
: fp
->_IO_buf_end
);
349 _IO_new_file_underflow (fp
)
354 /* SysV does not make this test; take it out for compatibility */
355 if (fp
->_flags
& _IO_EOF_SEEN
)
359 if (fp
->_flags
& _IO_NO_READS
)
361 fp
->_flags
|= _IO_ERR_SEEN
;
365 if (fp
->_IO_read_ptr
< fp
->_IO_read_end
)
366 return *(unsigned char *) fp
->_IO_read_ptr
;
368 if (fp
->_IO_buf_base
== NULL
)
370 /* Maybe we already have a push back pointer. */
371 if (fp
->_IO_save_base
!= NULL
)
373 free (fp
->_IO_save_base
);
374 fp
->_flags
&= ~_IO_IN_BACKUP
;
379 /* Flush all line buffered files before reading. */
380 /* FIXME This can/should be moved to genops ?? */
381 if (fp
->_flags
& (_IO_LINE_BUF
|_IO_UNBUFFERED
))
382 _IO_flush_all_linebuffered ();
384 _IO_switch_to_get_mode (fp
);
386 /* This is very tricky. We have to adjust those
387 pointers before we call _IO_SYSREAD () since
388 we may longjump () out while waiting for
389 input. Those pointers may be screwed up. H.J. */
390 fp
->_IO_read_base
= fp
->_IO_read_ptr
= fp
->_IO_buf_base
;
391 fp
->_IO_read_end
= fp
->_IO_buf_base
;
392 fp
->_IO_write_base
= fp
->_IO_write_ptr
= fp
->_IO_write_end
395 count
= _IO_SYSREAD (fp
, fp
->_IO_buf_base
,
396 fp
->_IO_buf_end
- fp
->_IO_buf_base
);
400 fp
->_flags
|= _IO_EOF_SEEN
;
402 fp
->_flags
|= _IO_ERR_SEEN
, count
= 0;
404 fp
->_IO_read_end
+= count
;
407 if (fp
->_offset
!= _IO_pos_BAD
)
408 _IO_pos_adjust (fp
->_offset
, count
);
409 return *(unsigned char *) fp
->_IO_read_ptr
;
413 _IO_new_file_overflow (f
, ch
)
417 if (f
->_flags
& _IO_NO_WRITES
) /* SET ERROR */
419 f
->_flags
|= _IO_ERR_SEEN
;
423 /* If currently reading or no buffer allocated. */
424 if ((f
->_flags
& _IO_CURRENTLY_PUTTING
) == 0 || f
->_IO_write_base
== 0)
426 /* Allocate a buffer if needed. */
427 if (f
->_IO_write_base
== 0)
430 _IO_setg (f
, f
->_IO_buf_base
, f
->_IO_buf_base
, f
->_IO_buf_base
);
432 /* Otherwise must be currently reading.
433 If _IO_read_ptr (and hence also _IO_read_end) is at the buffer end,
434 logically slide the buffer forwards one block (by setting the
435 read pointers to all point at the beginning of the block). This
436 makes room for subsequent output.
437 Otherwise, set the read pointers to _IO_read_end (leaving that
438 alone, so it can continue to correspond to the external position). */
439 if (f
->_IO_read_ptr
== f
->_IO_buf_end
)
440 f
->_IO_read_end
= f
->_IO_read_ptr
= f
->_IO_buf_base
;
441 f
->_IO_write_ptr
= f
->_IO_read_ptr
;
442 f
->_IO_write_base
= f
->_IO_write_ptr
;
443 f
->_IO_write_end
= f
->_IO_buf_end
;
444 f
->_IO_read_base
= f
->_IO_read_ptr
= f
->_IO_read_end
;
446 f
->_flags
|= _IO_CURRENTLY_PUTTING
;
447 if (f
->_mode
< 0 && f
->_flags
& (_IO_LINE_BUF
+_IO_UNBUFFERED
))
448 f
->_IO_write_end
= f
->_IO_write_ptr
;
451 return _IO_new_do_write(f
, f
->_IO_write_base
,
452 f
->_IO_write_ptr
- f
->_IO_write_base
);
453 if (f
->_IO_write_ptr
== f
->_IO_buf_end
) /* Buffer is really full */
454 if (_IO_do_flush (f
) == EOF
)
456 *f
->_IO_write_ptr
++ = ch
;
457 if ((f
->_flags
& _IO_UNBUFFERED
)
458 || ((f
->_flags
& _IO_LINE_BUF
) && ch
== '\n'))
459 if (_IO_new_do_write(f
, f
->_IO_write_base
,
460 f
->_IO_write_ptr
- f
->_IO_write_base
) == EOF
)
462 return (unsigned char) ch
;
466 _IO_new_file_sync (fp
)
472 /* char* ptr = cur_ptr(); */
473 if (fp
->_IO_write_ptr
> fp
->_IO_write_base
)
474 if (_IO_do_flush(fp
)) return EOF
;
475 delta
= fp
->_IO_read_ptr
- fp
->_IO_read_end
;
479 if (_IO_in_backup (fp
))
480 delta
-= eGptr () - Gbase ();
482 _IO_off64_t new_pos
= _IO_SYSSEEK (fp
, delta
, 1);
483 if (new_pos
!= (_IO_off64_t
) EOF
)
484 fp
->_IO_read_end
= fp
->_IO_read_ptr
;
486 else if (errno
== ESPIPE
)
487 ; /* Ignore error from unseekable devices. */
493 fp
->_offset
= _IO_pos_BAD
;
494 /* FIXME: Cleanup - can this be shared? */
495 /* setg(base(), ptr, ptr); */
500 _IO_new_file_seekoff (fp
, offset
, dir
, mode
)
507 _IO_off64_t delta
, new_offset
;
509 /* POSIX.1 8.2.3.7 says that after a call the fflush() the file
510 offset of the underlying file must be exact. */
511 int must_be_exact
= (fp
->_IO_read_base
== fp
->_IO_read_end
512 && fp
->_IO_write_base
== fp
->_IO_write_ptr
);
515 dir
= _IO_seek_cur
, offset
= 0; /* Don't move any pointers. */
517 /* Flush unwritten characters.
518 (This may do an unneeded write if we seek within the buffer.
519 But to be able to switch to reading, we would need to set
520 egptr to ptr. That can't be done in the current design,
521 which assumes file_ptr() is eGptr. Anyway, since we probably
522 end up flushing when we close(), it doesn't make much difference.)
523 FIXME: simulate mem-papped files. */
525 if (fp
->_IO_write_ptr
> fp
->_IO_write_base
|| _IO_in_put_mode (fp
))
526 if (_IO_switch_to_get_mode (fp
))
529 if (fp
->_IO_buf_base
== NULL
)
531 /* It could be that we already have a pushback buffer. */
532 if (fp
->_IO_read_base
!= NULL
)
534 free (fp
->_IO_read_base
);
535 fp
->_flags
&= ~_IO_IN_BACKUP
;
538 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
539 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
545 /* Adjust for read-ahead (bytes is buffer). */
546 offset
-= fp
->_IO_read_end
- fp
->_IO_read_ptr
;
547 if (fp
->_offset
== _IO_pos_BAD
)
549 /* Make offset absolute, assuming current pointer is file_ptr(). */
550 offset
+= fp
->_offset
;
559 if (_IO_SYSSTAT (fp
, &st
) == 0 && S_ISREG (st
.st_mode
))
561 offset
+= st
.st_size
;
568 /* At this point, dir==_IO_seek_set. */
570 /* If we are only interested in the current position we've found it now. */
574 /* If destination is within current buffer, optimize: */
575 if (fp
->_offset
!= _IO_pos_BAD
&& fp
->_IO_read_base
!= NULL
576 && !_IO_in_backup (fp
))
578 /* Offset relative to start of main get area. */
579 _IO_off64_t rel_offset
= (offset
- fp
->_offset
580 + (fp
->_IO_read_end
- fp
->_IO_read_base
));
584 if (_IO_in_backup (fp
))
585 _IO_switch_to_main_get_area (fp
);
587 if (rel_offset
<= fp
->_IO_read_end
- fp
->_IO_read_base
)
589 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
+ rel_offset
,
591 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
593 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
598 /* If we have streammarkers, seek forward by reading ahead. */
599 if (_IO_have_markers (fp
))
601 int to_skip
= rel_offset
602 - (fp
->_IO_read_ptr
- fp
->_IO_read_base
);
603 if (ignore (to_skip
) != to_skip
)
605 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
611 if (rel_offset
< 0 && rel_offset
>= Bbase () - Bptr ())
613 if (!_IO_in_backup (fp
))
614 _IO_switch_to_backup_area (fp
);
615 gbump (fp
->_IO_read_end
+ rel_offset
- fp
->_IO_read_ptr
);
616 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
623 _IO_unsave_markers (fp
);
626 if (fp
->_flags
& _IO_NO_READS
)
629 /* Try to seek to a block boundary, to improve kernel page management. */
630 new_offset
= offset
& ~(fp
->_IO_buf_end
- fp
->_IO_buf_base
- 1);
631 delta
= offset
- new_offset
;
632 if (delta
> fp
->_IO_buf_end
- fp
->_IO_buf_base
)
637 result
= _IO_SYSSEEK (fp
, new_offset
, 0);
644 count
= _IO_SYSREAD (fp
, fp
->_IO_buf_base
,
646 ? delta
: fp
->_IO_buf_end
- fp
->_IO_buf_base
));
649 /* We weren't allowed to read, but try to seek the remainder. */
650 offset
= count
== EOF
? delta
: delta
-count
;
655 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
+ delta
,
656 fp
->_IO_buf_base
+ count
);
657 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
658 fp
->_offset
= result
+ count
;
659 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
663 _IO_unsave_markers (fp
);
664 result
= _IO_SYSSEEK (fp
, offset
, dir
);
667 _IO_mask_flags (fp
, 0, _IO_EOF_SEEN
);
668 fp
->_offset
= result
;
669 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
670 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
675 /* We need to do it since it is possible that the file offset in
676 the kernel may be changed behind our back. It may happen when
677 we fopen a file and then do a fork. One process may access the
678 the file and the kernel file offset will be changed. */
679 if (fp
->_offset
>= 0)
680 _IO_SYSSEEK (fp
, fp
->_offset
, 0);
686 _IO_file_read (fp
, buf
, size
)
691 return read (fp
->_fileno
, buf
, size
);
695 _IO_file_seek (fp
, offset
, dir
)
701 return _G_LSEEK64 (fp
->_fileno
, offset
, dir
);
703 return lseek (fp
->_fileno
, offset
, dir
);
708 _IO_file_stat (fp
, st
)
713 return _G_FSTAT64 (fp
->_fileno
, (struct _G_stat64
*) st
);
715 return fstat (fp
->_fileno
, (struct _G_stat64
*) st
);
723 return close (fp
->_fileno
);
727 _IO_new_file_write (f
, data
, n
)
732 _IO_ssize_t to_do
= n
;
735 _IO_ssize_t count
= write (f
->_fileno
, data
, to_do
);
738 f
->_flags
|= _IO_ERR_SEEN
;
742 data
= (void *) ((char *) data
+ count
);
751 _IO_new_file_xsputn (f
, data
, n
)
756 register const char *s
= (const char *) data
;
757 _IO_size_t to_do
= n
;
763 /* This is an optimized implementation.
764 If the amount to be written straddles a block boundary
765 (or the filebuf is unbuffered), use sys_write directly. */
767 /* First figure out how much space is available in the buffer. */
768 count
= f
->_IO_write_end
- f
->_IO_write_ptr
; /* Space available. */
769 if ((f
->_flags
& _IO_LINE_BUF
) && (f
->_flags
& _IO_CURRENTLY_PUTTING
))
771 count
= f
->_IO_buf_end
- f
->_IO_write_ptr
;
774 register const char *p
;
775 for (p
= s
+ n
; p
> s
; )
786 /* Then fill the buffer. */
794 f
->_IO_write_ptr
= __mempcpy (f
->_IO_write_ptr
, s
, count
);
796 memcpy (f
->_IO_write_ptr
, s
, count
);
797 f
->_IO_write_ptr
+= count
;
803 register char *p
= f
->_IO_write_ptr
;
804 register int i
= (int) count
;
807 f
->_IO_write_ptr
= p
;
811 if (to_do
+ must_flush
> 0)
813 _IO_size_t block_size
, do_write
;
814 /* Next flush the (full) buffer. */
815 if (_IO_OVERFLOW (f
, EOF
) == EOF
)
818 /* Try to maintain alignment: write a whole number of blocks.
819 dont_write is what gets left over. */
820 block_size
= f
->_IO_buf_end
- f
->_IO_buf_base
;
821 do_write
= to_do
- (block_size
>= 128 ? to_do
% block_size
: 0);
825 count
= new_do_write (f
, s
, do_write
);
827 if (count
< do_write
)
831 /* Now write out the remainder. Normally, this will fit in the
832 buffer, but it's somewhat messier for line-buffered files,
833 so we let _IO_default_xsputn handle the general case. */
835 to_do
-= _IO_default_xsputn (f
, s
+do_write
, to_do
);
841 _IO_file_xsgetn (fp
, data
, n
)
846 register _IO_size_t want
, have
;
847 register _IO_ssize_t count
;
848 register char *s
= data
;
852 if (fp
->_IO_buf_base
== NULL
)
854 /* Maybe we already have a push back pointer. */
855 if (fp
->_IO_save_base
!= NULL
)
857 free (fp
->_IO_save_base
);
858 fp
->_flags
&= ~_IO_IN_BACKUP
;
865 have
= fp
->_IO_read_end
- fp
->_IO_read_ptr
;
868 memcpy (s
, fp
->_IO_read_ptr
, want
);
869 fp
->_IO_read_ptr
+= want
;
877 s
= __mempcpy (s
, fp
->_IO_read_ptr
, have
);
879 memcpy (s
, fp
->_IO_read_ptr
, have
);
883 fp
->_IO_read_ptr
+= have
;
886 /* Check for backup and repeat */
887 if (_IO_in_backup (fp
))
889 _IO_switch_to_main_get_area (fp
);
893 /* If we now want less than a buffer, underflow and repeat
894 the copy. Otherwise, _IO_SYSREAD directly to
896 if (fp
->_IO_buf_base
&& want
< fp
->_IO_buf_end
- fp
->_IO_buf_base
)
898 if (__underflow (fp
) == EOF
)
904 /* These must be set before the sysread as we might longjmp out
905 waiting for input. */
906 _IO_setg (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
907 _IO_setp (fp
, fp
->_IO_buf_base
, fp
->_IO_buf_base
);
909 /* Try to maintain alignment: read a whole number of blocks. */
911 if (fp
->_IO_buf_base
)
913 _IO_size_t block_size
= fp
->_IO_buf_end
- fp
->_IO_buf_base
;
914 if (block_size
>= 128)
915 count
-= want
% block_size
;
918 count
= _IO_SYSREAD (fp
, s
, count
);
922 fp
->_flags
|= _IO_EOF_SEEN
;
924 fp
->_flags
|= _IO_ERR_SEEN
;
931 if (fp
->_offset
!= _IO_pos_BAD
)
932 _IO_pos_adjust (fp
->_offset
, count
);
939 struct _IO_jump_t _IO_file_jumps
=
942 JUMP_INIT(finish
, _IO_new_file_finish
),
943 JUMP_INIT(overflow
, _IO_new_file_overflow
),
944 JUMP_INIT(underflow
, _IO_new_file_underflow
),
945 JUMP_INIT(uflow
, _IO_default_uflow
),
946 JUMP_INIT(pbackfail
, _IO_default_pbackfail
),
947 JUMP_INIT(xsputn
, _IO_new_file_xsputn
),
948 JUMP_INIT(xsgetn
, _IO_file_xsgetn
),
949 JUMP_INIT(seekoff
, _IO_new_file_seekoff
),
950 JUMP_INIT(seekpos
, _IO_default_seekpos
),
951 JUMP_INIT(setbuf
, _IO_new_file_setbuf
),
952 JUMP_INIT(sync
, _IO_new_file_sync
),
953 JUMP_INIT(doallocate
, _IO_file_doallocate
),
954 JUMP_INIT(read
, _IO_file_read
),
955 JUMP_INIT(write
, _IO_new_file_write
),
956 JUMP_INIT(seek
, _IO_file_seek
),
957 JUMP_INIT(close
, _IO_file_close
),
958 JUMP_INIT(stat
, _IO_file_stat
),
959 JUMP_INIT(showmanyc
, _IO_default_showmanyc
),
960 JUMP_INIT(imbue
, _IO_default_imbue
)
964 #if defined PIC && DO_VERSIONING
965 default_symbol_version (_IO_new_do_write
, _IO_do_write
, GLIBC_2
.1
);
966 default_symbol_version (_IO_new_file_attach
, _IO_file_attach
, GLIBC_2
.1
);
967 default_symbol_version (_IO_new_file_close_it
, _IO_file_close_it
, GLIBC_2
.1
);
968 default_symbol_version (_IO_new_file_finish
, _IO_file_finish
, GLIBC_2
.1
);
969 default_symbol_version (_IO_new_file_fopen
, _IO_file_fopen
, GLIBC_2
.1
);
970 default_symbol_version (_IO_new_file_init
, _IO_file_init
, GLIBC_2
.1
);
971 default_symbol_version (_IO_new_file_setbuf
, _IO_file_setbuf
, GLIBC_2
.1
);
972 default_symbol_version (_IO_new_file_sync
, _IO_file_sync
, GLIBC_2
.1
);
973 default_symbol_version (_IO_new_file_overflow
, _IO_file_overflow
, GLIBC_2
.1
);
974 default_symbol_version (_IO_new_file_seekoff
, _IO_file_seekoff
, GLIBC_2
.1
);
975 default_symbol_version (_IO_new_file_underflow
, _IO_file_underflow
, GLIBC_2
.1
);
976 default_symbol_version (_IO_new_file_write
, _IO_file_write
, GLIBC_2
.1
);
977 default_symbol_version (_IO_new_file_xsputn
, _IO_file_xsputn
, GLIBC_2
.1
);
980 strong_alias (_IO_new_do_write
, _IO_do_write
);
981 strong_alias (_IO_new_file_attach
, _IO_file_attach
);
982 strong_alias (_IO_new_file_close_it
, _IO_file_close_it
);
983 strong_alias (_IO_new_file_finish
, _IO_file_finish
);
984 strong_alias (_IO_new_file_fopen
, _IO_file_fopen
);
985 strong_alias (_IO_new_file_init
, _IO_file_init
);
986 strong_alias (_IO_new_file_setbuf
, _IO_file_setbuf
);
987 strong_alias (_IO_new_file_sync
, _IO_file_sync
);
988 strong_alias (_IO_new_file_overflow
, _IO_file_overflow
);
989 strong_alias (_IO_new_file_seekoff
, _IO_file_seekoff
);
990 strong_alias (_IO_new_file_underflow
, _IO_file_underflow
);
991 strong_alias (_IO_new_file_write
, _IO_file_write
);
992 strong_alias (_IO_new_file_xsputn
, _IO_file_xsputn
);