// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: mmap.cc,v 1.7 1998/07/19 04:42:14 jgg Exp $
+// $Id: mmap.cc,v 1.14 1999/03/18 04:32:46 jgg Exp $
/* ######################################################################
MMap Class - Provides 'real' mmap or a faked mmap using read().
#include <sys/mman.h>
#include <sys/stat.h>
-#include <sys/user.h>
#include <unistd.h>
#include <fcntl.h>
/*}}}*/
if ((Flags & Public) != Public)
Map = MAP_PRIVATE;
+ if (iSize == 0)
+ return _error->Error("Can't mmap an empty file");
+
// Map it.
Base = mmap(0,iSize,Prot,Map,Fd.Fd(),0);
if (Base == (void *)-1)
not return till all IO is complete */
bool MMap::Sync()
{
+#ifdef _POSIX_SYNCHRONIZED_IO
if ((Flags & ReadOnly) != ReadOnly)
if (msync((char *)Base,iSize,MS_SYNC) != 0)
return _error->Error("msync","Unable to write mmap");
+#endif
return true;
}
/*}}}*/
/* */
bool MMap::Sync(unsigned long Start,unsigned long Stop)
{
+#ifdef _POSIX_SYNCHRONIZED_IO
+ unsigned long PSize = sysconf(_SC_PAGESIZE);
if ((Flags & ReadOnly) != ReadOnly)
- if (msync((char *)Base+(int)(Start/PAGE_SIZE)*PAGE_SIZE,Stop - Start,MS_SYNC) != 0)
+ if (msync((char *)Base+(int)(Start/PSize)*PSize,Stop - Start,MS_SYNC) != 0)
return _error->Error("msync","Unable to write mmap");
+#endif
return true;
}
/*}}}*/
DynamicMMap::DynamicMMap(FileFd &F,unsigned long Flags,unsigned long WorkSpace) :
MMap(F,Flags | NoImmMap), WorkSpace(WorkSpace)
{
+ if (_error->PendingError() == true)
+ return;
+
unsigned long EndOfFile = Fd.Size();
Fd.Seek(WorkSpace);
char C = 0;
iSize = Result + Size;
// Just in case error check
- if (Result > WorkSpace)
+ if (Result + Size > WorkSpace)
{
_error->Error("Dynamic MMap ran out of room");
return 0;