]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/mmap.cc
Fixed size mismatch
[apt.git] / apt-pkg / contrib / mmap.cc
index f6def2154750ba33b930145c2abd4de6ba72669b..7a5065ffb219452ffef42c41a3eaef8be0f09e23 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: mmap.cc,v 1.9 1998/11/12 03:14:39 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().
@@ -31,7 +31,6 @@
 
 #include <sys/mman.h>
 #include <sys/stat.h>
-#include <sys/user.h>
 #include <unistd.h>
 #include <fcntl.h>
                                                                        /*}}}*/
@@ -106,9 +105,11 @@ bool MMap::Close(bool DoClose, bool DoSync)
    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;
 }
                                                                        /*}}}*/
@@ -117,9 +118,12 @@ bool MMap::Sync()
 /* */
 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;
 }
                                                                        /*}}}*/
@@ -130,6 +134,9 @@ bool MMap::Sync(unsigned long Start,unsigned long Stop)
 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;