about summary refs log tree commit diff
path: root/libio/iofopen.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-02-26 05:23:31 +0000
committerUlrich Drepper <drepper@redhat.com>2002-02-26 05:23:31 +0000
commitb39d571990557cc5ab855794ff0d4d7876f4596b (patch)
treef5f6918e0520a86a5576cc393c39fabb1cb4e0eb /libio/iofopen.c
parent77fe0b9cd86ccba7349921082d886cbca613404c (diff)
downloadglibc-b39d571990557cc5ab855794ff0d4d7876f4596b.tar.gz
glibc-b39d571990557cc5ab855794ff0d4d7876f4596b.tar.xz
glibc-b39d571990557cc5ab855794ff0d4d7876f4596b.zip
Update.
2002-02-25  Jakub Jelinek  <jakub@redhat.com>

	* libio/iofopen.c (__fopen_maybe_mmap): Set the initial
	position to fp->_offset if it is set.
	* stdio-common/Makefile (tests): Add tst-fdopen.
	* stdio-common/tst-fdopen.c: New test.

2002-02-25  Jakub Jelinek  <jakub@redhat.com>

	* libio/fileops.c (_IO_file_xsgetn_mmap): Handle reading from backup.
	* stdio-common/tst-ungetc.c (main): Add another test.
Diffstat (limited to 'libio/iofopen.c')
-rw-r--r--libio/iofopen.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/libio/iofopen.c b/libio/iofopen.c
index 4bb780de13..c1681a4a10 100644
--- a/libio/iofopen.c
+++ b/libio/iofopen.c
@@ -53,7 +53,9 @@ __fopen_maybe_mmap (fp)
       if (_IO_SYSSTAT (fp, &st) == 0
 	  && S_ISREG (st.st_mode) && st.st_size != 0
 	  /* Limit the file size to 1MB for 32-bit machines.  */
-	  && (sizeof (ptrdiff_t) > 4 || st.st_size < 1*1024*1024))
+	  && (sizeof (ptrdiff_t) > 4 || st.st_size < 1*1024*1024)
+	  /* Sanity check.  */
+	  && (fp->_offset == _IO_pos_BAD || fp->_offset <= st.st_size))
 	{
 	  /* Try to map the file.  */
 	  void *p;
@@ -72,15 +74,17 @@ __fopen_maybe_mmap (fp)
 		 underflow functions which never tries to read
 		 anything from the file.  */
 	      INTUSE(_IO_setb) (fp, p, (char *) p + st.st_size, 0);
-	      _IO_setg (fp, p, p, p);
+
+	      if (fp->_offset == _IO_pos_BAD)
+		fp->_offset = 0;
+
+	      _IO_setg (fp,  p, p + fp->_offset, p + fp->_offset);
 
 	      if (fp->_mode <= 0)
 		_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_file_jumps_mmap;
 	      else
 		_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_wfile_jumps_mmap;
 	      fp->_wide_data->_wide_vtable = &_IO_wfile_jumps_mmap;
-
-	      fp->_offset = 0;
 	    }
 	}
     }