The following patch makes the call to mmap in mmap.c actually use the
native_flags variable generated just above it, rather than always using
only READ.  If in fact it's not valid to use APR_MMAP_WRITE, then it
should probably be documented as such, and the code which sets
native_flags should go away.

The code which sets native flags if BEOS is set has similar issues --
but it's got a comment explaining that in fact both values are always
needed ... if in fact both are needed, it seems wrong to calculate
native_flags only to ignore the value.  So this patch removes that code.

This was pointed out to me by Jesse Burns <[EMAIL PROTECTED]>.

It compiles on linux; I'm working on testing.

thanks --

Ed

Index: mmap.c
===================================================================
RCS file: /home/cvspublic/apr/mmap/unix/mmap.c,v
retrieving revision 1.34
diff -u -r1.34 mmap.c
--- mmap.c      2001/02/25 20:39:35     1.34
+++ mmap.c      2001/03/28 09:39:57
@@ -105,13 +105,12 @@
                              apr_off_t offset, apr_size_t size, 
                              apr_int32_t flag, apr_pool_t *cont)
 {
-    apr_int32_t native_flags = 0;
-#ifdef BEOS
     void *mm;
+#ifdef BEOS
     area_id aid = -1;
     uint32 pages = 0;
 #else
-    void *mm;
+    apr_int32_t native_flags = 0;
 #endif
    
     if (file == NULL || file->filedes == -1 || file->buffered)
@@ -121,15 +120,10 @@
 #ifdef BEOS
     /* XXX: mmap shouldn't really change the seek offset */
     apr_file_seek(file, APR_SET, &offset);
-    if (flag & APR_MMAP_WRITE) {
-        native_flags |= B_WRITE_AREA;
-    }
-    if (flag & APR_MMAP_READ) {
-        native_flags |= B_READ_AREA;
-    }
 
     /* There seems to be some strange interactions that mean our area must
      * be set as READ & WRITE or writev will fail!  Go figure...
+     * So we ignore the value in flags and always ask for both READ and WRITE.
      */
     pages = (size + B_PAGE_SIZE -1) / B_PAGE_SIZE;
     aid = create_area("apr_mmap", &mm , B_ANY_ADDRESS, pages * B_PAGE_SIZE,
@@ -153,7 +147,7 @@
         native_flags |= PROT_READ;
     }
 
-    mm = mmap(NULL, size, PROT_READ, MAP_SHARED, file->filedes, offset);
+    mm = mmap(NULL, size, native_flags, MAP_SHARED, file->filedes, offset);
 
     if (mm == (void *)-1) {
         /* we failed to get an mmap'd file... */

Reply via email to