From 3342df63ef34b217234f01a79a27c2f8725d3c6d Mon Sep 17 00:00:00 2001
From: Olivier Bertrand <bertrandop@gmail.com>
Date: Fri, 8 Mar 2013 18:29:05 +0100
Subject: [PATCH] - Commit changes on memory mapping that hopefully should now
 work on Linux.

modified:
  storage/connect/maputil.cpp
  storage/connect/tabdos.cpp
  storage/connect/tabfmt.cpp
  storage/connect/tabvct.cpp
---
 storage/connect/maputil.cpp | 6 +++---
 storage/connect/tabdos.cpp  | 6 +-----
 storage/connect/tabfmt.cpp  | 4 ----
 storage/connect/tabvct.cpp  | 4 ----
 4 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/storage/connect/maputil.cpp b/storage/connect/maputil.cpp
index 69ab2fad87f..b7032f10d2b 100755
--- a/storage/connect/maputil.cpp
+++ b/storage/connect/maputil.cpp
@@ -159,9 +159,9 @@ HANDLE CreateFileMap(PGLOBAL g, LPCSTR fileName,
     
     // Now we are ready to load the file.  If mmap() is available we try
     //   this first.  If not available or it failed we try to load it.
-    mm->memory = mmap(NULL, filesize, protmode, MAP_PRIVATE, fd, 0);
+    mm->memory = mmap(NULL, filesize, protmode, MAP_SHARED, fd, 0);
 
-    if (mm->memory) {
+    if (mm->memory != MAP_FAILED) {
       mm->lenL = (mm->memory != 0) ? filesize : 0;
       mm->lenH = 0;
     } else {
@@ -180,7 +180,7 @@ bool CloseMemMap(void *memory, size_t dwSize)
   if (memory) {
     // All this must be redesigned
     int rc = msync(memory, dwSize, MS_SYNC);
-    return (munmap(memory, dwSize)) ? true : false;
+    return (munmap(memory, dwSize) < 0) ? true : false;
   } else
     return false;
 
diff --git a/storage/connect/tabdos.cpp b/storage/connect/tabdos.cpp
index a64d500e05c..be343690f08 100644
--- a/storage/connect/tabdos.cpp
+++ b/storage/connect/tabdos.cpp
@@ -284,15 +284,11 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
   {
   // Mapping not used for insert
   USETEMP tmp = PlgGetUser(g)->UseTemp;
-#if defined(WIN32)
   bool    map = Mapped && mode != MODE_INSERT &&
                 !(tmp != TMP_NO && Recfm == RECFM_VAR
-                       && mode == MODE_UPDATE) &&
+                                && mode == MODE_UPDATE) &&
                 !(tmp == TMP_FORCE &&
                 (mode == MODE_UPDATE || mode == MODE_DELETE));
-#else   // !WIN32
-  bool    map = Mapped && mode == MODE_READ;
-#endif  // !WIN32
   PTXF    txfp;
   PTDBASE tdbp;
 
diff --git a/storage/connect/tabfmt.cpp b/storage/connect/tabfmt.cpp
index fc31fd52080..a046fe771e5 100644
--- a/storage/connect/tabfmt.cpp
+++ b/storage/connect/tabfmt.cpp
@@ -444,14 +444,10 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
 
   if (Catfunc != FNC_COL) {
     USETEMP tmp = PlgGetUser(g)->UseTemp;
-#if defined(WIN32)
     bool    map = Mapped && mode != MODE_INSERT &&
                   !(tmp != TMP_NO && mode == MODE_UPDATE) &&
                   !(tmp == TMP_FORCE &&
                   (mode == MODE_UPDATE || mode == MODE_DELETE));
-#else   // !WIN32
-    bool    map = Mapped && mode == MODE_READ;
-#endif  // !WIN32
     PTXF    txfp;
 
     /*******************************************************************/
diff --git a/storage/connect/tabvct.cpp b/storage/connect/tabvct.cpp
index 9d8405c699d..c06f7bbead1 100644
--- a/storage/connect/tabvct.cpp
+++ b/storage/connect/tabvct.cpp
@@ -197,13 +197,9 @@ PTDB VCTDEF::GetTable(PGLOBAL g, MODE mode)
   /*********************************************************************/
   // Mapping not used for insert (except for true VEC not split tables)
   // or when UseTemp is forced
-#if defined(WIN32)
   bool map = Mapped && (Estimate || mode != MODE_INSERT) &&
              !(PlgGetUser(g)->UseTemp == TMP_FORCE &&
              (mode == MODE_UPDATE || mode == MODE_DELETE));
-#else   // !WIN32
-  bool map = Mapped && mode == MODE_READ;
-#endif  // !WIN32
   PTXF txfp;
   PTDB tdbp;
 
-- 
2.30.9