rbb 00/12/06 21:00:28
Modified: . CHANGES
include apr_mmap.h
mmap/unix mmap.c
test testmmap.c
Log:
Allow APR programmers to determine if an MMAP is read-only or if it should
be write-able.
Submitted by: Ryan Bloom and Will Rowe
Revision Changes Path
1.16 +4 -0 apr/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr/CHANGES,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- CHANGES 2000/12/05 23:15:03 1.15
+++ CHANGES 2000/12/07 05:00:27 1.16
@@ -1,4 +1,8 @@
Changes with APR a9
+ *) Allow the APR programmer to specify if the MMAP is read-only or
+ write-able.
+ [Ryan Bloom and Will Rowe]
+
*) Check more carefully for getaddrinfo(). Accept those that
require <netdb.h> to be included (e.g., Tru64). Reject those that
fail a very basic operational test (e.g., AIX). [Jeff Trawick]
1.18 +11 -2 apr/include/apr_mmap.h
Index: apr_mmap.h
===================================================================
RCS file: /home/cvs/apr/include/apr_mmap.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- apr_mmap.h 2000/12/02 19:02:27 1.17
+++ apr_mmap.h 2000/12/07 05:00:27 1.18
@@ -68,6 +68,9 @@
extern "C" {
#endif /* __cplusplus */
+#define APR_MMAP_READ 1
+#define APR_MMAP_WRITE 2
+
/**
* @package APR MMAP library
*/
@@ -103,10 +106,16 @@
* @param file The file turn into an mmap.
* @param offset The offset into the file to start the data pointer at.
* @param size The size of the file
+ * @param flag bit-wise or of:
+ * <PRE>
+ * APR_MMAP_READ MMap opened for reading
+ * APR_MMAP_WRITE MMap opened for writing
+ * </PRE>
* @param cntxt The pool to use when creating the mmap.
*/
-apr_status_t apr_mmap_create(apr_mmap_t ** newmmap, apr_file_t *file,
apr_off_t offset,
- apr_size_t size, apr_pool_t *cntxt);
+apr_status_t apr_mmap_create(apr_mmap_t ** newmmap, apr_file_t *file,
+ apr_off_t offset, apr_size_t size,
+ apr_int32_t flag, apr_pool_t *cntxt);
/**
* Remove a mmap'ed.
1.28 +19 -3 apr/mmap/unix/mmap.c
Index: mmap.c
===================================================================
RCS file: /home/cvs/apr/mmap/unix/mmap.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- mmap.c 2000/11/09 21:26:50 1.27
+++ mmap.c 2000/12/07 05:00:28 1.28
@@ -101,9 +101,11 @@
return errno;
}
-apr_status_t apr_mmap_create(apr_mmap_t **new, apr_file_t *file, apr_off_t
offset,
- apr_size_t size, apr_pool_t *cont)
+apr_status_t apr_mmap_create(apr_mmap_t **new, apr_file_t *file,
+ 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;
area_id aid = -1;
@@ -122,8 +124,15 @@
apr_seek(file, APR_SET, &offset);
pages = ((size -1) / B_PAGE_SIZE) + 1;
+ if (flag & APR_MMAP_WRITE) {
+ native_flags |= B_WRITE_AREA;
+ }
+ if (flag & APR_MMAP_READ) {
+ native_flags |= B_READ_AREA;
+ }
+
aid = create_area(areaname, &mm , B_ANY_ADDRESS, pages * B_PAGE_SIZE,
- B_FULL_LOCK, B_READ_AREA|B_WRITE_AREA);
+ B_FULL_LOCK, native_flags);
if (aid < B_NO_ERROR) {
/* we failed to get an mmap'd file... */
@@ -134,6 +143,13 @@
read(file->filedes, mm, size);
(*new)->area = aid;
#else
+
+ if (flag & APR_MMAP_WRITE) {
+ native_flags |= PROT_WRITE;
+ }
+ if (flag & APR_MMAP_READ) {
+ native_flags |= PROT_READ;
+ }
mm = mmap(NULL, size, PROT_READ, MAP_SHARED, file->filedes, offset);
1.17 +2 -1 apr/test/testmmap.c
Index: testmmap.c
===================================================================
RCS file: /home/cvs/apr/test/testmmap.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- testmmap.c 2000/12/04 22:59:58 1.16
+++ testmmap.c 2000/12/07 05:00:28 1.17
@@ -52,6 +52,7 @@
* <http://www.apache.org/>.
*/
+#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -116,7 +117,7 @@
}
fprintf(stdout,"Trying to mmap the file.............");
- if (apr_mmap_create(&themmap, thefile, 0, finfo.size, context) !=
APR_SUCCESS) {
+ if (apr_mmap_create(&themmap, thefile, 0, finfo.size, APR_MMAP_READ,
context) != APR_SUCCESS) {
fprintf(stderr,"Failed!\n");
exit(-1);
}