about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-08-30 07:07:16 +0000
committerUlrich Drepper <drepper@redhat.com>2002-08-30 07:07:16 +0000
commitdd0ee2e1022843c6a296a9141b7cab7ea74eec28 (patch)
tree540fab065032d56a49c05c3787e50500e40bc87d
parentb7fc6d07afa8956c5a18d28db02a52d63a70acb8 (diff)
downloadglibc-dd0ee2e1022843c6a296a9141b7cab7ea74eec28.tar.gz
glibc-dd0ee2e1022843c6a296a9141b7cab7ea74eec28.tar.xz
glibc-dd0ee2e1022843c6a296a9141b7cab7ea74eec28.zip
Update.
2002-08-29  Ulrich Drepper  <drepper@redhat.com>

	* libio/fileops.c (_IO_new_file_fopen): Recognize new mode specifier
	'm' to enable mmap I/O.
	* libio/libio.h (_IO_FILE): Rename _blksize field to _flags2.  The
	former wasn't used (anymore?).
	(_IO_FLAGS2_MMAP): New define.
	* libio/genops.c (_IO_no_init): Initialize _flags2 field.
	* libio/iofopen.c (__fopen_maybe_mmap): Use mmap callbacks only if
	_IO_FLAGS2_MMAP bit is set.
	* libio/iofdopen.c (_IO_new_fdopen): Recognize 'm' mode specifier.
	Enable mmap-using mode only if 'm' was set.
-rw-r--r--ChangeLog13
-rw-r--r--libio/genops.c1
-rw-r--r--libio/iofdopen.c31
-rw-r--r--libio/iofopen.c2
-rw-r--r--libio/libio.h6
5 files changed, 47 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 25de4eee0f..9e01dfae7a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2002-08-29  Ulrich Drepper  <drepper@redhat.com>
+
+	* libio/fileops.c (_IO_new_file_fopen): Recognize new mode specifier
+	'm' to enable mmap I/O.
+	* libio/libio.h (_IO_FILE): Rename _blksize field to _flags2.  The
+	former wasn't used (anymore?).
+	(_IO_FLAGS2_MMAP): New define.
+	* libio/genops.c (_IO_no_init): Initialize _flags2 field.
+	* libio/iofopen.c (__fopen_maybe_mmap): Use mmap callbacks only if
+	_IO_FLAGS2_MMAP bit is set.
+	* libio/iofdopen.c (_IO_new_fdopen): Recognize 'm' mode specifier.
+	Enable mmap-using mode only if 'm' was set.
+
 2002-08-29  Roland McGrath  <roland@redhat.com>
 
 	* sysdeps/mach/hurd/i386/init-first.c (_hurd_stack_setup: doinit):
diff --git a/libio/genops.c b/libio/genops.c
index 115c7dfe9a..14e6c0b47f 100644
--- a/libio/genops.c
+++ b/libio/genops.c
@@ -610,6 +610,7 @@ _IO_no_init (fp, flags, orientation, wd, jmp)
      struct _IO_jump_t *jmp;
 {
   fp->_flags = _IO_MAGIC|flags;
+  fp->_flags2 = 0;
   fp->_IO_buf_base = NULL;
   fp->_IO_buf_end = NULL;
   fp->_IO_read_base = NULL;
diff --git a/libio/iofdopen.c b/libio/iofdopen.c
index 2fb493e785..e122562f48 100644
--- a/libio/iofdopen.c
+++ b/libio/iofdopen.c
@@ -59,8 +59,10 @@ _IO_new_fdopen (fd, mode)
     struct _IO_wide_data wd;
   } *new_f;
   int fd_flags;
+  int i;
+  int use_mmap = 0;
 
-  switch (*mode++)
+  switch (*mode)
     {
     case 'r':
       read_write = _IO_NO_WRITES;
@@ -76,8 +78,26 @@ _IO_new_fdopen (fd, mode)
       MAYBE_SET_EINVAL;
       return NULL;
   }
-  if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
-    read_write &= _IO_IS_APPENDING;
+  for (i = 1; i < 5; ++i)
+    {
+      switch (*++mode)
+	{
+	case '\0':
+	  break;
+	case '+':
+	  read_write &= _IO_IS_APPENDING;
+	  break;
+	case 'm':
+	  use_mmap = 1;
+	  continue;
+	case 'x':
+	case 'b':
+	default:
+	  /* Ignore */
+	  continue;
+	}
+      break;
+    }
 #ifdef F_GETFL
   fd_flags = _IO_fcntl (fd, F_GETFL);
 #ifndef O_ACCMODE
@@ -129,12 +149,13 @@ _IO_new_fdopen (fd, mode)
      call _IO_file_attach or else it will allocate a buffer immediately.  */
   _IO_no_init (&new_f->fp.file, 0, 0, &new_f->wd,
 #ifdef _G_HAVE_MMAP
-	       (read_write & _IO_NO_WRITES) ? &_IO_wfile_jumps_maybe_mmap :
+	       (use_mmap && (read_write & _IO_NO_WRITES))
+	       ? &_IO_wfile_jumps_maybe_mmap :
 #endif
 	       &INTUSE(_IO_wfile_jumps));
   _IO_JUMPS (&new_f->fp) =
 #ifdef _G_HAVE_MMAP
-    (read_write & _IO_NO_WRITES) ? &_IO_file_jumps_maybe_mmap :
+    (use_mmap && (read_write & _IO_NO_WRITES)) ? &_IO_file_jumps_maybe_mmap :
 #endif
       &INTUSE(_IO_file_jumps);
   INTUSE(_IO_file_init) (&new_f->fp);
diff --git a/libio/iofopen.c b/libio/iofopen.c
index 00a2c5f073..8cd68a3690 100644
--- a/libio/iofopen.c
+++ b/libio/iofopen.c
@@ -41,7 +41,7 @@ __fopen_maybe_mmap (fp)
      _IO_FILE *fp;
 {
 #ifdef _G_HAVE_MMAP
-  if (fp->_flags & _IO_NO_WRITES)
+  if ((fp->_flags2 & _IO_FLAGS2_MMAP) && (fp->_flags & _IO_NO_WRITES))
     {
       /* Since this is read-only, we might be able to mmap the contents
 	 directly.  We delay the decision until the first read attempt by
diff --git a/libio/libio.h b/libio/libio.h
index c8231df3ab..3c6bef9b37 100644
--- a/libio/libio.h
+++ b/libio/libio.h
@@ -137,6 +137,8 @@
 #define _IO_BAD_SEEN 0x4000
 #define _IO_USER_LOCK 0x8000
 
+#define _IO_FLAGS2_MMAP 1
+
 /* These are "formatting flags" matching the iostream fmtflags enum values. */
 #define _IO_SKIPWS 01
 #define _IO_LEFT 02
@@ -282,7 +284,11 @@ struct _IO_FILE {
   struct _IO_FILE *_chain;
 
   int _fileno;
+#if 0
   int _blksize;
+#else
+  int _flags2;
+#endif
   _IO_off_t _old_offset; /* This used to be _offset but it's too small.  */
 
 #define __HAVE_COLUMN /* temporary */