[dovecot-cvs] dovecot/src/lib mmap-util.c,1.7,1.8 mmap-util.h,1.3,1.4
cras at procontrol.fi
cras at procontrol.fi
Mon Oct 28 11:00:27 EET 2002
Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv12485/lib
Modified Files:
mmap-util.c mmap-util.h
Log Message:
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.
Index: mmap-util.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/mmap-util.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mmap-util.c 14 Sep 2002 11:09:42 -0000 1.7
+++ mmap-util.c 28 Oct 2002 09:00:25 -0000 1.8
@@ -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)
@@ -57,28 +58,6 @@
void *mmap_rw_file(int fd, size_t *length)
{
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
Index: mmap-util.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/mmap-util.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mmap-util.h 14 Sep 2002 11:09:42 -0000 1.3
+++ mmap-util.h 28 Oct 2002 09:00:25 -0000 1.4
@@ -25,11 +25,9 @@
# 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. */
More information about the dovecot-cvs
mailing list