Index: gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/Makefile.in
===================================================================
--- gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/Makefile.in	(revision 18028)
+++ gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/Makefile.in	(revision 18038)
@@ -68,5 +68,5 @@
 	gdbmreorg.c gdbmseq.c gdbmsync.c gdbmerrno.c gdbmexists.c gdbmfdesc.c \
 	gdbmsetopt.c bucket.c falloc.c findkey.c global.c hash.c update.c \
-	version.c
+	version.c gsdlmods.c
 
 TEST_CF = testdbm.c testndbm.c testgdbm.c
@@ -81,5 +81,5 @@
 	gdbmreorg.o gdbmseq.o gdbmsync.o gdbmerrno.o gdbmexists.o gdbmfdesc.o \
 	gdbmsetopt.o bucket.o falloc.o findkey.o global.o hash.o update.o \
-	version.o
+	version.o gsdlmods.o
 
 DBM_LOF = dbminit.lo delete.lo fetch.lo store.lo seq.lo close.lo
@@ -91,5 +91,5 @@
 	gdbmreorg.lo gdbmseq.lo gdbmsync.lo gdbmerrno.lo gdbmexists.lo \
 	gdbmfdesc.lo gdbmsetopt.lo bucket.lo falloc.lo findkey.lo global.lo \
-	hash.lo update.lo version.lo
+	hash.lo update.lo version.lo gsdlmods.lo
 
 TEX_F = gdbm.aux gdbm.cp gdbm.dvi gdbm.fn gdbm.ky gdbm.log gdbm.pg \
Index: gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/bucket.c
===================================================================
--- gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/bucket.c	(revision 18028)
+++ gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/bucket.c	(revision 18038)
@@ -32,4 +32,6 @@
 
 #include "gdbmdefs.h"
+
+#include "gsdlmods.h"
 
 
@@ -115,4 +117,10 @@
       if (num_bytes != dbf->header->bucket_size)
 	_gdbm_fatal (dbf, "read error");
+
+      // GREENSTONE CUSTOMISATION: Swap each value in the bucket if the GDBM file is the wrong endianness
+      if (wrong_endianness)
+      {
+	endian_swap_array((int*) dbf->bucket, dbf->header->bucket_size);
+      }
     }
 
Index: gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/gdbmopen.c
===================================================================
--- gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/gdbmopen.c	(revision 18028)
+++ gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/gdbmopen.c	(revision 18038)
@@ -33,4 +33,7 @@
 #include "gdbmdefs.h"
 #include "gdbmerrno.h"
+
+#include "gsdlmods.h"
+
 
 /* Initialize dbm system.  FILE is a pointer to the file name.  If the file
@@ -330,4 +333,14 @@
 	}
 
+      // GREENSTONE CUSTOMISATION: Check if the magic number is reversed
+      // If it is then the GDBM file is the wrong endianness for the current machine
+      wrong_endianness = (partial_header.header_magic == 0xCE9A5713);
+
+      // GREENSTONE CUSTOMISATION: Swap each value in the partial header if the GDBM file is the wrong endianness
+      if (wrong_endianness)
+      {
+	endian_swap_array((int*) &partial_header, sizeof (gdbm_file_header));
+      }
+
       /* Is the magic number good? */
       if (partial_header.header_magic != 0x13579ace)
@@ -349,4 +362,12 @@
       num_bytes = read (dbf->desc, &dbf->header->avail.av_table[1],
 			dbf->header->block_size-sizeof (gdbm_file_header));
+
+      // GREENSTONE CUSTOMISATION: Swap each value in the header if the GDBM file is the wrong endianness
+      if (wrong_endianness)
+      {
+	endian_swap_array((int*) &dbf->header->avail.av_table[1],
+			  dbf->header->block_size-sizeof(gdbm_file_header));
+      }
+
       if (num_bytes != dbf->header->block_size-sizeof (gdbm_file_header))
 	{
@@ -382,4 +403,9 @@
 	}
 
+      // GREENSTONE CUSTOMISATION: Swap each value in the directory if the GDBM file is the wrong endianness
+      if (wrong_endianness)
+      {
+	endian_swap_array((int*) dbf->dir, dbf->header->dir_size);
+      }
     }
 
Index: gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/gsdlmods.c
===================================================================
--- gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/gsdlmods.c	(revision 18038)
+++ gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/gsdlmods.c	(revision 18038)
@@ -0,0 +1,46 @@
+/**********************************************************************
+ *
+ * gsdlmods.c -- C file for endian-swapping functions
+ * Copyright (C) 2008  DL Consulting Ltd
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#include "gsdlmods.h"
+
+
+int wrong_endianness = 0;
+
+
+int endian_swap (unsigned int x)
+{
+  return (x >> 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x << 24);
+}
+
+
+void endian_swap_array (int* a, unsigned int l)
+{
+  int i;
+  for (i = 0; i < (l / sizeof(int)); i++)
+  {
+    a[i] = endian_swap (a[i]);
+  }
+}
Index: gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/gsdlmods.h
===================================================================
--- gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/gsdlmods.h	(revision 18038)
+++ gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/gsdlmods.h	(revision 18038)
@@ -0,0 +1,38 @@
+/**********************************************************************
+ *
+ * gsdlmods.h -- H file for endian-swapping functions
+ * Copyright (C) 2008  DL Consulting Ltd
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef GSDLMODS_H
+#define GSDLMODS_H
+
+
+extern int wrong_endianness;
+
+int endian_swap (unsigned int x);
+
+void endian_swap_array (int* a, unsigned int l);
+
+
+#endif
