diff options
-rw-r--r-- | aclocal.m4 | 28 | ||||
-rw-r--r-- | configure.in | 13 | ||||
-rw-r--r-- | include/apr_mmap.h | 12 | ||||
-rw-r--r-- | include/arch/unix/mmap.c | 97 | ||||
-rw-r--r-- | mmap/beos/mmap.c | 139 | ||||
-rw-r--r-- | mmap/beos/mmap_h.h | 3 | ||||
-rw-r--r-- | mmap/unix/common.c | 30 | ||||
-rw-r--r-- | mmap/unix/mmap.c | 97 | ||||
-rw-r--r-- | mmap/unix/mmap_h.h | 3 |
9 files changed, 59 insertions, 363 deletions
diff --git a/aclocal.m4 b/aclocal.m4 index e4e5174f2..d1eb0cdc2 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -133,6 +133,32 @@ ifelse([$3], , , [ $3 ])dnl fi rm -fr conftest*]) - +dnl A variant of AC_CHECK_SIZEOF which allows the checking of +dnl sizes of non-builtin types +dnl AC_CHECK_SIZEOF_EXTENDED(INCLUDES, TYPE [, CROSS_SIZE]) +AC_DEFUN(AC_CHECK_SIZEOF_EXTENDED, +[changequote(<<,>>)dnl +dnl The name to #define +define(<<AC_TYPE_NAME>>, translit(sizeof_$2, [a-z *], [A-Z_P]))dnl +dnl The cache variable +define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$2, [ *],[<p>]))dnl +changequote([, ])dnl +AC_MSG_CHECKING(size of $2) +AC_CACHE_VAL(AC_CV_NAME, +[AC_TRY_RUN([#include <stdio.h> +$1 +main() +{ + FILE *f=fopen("conftestval","w"); + if (!f) exit(1); + fprintf(f, "%d\n", sizeof($2)); + exit(0); +}], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=0, ifelse([$3],,, +AC_CV_NAME=$3))])dnl +AC_MSG_RESULT($AC_CV_NAME) +AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME) +undefine([AC_TYPE_NAME])dnl +undefine([AC_CV_NAME])dnl +]) diff --git a/configure.in b/configure.in index 5260a1b53..53542d13f 100644 --- a/configure.in +++ b/configure.in @@ -57,18 +57,7 @@ AC_CHECK_SIZEOF(short, 2) AC_CHECK_SIZEOF(long double, 12) AC_CHECK_SIZEOF(long long, 8) -MY_TRY_RUN([ -#include <sys/types.h> -#include <stdlib.h> -#include <stdio.h> - -int main() { - return(sizeof(ssize_t)); -} -], -AC_DEFINE(SIZEOF_SSIZE_T, 4), -AC_DEFINE_UNQUOTED(SIZEOF_SSIZE_T, $?), -AC_DEFINE(SIZEOF_SSIZE_T, 4)) +AC_CHECK_SIZEOF_EXTENDED([#include <sys/types.h>], ssize_t, 8) # Use /bin/sh if it exists, otherwise go looking for sh in the path if test ".$SH" = . -a -f /bin/sh; then diff --git a/include/apr_mmap.h b/include/apr_mmap.h index 3d8d119b5..7b3073b8c 100644 --- a/include/apr_mmap.h +++ b/include/apr_mmap.h @@ -71,19 +71,13 @@ typedef struct mmap_t ap_mmap_t; /* Function definitions */ /* creation */ -ap_status_t ap_mmap_create(ap_mmap_t ** newmmap, const char *fname, ap_context_t *cntxt); -ap_status_t ap_mmap_open_create(ap_mmap_t **newmmap, ap_file_t *file, ap_context_t *cntxt); -ap_status_t ap_mmap_size_create(ap_mmap_t **newmmap, ap_file_t *file, ap_size_t size, - ap_context_t *cntxt); +ap_status_t ap_mmap_create(ap_mmap_t ** newmmap, ap_file_t *file, ap_off_t offset, + ap_size_t size, ap_context_t *cntxt); /* destruction */ ap_status_t ap_mmap_delete(ap_mmap_t *mmap); -/* These are designed to be used in qsort, bsearch etc */ -ap_int32_t ap_mmap_inode_compare(const void *m1, const void *m2); -ap_int32_t ap_mmap_filename_compare(const void *m1, const void *m2); - -ap_status_t ap_mmap_offset(void **addr, ap_mmap_t *mmap, ap_size_t offset); +ap_status_t ap_mmap_offset(void **addr, ap_mmap_t *mmap, ap_off_t offset); #ifdef __cplusplus } diff --git a/include/arch/unix/mmap.c b/include/arch/unix/mmap.c index 75d8efbf7..846cf78b4 100644 --- a/include/arch/unix/mmap.c +++ b/include/arch/unix/mmap.c @@ -87,111 +87,28 @@ ap_status_t mmap_cleanup(void *themmap) return errno; } -ap_status_t ap_mmap_create(ap_mmap_t **new, const char * fname, - ap_context_t *cont) +ap_status_t ap_mmap_create(ap_mmap_t **new, ap_file_t *file, ap_off_t offset, + ap_size_t size, ap_context_t *cont) { - struct stat st; int fd; caddr_t mm; - (*new) = (struct mmap_t *)ap_palloc(cont, sizeof(struct mmap_t)); - - if (stat(fname, &st) == -1) { - /* we couldn't stat the file...probably doesn't exist! */ - return APR_ENOFILE; - } - if ((st.st_mode & S_IFMT) != S_IFREG) { - /* oh dear, we're only doing regular files at present... */ + if (file == NULL || file->buffered || file->filedes == -1) return APR_EBADF; - } - if ((fd = open(fname, O_RDONLY, 0)) == -1) { - return APR_EBADF; - } - mm = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd ,0); - close (fd); - if (mm == (caddr_t)-1) { - /* we failed to get an mmap'd file... */ - return APR_ENOMEM; - } - (*new)->filename = ap_pstrdup(cont, fname); - (*new)->mm = mm; - (*new)->sinfo = st; - (*new)->size = st.st_size; - (*new)->cntxt = cont; - /* register the cleanup... */ - ap_register_cleanup((*new)->cntxt, (void*)(*new), mmap_cleanup, - ap_null_cleanup); - return APR_SUCCESS; -} - -ap_status_t ap_mmap_open_create(struct mmap_t **new, ap_file_t *file, - ap_context_t *cont) -{ - caddr_t mm; - - if (file->buffered) - /* we don't yet mmap buffered files... */ - return APR_EBADF; - if (file->filedes == -1) - /* there isn't a file handle so how can we mmap?? */ - return APR_EBADF; - (*new) = (struct mmap_t*)ap_palloc(cont, sizeof(struct mmap_t)); + (*new) = (struct mmap_t *)ap_palloc(cont, sizeof(struct mmap_t)); - if (!file->stated) { - /* hmmmm... we need to stat the file now */ - struct stat st; - if (stat(file->fname, &st) == -1) { - /* hmm, is this fatal?? */ - return APR_EBADF; - } - file->stated = 1; - file->size = st.st_size; - file->atime = st.st_atime; - file->mtime = st.st_mtime; - file->ctime = st.st_ctime; - (*new)->sinfo = st; - } + ap_seek(file, APR_SET, &offset); + mm = mmap(NULL, size, PROT_READ, MAP_SHARED, file->filedes ,0); - mm = mmap(NULL, file->size, PROT_READ, MAP_SHARED, file->filedes ,0); if (mm == (caddr_t)-1) { /* we failed to get an mmap'd file... */ return APR_ENOMEM; } - - (*new)->filename = ap_pstrdup(cont, file->fname); (*new)->mm = mm; - (*new)->size = file->size; + (*new)->size = size; (*new)->cntxt = cont; - - /* register the cleanup... */ - ap_register_cleanup((*new)->cntxt, (void*)(*new), mmap_cleanup, - ap_null_cleanup); - return APR_SUCCESS; -} - -ap_status_t ap_mmap_size_create(ap_mmap_t **new, ap_file_t *file, ap_size_t mmapsize, - ap_context_t *cont) -{ - caddr_t mm; - if (file->buffered) - return APR_EBADF; - if (file->filedes == -1) - return APR_EBADF; - - (*new) = (struct mmap_t*)ap_palloc(cont, sizeof(struct mmap_t)); - - mm = mmap(NULL, mmapsize, PROT_READ, MAP_SHARED, file->filedes ,0); - if (mm == (caddr_t)-1) { - return APR_ENOMEM; - } - - (*new)->filename = ap_pstrdup(cont, file->fname); - (*new)->mm = mm; - (*new)->size = mmapsize; - (*new)->cntxt = cont; - /* register the cleanup... */ ap_register_cleanup((*new)->cntxt, (void*)(*new), mmap_cleanup, ap_null_cleanup); diff --git a/mmap/beos/mmap.c b/mmap/beos/mmap.c index facb71939..dd95c3c24 100644 --- a/mmap/beos/mmap.c +++ b/mmap/beos/mmap.c @@ -79,151 +79,38 @@ ap_status_t mmap_cleanup(void *themmap) return errno; } -ap_status_t ap_mmap_create(struct mmap_t **new, const char *fname, - ap_context_t *cont) +ap_status_t ap_mmap_create(struct mmap_t **new, ap_file_t *file, ap_off_t offset, ap_size_t size, + ap_context_t *cont) { - struct stat st; - int fd = -1; void *mm; area_id aid = -1; char *areaname = "apr_mmap\0"; - uint32 size = 0; + uint32 pages = 0; + if (file == NULL || file->buffered || file->filedes == -1) + return APR_EBADF; (*new) = (struct mmap_t *)ap_palloc(cont, sizeof(struct mmap_t)); - if (stat(fname, &st) == -1) { - /* we couldn't stat the file...probably doesn't exist! */ - return APR_ENOFILE; - } - if ((st.st_mode & S_IFMT) != S_IFREG) { - /* oh dear, we're only doing regular files at present... */ - return APR_EBADF; - } - size = ((st.st_size -1) / B_PAGE_SIZE) + 1; + pages = ((size -1) / B_PAGE_SIZE) + 1; - if ((fd = open(fname, O_RDONLY, 0)) == -1) { - return APR_EBADF; - } - - aid = create_area(areaname, &mm , B_ANY_ADDRESS, size * B_PAGE_SIZE, + ap_seek(file, APR_SET, &offset); + + aid = create_area(areaname, &mm , B_ANY_ADDRESS, pages * B_PAGE_SIZE, B_FULL_LOCK, B_READ_AREA|B_WRITE_AREA); - if (aid >= B_NO_ERROR) - read(fd, mm, st.st_size); - - close (fd); if (aid < B_NO_ERROR) { /* we failed to get an mmap'd file... */ return APR_ENOMEM; - } - - (*new)->filename = ap_pstrdup(cont, fname); - (*new)->mm = mm; - (*new)->sinfo = st; - (*new)->size = st.st_size; - (*new)->area = aid; - (*new)->cntxt = cont; - (*new)->statted = 1; - - /* register the cleanup... */ - ap_register_cleanup((*new)->cntxt, (void*)(*new), mmap_cleanup, - ap_null_cleanup); - - return APR_SUCCESS; -} - -ap_status_t ap_mmap_open_create(struct mmap_t **new, ap_file_t *file, - ap_context_t *cont) -{ - char *mm; - area_id aid = -1; - char *areaname = "apr_mmap\0"; - uint32 size; - - if (file->buffered) - /* we don't yet mmap buffered files... */ - return APR_EBADF; - if (file->filedes == -1) - /* there isn't a file handle so how can we mmap?? */ - return APR_EBADF; - (*new) = (struct mmap_t*)ap_palloc(cont, sizeof(struct mmap_t)); - - if (!file->stated) { - /* hmmmm... we need to stat the file now */ - struct stat st; - if (stat(file->fname, &st) == -1) { - /* hmm, is this fatal?? */ - return APR_EBADF; - } - file->stated = 1; - file->size = st.st_size; - file->atime = st.st_atime; - file->mtime = st.st_mtime; - file->ctime = st.st_ctime; - (*new)->sinfo = st; } - - size = ((file->size -1) / B_PAGE_SIZE) + 1; - - aid = create_area(areaname, (void*)&mm, B_ANY_ADDRESS, size * B_PAGE_SIZE, - B_FULL_LOCK, B_READ_AREA|B_WRITE_AREA); - free(areaname); - - if (aid < B_OK) { - /* we failed to get an mmap'd file... */ - return APR_ENOMEM; - } - if (aid >= B_OK) - read(file->filedes, mm, file->size); - - (*new)->filename = ap_pstrdup(cont, file->fname); - (*new)->mm = mm; - (*new)->size = file->size; - (*new)->area = aid; - (*new)->cntxt = cont; - (*new)->statted = 1; - - /* register the cleanup... */ - ap_register_cleanup((*new)->cntxt, (void*)(*new), mmap_cleanup, - ap_null_cleanup); - - return APR_SUCCESS; -} - -ap_status_t ap_mmap_size_create(ap_mmap_t **new, ap_file_t *file, ap_size_t mmapsize, - ap_context_t *cont) -{ - char *mm; - area_id aid = -1; - char *areaname = "apr_mmap\0"; - uint32 size; - - if (file->buffered) - return APR_EBADF; - if (file->filedes == -1) - return APR_EBADF; - (*new) = (struct mmap_t*)ap_palloc(cont, sizeof(struct mmap_t)); - size = ((mmapsize -1) / B_PAGE_SIZE) + 1; - - aid = create_area(areaname, (void*)&mm, B_ANY_ADDRESS, size * B_PAGE_SIZE, - B_FULL_LOCK, B_READ_AREA|B_WRITE_AREA); - free(areaname); - - if (aid < B_OK) { - /* we failed to get an mmap'd file... */ - return APR_ENOMEM; - } - if (aid >= B_OK) - read(file->filedes, mm, mmapsize); + if (aid >= B_NO_ERROR) + read(file->filedes, mm, size); - (*new)->filename = ap_pstrdup(cont, file->fname); (*new)->mm = mm; - (*new)->size = mmapsize; + (*new)->size = size; (*new)->area = aid; (*new)->cntxt = cont; - (*new)->statted = 0; - + /* register the cleanup... */ ap_register_cleanup((*new)->cntxt, (void*)(*new), mmap_cleanup, ap_null_cleanup); diff --git a/mmap/beos/mmap_h.h b/mmap/beos/mmap_h.h index af9007302..37a9e77b8 100644 --- a/mmap/beos/mmap_h.h +++ b/mmap/beos/mmap_h.h @@ -64,12 +64,9 @@ struct mmap_t { ap_context_t *cntxt; - char *filename; /* the full path to the file */ - struct stat sinfo; area_id area; void *mm; size_t size; - ap_int32_t statted; }; ap_status_t mmap_cleanup(void *); diff --git a/mmap/unix/common.c b/mmap/unix/common.c index 012d8c0b2..39e73d4aa 100644 --- a/mmap/unix/common.c +++ b/mmap/unix/common.c @@ -87,35 +87,7 @@ #if HAVE_MMAP -ap_int32_t ap_mmap_inode_compare(const void *m1, const void *m2) -{ - const ap_mmap_t *a = *(ap_mmap_t **)m1; - const ap_mmap_t *b = *(ap_mmap_t **)m2; - ap_int32_t c; - - if (a->statted == 0 || b->statted == 0) { - /* we can't do this as we have no stat info... */ - /* what do we return??? */ - return (-1); - } - c = a->sinfo.st_ino - b->sinfo.st_ino; - if (c == 0) { - return a->sinfo.st_dev - b->sinfo.st_dev; - } - return c; -} - -ap_int32_t ap_mmap_filename_compare(const void *m1, const void *m2) -{ - const ap_mmap_t *a = m1; - const ap_mmap_t *b = m2; - - return strcmp(a->filename, b->filename); -} - - - -ap_status_t ap_mmap_offset(void **addr, ap_mmap_t *mmap, ap_size_t offset) +ap_status_t ap_mmap_offset(void **addr, ap_mmap_t *mmap, ap_off_t offset) { if (offset < 0 || offset > mmap->size) return APR_EINVAL; diff --git a/mmap/unix/mmap.c b/mmap/unix/mmap.c index 75d8efbf7..846cf78b4 100644 --- a/mmap/unix/mmap.c +++ b/mmap/unix/mmap.c @@ -87,111 +87,28 @@ ap_status_t mmap_cleanup(void *themmap) return errno; } -ap_status_t ap_mmap_create(ap_mmap_t **new, const char * fname, - ap_context_t *cont) +ap_status_t ap_mmap_create(ap_mmap_t **new, ap_file_t *file, ap_off_t offset, + ap_size_t size, ap_context_t *cont) { - struct stat st; int fd; caddr_t mm; - (*new) = (struct mmap_t *)ap_palloc(cont, sizeof(struct mmap_t)); - - if (stat(fname, &st) == -1) { - /* we couldn't stat the file...probably doesn't exist! */ - return APR_ENOFILE; - } - if ((st.st_mode & S_IFMT) != S_IFREG) { - /* oh dear, we're only doing regular files at present... */ + if (file == NULL || file->buffered || file->filedes == -1) return APR_EBADF; - } - if ((fd = open(fname, O_RDONLY, 0)) == -1) { - return APR_EBADF; - } - mm = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd ,0); - close (fd); - if (mm == (caddr_t)-1) { - /* we failed to get an mmap'd file... */ - return APR_ENOMEM; - } - (*new)->filename = ap_pstrdup(cont, fname); - (*new)->mm = mm; - (*new)->sinfo = st; - (*new)->size = st.st_size; - (*new)->cntxt = cont; - /* register the cleanup... */ - ap_register_cleanup((*new)->cntxt, (void*)(*new), mmap_cleanup, - ap_null_cleanup); - return APR_SUCCESS; -} - -ap_status_t ap_mmap_open_create(struct mmap_t **new, ap_file_t *file, - ap_context_t *cont) -{ - caddr_t mm; - - if (file->buffered) - /* we don't yet mmap buffered files... */ - return APR_EBADF; - if (file->filedes == -1) - /* there isn't a file handle so how can we mmap?? */ - return APR_EBADF; - (*new) = (struct mmap_t*)ap_palloc(cont, sizeof(struct mmap_t)); + (*new) = (struct mmap_t *)ap_palloc(cont, sizeof(struct mmap_t)); - if (!file->stated) { - /* hmmmm... we need to stat the file now */ - struct stat st; - if (stat(file->fname, &st) == -1) { - /* hmm, is this fatal?? */ - return APR_EBADF; - } - file->stated = 1; - file->size = st.st_size; - file->atime = st.st_atime; - file->mtime = st.st_mtime; - file->ctime = st.st_ctime; - (*new)->sinfo = st; - } + ap_seek(file, APR_SET, &offset); + mm = mmap(NULL, size, PROT_READ, MAP_SHARED, file->filedes ,0); - mm = mmap(NULL, file->size, PROT_READ, MAP_SHARED, file->filedes ,0); if (mm == (caddr_t)-1) { /* we failed to get an mmap'd file... */ return APR_ENOMEM; } - - (*new)->filename = ap_pstrdup(cont, file->fname); (*new)->mm = mm; - (*new)->size = file->size; + (*new)->size = size; (*new)->cntxt = cont; - - /* register the cleanup... */ - ap_register_cleanup((*new)->cntxt, (void*)(*new), mmap_cleanup, - ap_null_cleanup); - return APR_SUCCESS; -} - -ap_status_t ap_mmap_size_create(ap_mmap_t **new, ap_file_t *file, ap_size_t mmapsize, - ap_context_t *cont) -{ - caddr_t mm; - if (file->buffered) - return APR_EBADF; - if (file->filedes == -1) - return APR_EBADF; - - (*new) = (struct mmap_t*)ap_palloc(cont, sizeof(struct mmap_t)); - - mm = mmap(NULL, mmapsize, PROT_READ, MAP_SHARED, file->filedes ,0); - if (mm == (caddr_t)-1) { - return APR_ENOMEM; - } - - (*new)->filename = ap_pstrdup(cont, file->fname); - (*new)->mm = mm; - (*new)->size = mmapsize; - (*new)->cntxt = cont; - /* register the cleanup... */ ap_register_cleanup((*new)->cntxt, (void*)(*new), mmap_cleanup, ap_null_cleanup); diff --git a/mmap/unix/mmap_h.h b/mmap/unix/mmap_h.h index a29e86ab0..96a7e9aa1 100644 --- a/mmap/unix/mmap_h.h +++ b/mmap/unix/mmap_h.h @@ -65,11 +65,8 @@ struct mmap_t { ap_context_t *cntxt; - char *filename; /* the full path to the file */ - struct stat sinfo; void *mm; size_t size; - ap_int32_t statted; }; ap_status_t mmap_cleanup(void *); |