Mercurial > dovecot > original-hg > dovecot-1.2
changeset 543:52fd3d82e59a HEAD
Removed mmap_aligned() which isn't used anywhere. Added mmap_file() which
accepts prot argument. We use now fstat() instead of lseek() to get file
size.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 28 Oct 2002 11:00:25 +0200 |
parents | 14da2c45cdc7 |
children | 42e65c2ba49d |
files | src/lib/mmap-util.c src/lib/mmap-util.h |
diffstat | 2 files changed, 9 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/mmap-util.c Mon Oct 28 10:32:30 2002 +0200 +++ b/src/lib/mmap-util.c Mon Oct 28 11:00:25 2002 +0200 @@ -26,27 +26,28 @@ #include "lib.h" #include "mmap-util.h" -static void *mmap_file(int fd, size_t *length, int access) +#include <sys/stat.h> + +void *mmap_file(int fd, size_t *length, int prot) { - off_t size; + struct stat st; - size = lseek(fd, 0, SEEK_END); - if (size == -1) + if (fstat(fd, &st) < 0) return MAP_FAILED; - if (size > SSIZE_T_MAX) { + if (st.st_size > SSIZE_T_MAX) { /* too large file to map into memory */ errno = EFBIG; return MAP_FAILED; } - *length = (size_t)size; + *length = (size_t)st.st_size; if (*length == 0) return NULL; i_assert(*length > 0 && *length < SSIZE_T_MAX); - return mmap(NULL, *length, access, MAP_SHARED, fd, 0); + return mmap(NULL, *length, prot, MAP_SHARED, fd, 0); } void *mmap_ro_file(int fd, size_t *length) @@ -59,28 +60,6 @@ return mmap_file(fd, length, PROT_READ | PROT_WRITE); } -void *mmap_aligned(int fd, int access, off_t offset, size_t length, - void **data_start, size_t *mmap_length) -{ - void *mmap_base; - static int pagemask = 0; - - if (pagemask == 0) { - pagemask = getpagesize(); - i_assert(pagemask > 0); - pagemask--; - } - - *mmap_length = length + (offset & pagemask); - - mmap_base = mmap(NULL, *mmap_length, access, MAP_SHARED, - fd, offset & ~pagemask); - *data_start = mmap_base == MAP_FAILED || mmap_base == NULL ? NULL : - (char *) mmap_base + (offset & pagemask); - - return mmap_base; -} - #ifndef HAVE_MADVISE int madvise(void *start, size_t length, int advice) {
--- a/src/lib/mmap-util.h Mon Oct 28 10:32:30 2002 +0200 +++ b/src/lib/mmap-util.h Mon Oct 28 11:00:25 2002 +0200 @@ -25,12 +25,10 @@ # endif #endif +void *mmap_file(int fd, size_t *length, int prot); void *mmap_ro_file(int fd, size_t *length); void *mmap_rw_file(int fd, size_t *length); -void *mmap_aligned(int fd, int access, off_t offset, size_t length, - void **data_start, size_t *mmap_length); - /* for allocating anonymous mmap()s, with portable mremap(). these must not be mixed with any standard mmap calls. */ void *mmap_anon(size_t length);