aboutsummaryrefslogtreecommitdiff
path: root/libio/fileops.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-01-07 09:33:53 +0000
committerUlrich Drepper <drepper@redhat.com>2002-01-07 09:33:53 +0000
commit0469311e8702371ee6270ec0ccd05e85e5138483 (patch)
treeefbf96c9796b587b09119d832df76a1a23ccd186 /libio/fileops.c
parent463918b5f2323285b89bde42c732b83f63eb4881 (diff)
downloadglibc-0469311e8702371ee6270ec0ccd05e85e5138483.zip
glibc-0469311e8702371ee6270ec0ccd05e85e5138483.tar.gz
glibc-0469311e8702371ee6270ec0ccd05e85e5138483.tar.bz2
Update.
2002-01-07 Ulrich Drepper <drepper@redhat.com> * libio/fileops.c (_IO_file_underflow_mmap): New function. (_IO_file_close_mmap): New function. (_IO_file_jumps_mmap): New variable. * libio/wfileops.c (_IO_wfile_underflow): Reset read pointer before trying to convert rest of byte buffer. (_IO_wfile_underflow_mmap): New function. (_IO_wfile_jumps_mmap): New variable. * libio/iofopen.c (__fopen_maybe_mmap): New function. (__fopen_internal): New function. Split out from _IO_new_fopen. (_IO_new_fopen): Call __fopen_internal. * libio/iofopen64.c: Just call __fopen_internal. * libio/iofdopen.c: Call __fopen_maybe_mmap before returning successfully. * libio/iolibio.h: Declare __fopen_internal and __fopen_maybe_mmap. * libio/libioP.h: Declare _IO_file_jumps_mmap, _IO_wfile_jumps_mmap, _IO_file_close_mmap. * sysdeps/gnu/_G_config.h: Define _G_MMAP64. * sysdeps/unix/sysv/linux/cris/_G_config.h: Likewise. * stdio-common/Makefile (tests): Add tst-rndseek. * stdio-common/tst-rndseek.c: New file.
Diffstat (limited to 'libio/fileops.c')
-rw-r--r--libio/fileops.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/libio/fileops.c b/libio/fileops.c
index f67eeef..32fa524 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -556,6 +556,34 @@ _IO_new_file_underflow (fp)
return *(unsigned char *) fp->_IO_read_ptr;
}
+/* Special callback replacing the underflow callbacks if we mmap the
+ file. */
+static int
+_IO_file_underflow_mmap (_IO_FILE *fp)
+{
+ if (fp->_IO_read_end < fp->_IO_buf_end)
+ {
+ if (
+# ifdef _G_LSEEK64
+ _G_LSEEK64 (fp->_fileno, fp->_IO_buf_end - fp->_IO_buf_base,
+ SEEK_SET)
+# else
+ __lseek (fp->_fileno, fp->_IO_buf_end - fp->_IO_buf_base, SEEK_SET)
+# endif
+ != fp->_IO_buf_end - fp->_IO_buf_base)
+ {
+ fp->_flags |= _IO_ERR_SEEN;
+ return EOF;
+ }
+
+ fp->_IO_read_end = fp->_IO_buf_end;
+ return *fp->_IO_read_ptr;
+ }
+
+ fp->_flags |= _IO_EOF_SEEN;
+ return EOF;
+}
+
int
_IO_new_file_overflow (f, ch)
_IO_FILE *f;
@@ -864,6 +892,17 @@ _IO_file_stat (fp, st)
}
int
+_IO_file_close_mmap (fp)
+ _IO_FILE *fp;
+{
+ /* In addition to closing the file descriptor we have to unmap the
+ file. */
+ (void) munmap (fp->_IO_buf_base, fp->_IO_buf_end - fp->_IO_buf_base);
+ fp->_IO_buf_base = fp->_IO_buf_end = NULL;
+ return close (fp->_fileno);
+}
+
+int
_IO_file_close (fp)
_IO_FILE *fp;
{
@@ -1107,6 +1146,30 @@ struct _IO_jump_t _IO_file_jumps =
JUMP_INIT(imbue, _IO_default_imbue)
};
+struct _IO_jump_t _IO_file_jumps_mmap =
+{
+ JUMP_INIT_DUMMY,
+ JUMP_INIT(finish, _IO_new_file_finish),
+ JUMP_INIT(overflow, _IO_new_file_overflow),
+ JUMP_INIT(underflow, _IO_file_underflow_mmap),
+ JUMP_INIT(uflow, _IO_default_uflow),
+ JUMP_INIT(pbackfail, _IO_default_pbackfail),
+ JUMP_INIT(xsputn, _IO_new_file_xsputn),
+ JUMP_INIT(xsgetn, _IO_file_xsgetn),
+ JUMP_INIT(seekoff, _IO_new_file_seekoff),
+ JUMP_INIT(seekpos, _IO_default_seekpos),
+ JUMP_INIT(setbuf, _IO_new_file_setbuf),
+ JUMP_INIT(sync, _IO_new_file_sync),
+ JUMP_INIT(doallocate, _IO_file_doallocate),
+ JUMP_INIT(read, _IO_file_read),
+ JUMP_INIT(write, _IO_new_file_write),
+ JUMP_INIT(seek, _IO_file_seek),
+ JUMP_INIT(close, _IO_file_close_mmap),
+ JUMP_INIT(stat, _IO_file_stat),
+ JUMP_INIT(showmanyc, _IO_default_showmanyc),
+ JUMP_INIT(imbue, _IO_default_imbue)
+};
+
#ifdef _LIBC
versioned_symbol (libc, _IO_new_do_write, _IO_do_write, GLIBC_2_1);
versioned_symbol (libc, _IO_new_file_attach, _IO_file_attach, GLIBC_2_1);