#include <sys/stat.h>
#include <string.h>
#include <errno.h>
+#ifdef __STDC__
+#include <stdlib.h>
+#endif
#ifndef errno
extern int errno;
#endif
return *(unsigned char *) fp->_IO_read_ptr;
if (fp->_IO_buf_base == NULL)
- _IO_doallocbuf (fp);
+ {
+ /* Maybe we already have a push back pointer. */
+ if (fp->_IO_save_base != NULL)
+ {
+ free (fp->_IO_save_base);
+ fp->_flags &= ~_IO_IN_BACKUP;
+ }
+ _IO_doallocbuf (fp);
+ }
/* Flush all line buffered files before reading. */
/* FIXME This can/should be moved to genops ?? */
if (fp->_IO_buf_base == NULL)
{
+ /* It could be that we already have a pushback buffer. */
+ if (fp->_IO_read_base != NULL)
+ {
+ free (fp->_IO_read_base);
+ fp->_flags &= ~_IO_IN_BACKUP;
+ }
_IO_doallocbuf (fp);
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
}
/* At this point, dir==_IO_seek_set. */
+ /* If we are only interested in the current position we've found it now. */
+ if (mode == 0)
+ return offset;
+
/* If destination is within current buffer, optimize: */
if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
&& !_IO_in_backup (fp))
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
fp->_IO_read_end);
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
- return offset;
+ {
+ _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
+ return offset;
+ }
}
#ifdef TODO
/* If we have streammarkers, seek forward by reading ahead. */
- (fp->_IO_read_ptr - fp->_IO_read_base);
if (ignore (to_skip) != to_skip)
goto dumb;
+ _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
return offset;
}
#endif
if (!_IO_in_backup (fp))
_IO_switch_to_backup_area (fp);
gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
+ _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
return offset;
}
#endif