1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00
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.
This commit is contained in:
Ulrich Drepper
2002-01-07 09:33:53 +00:00
parent 463918b5f2
commit 0469311e87
11 changed files with 271 additions and 35 deletions

View File

@ -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;
@ -863,6 +891,17 @@ _IO_file_stat (fp, st)
#endif
}
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);