Index: /trunk/psLib/src/types/psMetadataConfig.c
===================================================================
--- /trunk/psLib/src/types/psMetadataConfig.c	(revision 11151)
+++ /trunk/psLib/src/types/psMetadataConfig.c	(revision 11152)
@@ -10,6 +10,6 @@
 *  @author Eric Van Alst, MHPCC
 *
-*  @version $Revision: 1.126 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2007-01-09 22:38:53 $
+*  @version $Revision: 1.127 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2007-01-19 04:29:11 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -32,5 +32,5 @@
 #include "psMetadataConfig.h"
 #include "psAssert.h"
-
+#include "psTrace.h"
 
 /******************************************************************************/
@@ -1295,44 +1295,56 @@
         return NULL;
     }
+    // XXX EAM : for some reason, the mmap below results in a buffer which causes
+    // bus errors if the file is empty.  This seems like a strange result...
+    if (buf.st_size == 0) {
+        psError(PS_ERR_IO, true, _("Empty file '%s'.\n"), filename);
+        close(fd);
+        return NULL;
+    }
+
+    // determine the system page size
+    int pageSize = getpagesize();
+
+    // request one extra page.  even if st_size is an exact multiple of pageSize, this
+    // will guarantee we get a block of 0-valued bytes at the end of the file data.
+    int nPages = buf.st_size / pageSize + 1;
+
+    int nBytes = nPages * pageSize;
 
     // psMetadataConfigParse() is going to read the entire file into memory so
     // we're trying to be nice by allowing the VM to flush the file out of
-    // memory if need be.  XXX we're adding 1 to buf.st_size here in case
-    // st_size / system page size has a remaineder of zero (in that case this
-    // magic trick may not work because there won't be any trailing \0s at the
-    // end of the page).
-    void *file = mmap(0, (size_t)buf.st_size + 1, PROT_READ, MAP_PRIVATE, fd, 0);
+    // memory if need be.
+
+    void *file = mmap(0, nBytes, PROT_READ, MAP_PRIVATE, fd, 0);
     if (file == MAP_FAILED) {
         psError(PS_ERR_IO, true, _("failed to mmap() file %s"), filename);
         if (close(fd) != 0) {
             psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
-            return NULL;
         }
         return NULL;
     }
+
+    bool success = true;
 
     md = psMetadataConfigParse(md, nFail, (char *)file, overwrite);
     if (!md) {
         psError(PS_ERR_IO, true, _("failed to parse file '%s'"), filename);
-        return NULL;
-    }
-
-    if (munmap(file, (size_t)buf.st_size) != 0) {
+        success = false;
+    }
+
+    if (munmap(file, nBytes) != 0) {
         psError(PS_ERR_IO, true, _("failed to munmap file '%s'"), filename);
-        if (close(fd) != 0) {
-            // the new error flag is set to false so as not to hide the
-            // munmap() error
-            psError(PS_ERR_IO, false, _("Failed to close file '%s'."), filename);
-            psFree(md);
-            return NULL;
-        }
+        success = false;
     }
 
     if (close(fd) != 0) {
         psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
-        psFree(md);
+        success = false;
+    }
+
+    if (!success) {
+        psFree (md);
         return NULL;
     }
-
     return md;
 }
@@ -1403,4 +1415,5 @@
                 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Error parsing line: %s", line);
             }
+            psTrace("psLib.types", 4, "Error parsing line: %s", line);
         }
     }
