2014-03-03  Guerrero, Juan Manuel  <juan.guerrero@gmx.de>

	* src/var.c (set_progname):  Rename bool with gdbm_bool in union value.
	(s2b, b2b, i2b, variable_get, variable_print_all):  bool replaved with
	gdbm_bool.


2014-03-02  Guerrero, Juan Manuel  <juan.guerrero@gmx.de>

	* src/gdbmtool.h:  Use _GDBMTOOLRC macro defined in systems.h instead
	of hard coded file name.

	* src/systems.h [O_BINARY, __DJGPP__]:  New macros HAS_LFN_SUPPORT and
	GDBMTOOLRC.  These macros select either .gdbmtoolrc or _gdbmtoolrc as
	file name depending on LFN/SFN capability of the file system used.
	They provide default values for anything else than DJGPP.

	* src/progname.c (set_progname):  Use STRIP_FULL_PATH_AND_EXTENSION and
	CANONICALIZE_PATH.


2014-03-01  Guerrero, Juan Manuel  <juan.guerrero@gmx.de>

	* tests/gtopt.c [_SC_PAGESIZE]:  If _SC_PAGESIZE not defined define it
	as 65536

	* src/lock.c [EWOULDBLOCK]:  If EWOULDBLOCK not defined define it as
	EAGAIN.
	[EDEADLK]:  If EDEADLK not defined define it as 9.  Taken from errno.h.

	* gdbmreorg.c (gdbm_reorganize) (IS_DIR_SEPARTOR):  DOS-style paths
	may contain mixed slash, backslash and colon as directory separator.
	(gdbm_reorganize) [O_BINARY]:  Close old and new database files before
	renaming it.

	* src/gdbmexp.c [__DJGPP__]:  Do not include arpa/inet.h.

	* src/gdbmimp.c [__DJGPP__]:  Do not include arpa/inet.h.

	* src/gdbmdefs.h:  Add structure tag to data and gdbm structures.
	This inhibits warning about anonymous struct using if g++ 2.95.2
	is used.

	* src/gdbm.h.in:  Add structure tag to data structures.  This inhibits
	warning about anonymous struct using if g++ 2.95.2 is used.

	* src/systems.h [O_BINARY]:  PAG_FILE_IS_HARD_LINK_TO_DIR_FILE macro
	tries to check if data base file .pag is a hard link to data base
	file .dir.
	[O_BINARY, __DJGPP__]:  STATBLKSIZE must be set to a multiple of 512
	or the initalization of the hash table directory for a new file will
	fail.
	[O_BINARY]:  New macro open. Open file in binary mode.
	[O_BINARY]:  New macro IS_DIR_SEPARATOR. Check for DOS-style directory
	separators.
	[O_BINARY, __DJGPP__]:  DJGPP does neither provide htonl() nor ntohl().
	Those functions implemented as NO-OP macros.
	New macros STRIP_FULL_PATH_AND_EXTENSION and CANONICALIZE_PATH.  These
	are NO-OPs for anything else than DJGPP.
	[O_BINARY, __DJGPP__, __DJGPP_MINOR__]:  DJGPP 2.03 implementation of
	fcntl() does not support F_GETLK, F_SETLK nor F_SETLKW.  Function
	_gdbm_lock_file() will always return success.

	* compat/dbmopen.c (ndbm_open_dir_file0) [O_BINARY]:  For DOS/DJGPP
	systems use PAG_FILE_IS_HARD_LINK_TO_DIR_FILE instead of st_ino
	together with st_dev.

	* compat/ndbm.h:  Add structure tag to data structure.  This inhibits
	warning about anonymous struct using if g++ 2.95.2 is used.

	* gdbm.texinfo:  Add additional library linking info.

	* doc/gdbm.3:  Typo fixed.
	Add additional library linking info.






diff -aprNU5 gdbm-1.11.orig/compat/dbmopen.c gdbm-1.11/compat/dbmopen.c
--- gdbm-1.11.orig/compat/dbmopen.c	2011-11-11 19:39:42 +0100
+++ gdbm-1.11/compat/dbmopen.c	2014-03-02 19:25:46 +0100
@@ -76,13 +76,17 @@ ndbm_open_dir_file0 (const char *file_na
     } 
       
   /* Previous versions of GDBM linked pag to dir. Try to detect this: */
   if (stat (file_name, &st) == 0)
     {
+#if defined(__DJGPP__)
+      if (PAG_FILE_IS_HARD_LINK_TO_DIR_FILE(file_name))
+#else
       if (st.st_nlink >= 2)
 	{
 	  if (st.st_dev == pagst.st_dev && st.st_ino == pagst.st_ino)
+#endif
 	    {
 	      if (unlink (file_name))
 		{
 		  if ((mode & GDBM_OPENMASK) == GDBM_READER)
 		    /* Ok, try to cope with it. */
@@ -92,16 +96,18 @@ ndbm_open_dir_file0 (const char *file_na
 		      gdbm_errno = GDBM_FILE_OPEN_ERROR; 
 		      return -1;
 		    } 
 		}
 	    }
+#if !defined(__DJGPP__)
 	  else
 	    {
 	      gdbm_errno = GDBM_FILE_OPEN_ERROR;
 	      return -1;
 	    }
 	}
+#endif
       else if (st.st_size == 0)
 	/* ok */;
       else if (st.st_size != DEF_DIR_SIZE)
 	{
 	  gdbm_errno = GDBM_BAD_MAGIC_NUMBER;
diff -aprNU5 gdbm-1.11.orig/compat/ndbm.h gdbm-1.11/compat/ndbm.h
--- gdbm-1.11.orig/compat/ndbm.h	2011-08-09 13:24:56 +0200
+++ gdbm-1.11/compat/ndbm.h	2014-03-02 19:25:46 +0100
@@ -30,11 +30,11 @@
 /* Parameters to dbm_store for simple insertion or replacement. */
 #define DBM_INSERT  GDBM_INSERT
 #define DBM_REPLACE GDBM_REPLACE
 
 /* The file information header.  */
-typedef struct
+typedef struct __tag_dbm
 {
   GDBM_FILE file;         /* Actual gdbm file (held in the .pag file */
   int dirfd;              /* Descriptor of the .dir file */
   datum _dbm_memory;      /* Keeps the last returned key */
   char *_dbm_fetch_val;   /* Keeps the dptr of the last fetched datum */
diff -aprNU5 gdbm-1.11.orig/doc/gdbm.3 gdbm-1.11/doc/gdbm.3
--- gdbm-1.11.orig/doc/gdbm.3	2013-05-08 15:57:50 +0200
+++ gdbm-1.11/doc/gdbm.3	2014-03-02 19:25:46 +0100
@@ -150,11 +150,11 @@ writer - create new database regardless
 .PP
 The \fBGDBM_NOMMAP\fR added to \fIread_write\fR by bitwise or instructs
 \fBgdbm_open\fR to disable the use of
 .BR mmap (2).
 .PP
-For the last three (writers of the database) the following may be added
+For the last three (writers of the database) the following may be
 added to \fIread_write\fR by bitwise or:
 .TP
 .B GDBM_SYNC
 Causes all database operations to be synchronized to the disk,
 .TP
@@ -410,11 +410,16 @@ gcc \-o prog prog.c \-lgdbm
 If you wish to use the \fBdbm\fR or \fBndbm\fR compatibility routines,
 you must link in the \fIgdbm_compat\fR library as well.  For example:
 .sp
 .nf
 .in +5
-gcc \-o prog proc.c \-lgdbm \-lgdbm_compat
+gcc \-o prog proc.c \-lgdbm_compat \-lgdbm
+
+Please note that the compatibility library contains references to
+gdbm routines so the order in which the libraries are linked is essential.
+This means that the library linking order given in the above example must
+be respected.
 .in
 .fi
 .\" .SH BUGS
 
 .SH "BUG REPORTS"
diff -aprNU5 gdbm-1.11.orig/doc/gdbm.texinfo gdbm-1.11/doc/gdbm.texinfo
--- gdbm-1.11.orig/doc/gdbm.texinfo	2013-12-25 10:31:58 +0100
+++ gdbm-1.11/doc/gdbm.texinfo	2014-03-02 19:25:46 +0100
@@ -1412,18 +1412,23 @@ The compatibility layer consists of two
 and @file{dbm.h} and the @file{libgdbm_compat} library.
 
 Older programs using @code{ndbm} or @code{dbm} interfaces can
 use @file{libgdbm_compat} without any changes.  To link a program with
 the compatibility library, add the following two options to the
-@command{cc} invocation: @option{-lgdbm -lgdbm_compat}.  The @option{-L}
+@command{cc} invocation: @option{-lgdbm_compat -lgdbm}.  The @option{-L}
 option may also be required, depending on where @code{gdbm} is
 installed, e.g.:
 
 @example
-cc ... -L/usr/local/lib -lgdbm -lgdbm_compat
+cc ... -L/usr/local/lib -lgdbm_compat -lgdbm
 @end example
 
+Please note that the compatibility library contains references to
+gdbm routines so the order in which the libraries are linked is essential.
+This means that the library linking order given in the above example must
+be respected.
+
 @cindex @samp{dir} file
 @cindex @samp{pag} file
 Databases created and manipulated by the compatibility interfaces
 consist of two different files: @file{@var{file}.dir} and
 @file{@var{file}.pag}.  This is required by the @acronym{POSIX}
diff -aprNU5 gdbm-1.11.orig/src/gdbm.h.in gdbm-1.11/src/gdbm.h.in
--- gdbm-1.11.orig/src/gdbm.h.in	2013-05-21 17:15:28 +0200
+++ gdbm-1.11/src/gdbm.h.in	2014-03-02 19:25:46 +0100
@@ -80,11 +80,11 @@ extern "C" {
 # define GDBM_GETDBNAME       15 /* Return database file name */
 
 typedef @GDBM_COUNT_T@ gdbm_count_t;
   
 /* The data and key structure. */
-typedef struct {
+typedef struct __tag_datum {
 	char *dptr;
 	int   dsize;
       } datum;
 
 
diff -aprNU5 gdbm-1.11.orig/src/gdbmdefs.h gdbm-1.11/src/gdbmdefs.h
--- gdbm-1.11.orig/src/gdbmdefs.h	2013-05-21 21:40:26 +0200
+++ gdbm-1.11/src/gdbmdefs.h	2014-03-02 19:25:46 +0100
@@ -33,28 +33,28 @@
    one filles up, it is split in half and half is pushed on an "avail
    stack."  When the active avail table is empty and the "avail stack" is
    not empty, the top of the stack is popped into the active avail table. */
 
 /* The following structure is the element of the avaliable table.  */
-typedef struct {
+typedef struct __tag_avail_elem {
   	int   av_size;		/* The size of the available block. */
 	off_t  av_adr;		/* The file address of the available block. */
       } avail_elem;
 
 /* This is the actual table. The in-memory images of the avail blocks are
    allocated by malloc using a calculated size.  */
-typedef struct {
+typedef struct __tag_avail_block {
 	int   size;		/* The number of avail elements in the table.*/
 	int   count;		/* The number of entries in the table. */
 	off_t next_block;	/* The file address of the next avail block. */
 	avail_elem av_table[1]; /* The table.  Make it look like an array.  */
       } avail_block;
 
 /* The dbm file header keeps track of the current location of the hash
    directory and the free space in the file.  */
 
-typedef struct {
+typedef struct __tag_gdbm_file_header {
 	int   header_magic;  /* Version of file. */
 	int   block_size;    /* The optimal i/o blocksize from stat. */
 	off_t dir;	     /* File address of hash directory table. */
 	int   dir_size;	     /* Size in bytes of the table.  */
 	int   dir_bits;	     /* The number of address bits used in the table.*/
@@ -62,20 +62,20 @@ typedef struct {
 	int   bucket_elems;  /* Number of elements in a hash bucket. */
 	off_t next_block;    /* The next unallocated block address. */
 	avail_block avail;   /* This must be last because of the pseudo
 				array in avail.  This avail grows to fill
 				the entire block. */
-      }  gdbm_file_header;
+      } gdbm_file_header;
 
 
 /* The dbm hash bucket element contains the full 31 bit hash value, the
    "pointer" to the key and data (stored together) with their sizes.  It also
    has a small part of the actual key value.  It is used to verify the first
    part of the key has the correct value without having to read the actual
    key. */
 
-typedef struct {
+typedef struct __tag_bucket_element {
 	int   hash_value;	/* The complete 31 bit value. */
 	char  key_start[SMALL];	/* Up to the first SMALL bytes of the key.  */
 	off_t data_pointer;	/* The file address of the key record. The
 				   data record directly follows the key.  */
 	int   key_size;		/* Size of key data in the file. */
@@ -93,11 +93,11 @@ typedef struct {
    value modulo the size of the bucket.  The in-memory images of the
    buckets are allocated by malloc using a calculated size depending of
    the file system buffer size.  To speed up write, each bucket will have
    BUCKET_AVAIL avail elements with the bucket. */
 
-typedef struct {
+typedef struct __tag_hash_bucket {
         int   av_count;		   /* The number of bucket_avail entries. */
         avail_elem bucket_avail[BUCKET_AVAIL];  /* Distributed avail. */
 	int   bucket_bits;	   /* The number of bits used to get here. */
 	int   count;		   /* The number of element buckets full. */
 	bucket_element h_table[1]; /* The table.  Make it look like an array.*/
@@ -112,19 +112,19 @@ typedef struct {
    must exactly match the key from the file.  To reduce overhead, the
    data will be read at the same time.  Both key and data will be stored
    in a data cache.  Each bucket cached will have a one element data
    cache.  */
 
-typedef struct {
+typedef struct __tag_data_cache_elem {
         int   hash_val;
 	int   data_size;
 	int   key_size;
 	char *dptr;
 	int   elem_loc;
-      }  data_cache_elem;
+      } data_cache_elem;
 
-typedef struct {
+typedef struct __tag_cache_elem {
         hash_bucket *   ca_bucket;
 	off_t           ca_adr;
 	char		ca_changed;   /* Data in the bucket changed. */
 	data_cache_elem ca_data;
       } cache_elem;
diff -aprNU5 gdbm-1.11.orig/src/gdbmexp.c gdbm-1.11/src/gdbmexp.c
--- gdbm-1.11.orig/src/gdbmexp.c	2013-12-25 10:52:16 +0100
+++ gdbm-1.11/src/gdbmexp.c	2014-03-02 19:25:46 +0100
@@ -16,11 +16,13 @@
    You should have received a copy of the GNU General Public License
    along with GDBM. If not, see <http://www.gnu.org/licenses/>.   */
 
 /* Include system configuration before all else. */
 # include "autoconf.h"
-# include <arpa/inet.h>
+# ifndef __DJGPP__
+#  include <arpa/inet.h>
+# endif
 
 # include "gdbmdefs.h"
 # include "gdbm.h"
 
 int
diff -aprNU5 gdbm-1.11.orig/src/gdbmimp.c gdbm-1.11/src/gdbmimp.c
--- gdbm-1.11.orig/src/gdbmimp.c	2013-12-25 10:52:36 +0100
+++ gdbm-1.11/src/gdbmimp.c	2014-03-02 19:25:46 +0100
@@ -15,11 +15,13 @@
 
    You should have received a copy of the GNU General Public License
    along with GDBM. If not, see <http://www.gnu.org/licenses/>.   */
 
 # include "autoconf.h"
-# include <arpa/inet.h>
+# ifndef __DJGPP__
+#  include <arpa/inet.h>
+# endif
 
 # include "gdbmdefs.h"
 # include "gdbm.h"
 
 int
diff -aprNU5 gdbm-1.11.orig/src/gdbmreorg.c gdbm-1.11/src/gdbmreorg.c
--- gdbm-1.11.orig/src/gdbmreorg.c	2013-12-25 10:52:56 +0100
+++ gdbm-1.11/src/gdbmreorg.c	2014-03-02 19:25:46 +0100
@@ -61,11 +61,13 @@ gdbm_reorganize (GDBM_FILE dbf)
   GDBM_FILE new_dbf;		/* The new file. */
   char *new_name;			/* A temporary name. */
   int  len;				/* Used in new_name construction. */
   datum key, nextkey, data;		/* For the sequential sweep. */
   struct stat fileinfo;			/* Information about the file. */
+#if O_BINARY
   int  index;				/* Use in moving the bucket cache. */
+#endif
 
 
   /* Readers can not reorganize! */
   if (dbf->read_write == GDBM_READER)
     {
@@ -92,11 +94,11 @@ gdbm_reorganize (GDBM_FILE dbf)
       return -1;
     }
   strcpy (&new_name[0], dbf->name);
   new_name[len+2] = 0;
   new_name[len+1] = '#';
-  while ( (len > 0) && new_name[len-1] != '/')
+  while ( (len > 0) && !IS_DIR_SEPARATOR(new_name[len-1]))
     {
       new_name[len] = new_name[len-1];
       len -= 1;
     }
   new_name[len] = '#';
@@ -155,10 +157,65 @@ gdbm_reorganize (GDBM_FILE dbf)
   _gdbm_mapped_unmap (dbf);
 #endif
   
   /* Move the new file to old name. */
 
+#if O_BINARY
+
+  /* DOS can not rename an open file.
+     Both source and destination must be closed. */
+
+  {
+     char *dbf_name;
+     int dbf_block_size;
+     int dbf_flags;
+     void (*dbf_fatal) ();
+     int status;
+
+     gdbm_close (new_dbf);
+
+     dbf_name = (char *) malloc (strlen (dbf->name + 1));
+     if (dbf_name == NULL)
+       {
+         gdbm_errno = GDBM_REORGANIZE_FAILED;
+         free (new_name);
+         return -1;
+       }
+     strcpy (dbf_name, dbf->name);
+     dbf_block_size = dbf->header->block_size;
+     dbf_flags = GDBM_WRITER;
+     if (!(dbf->file_locking)) dbf_flags |= GDBM_NOLOCK;
+     if (!(dbf->fast_write))   dbf_flags |= GDBM_SYNC;
+     dbf_fatal = dbf->fatal_err;
+
+     gdbm_close (dbf);
+
+     status = rename (new_name, dbf_name);
+
+     /* Reorganized database will be opened with old file name. */
+     new_dbf = gdbm_open (dbf_name, dbf_block_size, dbf_flags,
+                          fileinfo.st_mode, dbf_fatal);
+     free (dbf_name);
+     if (new_dbf == NULL)
+       /* Database file can not be reopened.
+          Note that gdbm_errno != GDBM_REORGANIZE_FAILED now,
+          and hence the `dbf' is corrupt. */
+       status = -1;
+     else
+       {
+          /* if errno == GDBM_REORGANIZE_FAILED,
+             the caller still has a valid `dbf'. */
+          if (status != 0) gdbm_errno = GDBM_REORGANIZE_FAILED;
+          *dbf = *new_dbf;
+          free (new_dbf);
+       }
+
+     return status;  /* If status == 0 then renaming *and* reopening worked. */
+  }
+
+#else  /* not O_BINARY */
+
   if (rename (new_name, dbf->name) != 0)
     {
       gdbm_errno = GDBM_REORGANIZE_FAILED;
       gdbm_close (new_dbf);
       free (new_name);
@@ -213,6 +270,8 @@ gdbm_reorganize (GDBM_FILE dbf)
   /* Force the right stuff for a correct bucket cache. */
   dbf->cache_entry    = &dbf->bucket_cache[0];
   _gdbm_get_bucket (dbf, 0);
 
   return 0;
+
+#endif /* not O_BINARY */
 }
diff -aprNU5 gdbm-1.11.orig/src/gdbmtool.h gdbm-1.11/src/gdbmtool.h
--- gdbm-1.11.orig/src/gdbmtool.h	2013-05-15 17:32:42 +0200
+++ gdbm-1.11/src/gdbmtool.h	2014-03-02 21:48:58 +0100
@@ -100,11 +100,11 @@ int setsource (const char *filename, int
 
 extern char *file_name;
 extern int interactive;
 extern int open_mode;
 
-#define GDBMTOOLRC ".gdbmtoolrc"
+#define GDBMTOOLRC _GDBMTOOLRC
 #define GDBMTOOL_DEFFILE "junk.gdbm"
 
 
 struct slist
 {
diff -aprNU5 gdbm-1.11.orig/src/lock.c gdbm-1.11/src/lock.c
--- gdbm-1.11.orig/src/lock.c	2013-12-25 10:57:58 +0100
+++ gdbm-1.11/src/lock.c	2014-03-02 19:25:46 +0100
@@ -45,10 +45,20 @@
 # define HAVE_FCNTL_LOCK 1
 #else
 # define HAVE_FCNTL_LOCK 0
 #endif
 
+#ifndef EWOULDBLOCK
+# define EWOULDBLOCK  EAGAIN
+#endif
+
+#ifndef EDEADLK
+# if __DJGPP__
+#  define EDEADLK  9  /* From errno.h.  */
+# endif
+#endif
+
 #if 0
 int
 gdbm_locked (GDBM_FILE dbf)
 {
   return (dbf->lock_type != LOCKING_NONE);
diff -aprNU5 gdbm-1.11.orig/src/progname.c gdbm-1.11/src/progname.c
--- gdbm-1.11.orig/src/progname.c	2013-12-25 10:58:22 +0100
+++ gdbm-1.11/src/progname.c	2014-03-02 20:25:46 +0100
@@ -16,17 +16,20 @@
 
 # include "autoconf.h"
 # include "gdbm.h"
 # include "gdbmapp.h"
 # include <string.h>
+# ifndef STRIP_FULL_PATH_AND_EXTENSION
+#  include "systems.h"
+# endif
 
 const char *progname;
 
 void
 set_progname (const char *arg)
 {
-  const char *p = strrchr (arg, '/');
+  const char *p = STRIP_FULL_PATH_AND_EXTENSION(arg);
   if (p)
     ++p;
   else
     p = arg;
   if (strncmp (p, "lt-", 3) == 0)
diff -aprNU5 gdbm-1.11.orig/src/systems.h gdbm-1.11/src/systems.h
--- gdbm-1.11.orig/src/systems.h	2013-12-25 10:58:38 +0100
+++ gdbm-1.11/src/systems.h	2014-03-03 20:08:48 +0100
@@ -33,25 +33,27 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
 
 #ifndef SEEK_SET
-# define SEEK_SET        0
+# define SEEK_SET   0
 #endif
 
 #ifndef O_CLOEXEC
-# define O_CLOEXEC 0
+# define O_CLOEXEC  0
 #endif
 
 /* Default block size.  Some systems do not have blocksize in their
    stat record. This code uses the BSD blocksize from stat. */
 
+#ifndef __DJGPP__
 #if HAVE_STRUCT_STAT_ST_BLKSIZE
 # define STATBLKSIZE file_stat.st_blksize
 #else
 # define STATBLKSIZE 1024
 #endif
+#endif
 
 /* Do we have ftruncate? */
 #if HAVE_FTRUNCATE
 # define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
 #else
@@ -77,5 +79,190 @@
 # else
 #  define __fsync(_dbf)			{ sync(); sync(); }
 # endif
 #endif
 
+/* For systems that distinguish between text and binary I/O.
+   O_BINARY is usually declared in fcntl.h  */
+#if !defined O_BINARY && defined _O_BINARY
+  /* For MSC-compatible compilers.  */
+# define O_BINARY _O_BINARY
+#endif
+#if O_BINARY
+  /* Files must be opened in BINARY mode. */
+# undef  open
+# define open(file, mode, ...)  open((file), (mode) | O_BINARY, ##__VA_ARGS__)
+# define IS_DIR_SEPARATOR(c)    ((c) == ':' || (c) == '/' || (c) == '\\')
+
+# if __DJGPP__
+
+   /* DJGPP does not support neither hton[ls] nor ntoh[ls].  */
+#  undef  htonl
+#  define htonl(hostlong)  (hostlong)  /*  No op.  */
+#  undef  ntohl
+#  define ntohl(netlong)   (netlong)   /*  No op.  */
+
+   /*
+       A newly created data base file gets an initial hash table directory
+       that has a size of 8 * sizeof (off_t).  This is only possible if
+       STATBLKSIZE (file system block size) is a multiple of 512.
+       Unfortunately DJGPP's fstat does not always return a st_blksize value
+       that is a multiple of 512.
+   */
+#  undef  STATBLKSIZE
+#  define STATBLKSIZE  512
+
+
+#  if __DJGPP_MINOR__ < 4
+    /*
+        DJGPP 2.03 implementation of fcntl() does not support F_GETLK, F_SETLK
+        nor F_SETLKW. To make this package work, _gdbm_lock_file() below will
+        *NEVER* invoke fcntl() at all and *ALWAYS* return success.
+        All this means that _gdbm_lock_file() will set lock_val = 0 simulating
+        file locking/unlocking success when there have been done **NO** file
+        locking/unlocking at all.
+    */
+#   undef  fcntl
+#   define fcntl(fd, cmd, arg)                       \
+    (__gnuc_extension__                              \
+      ({                                             \
+         (0);    /*  Simulate success.  */           \
+      })                                             \
+    )
+#  endif /* __DJGPP__ < 2.04 */
+
+
+#  if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#   define __gnuc_extension__  __extension__
+#  else
+#   define __gnuc_extension__
+#  endif
+
+#  include <libc/unconst.h>
+#  define STRIP_FULL_PATH_AND_EXTENSION(file_name)   \
+   (__gnuc_extension__                               \
+     ({                                              \
+        char *_dst, *_src;                           \
+        _dst = _src = unconst((file_name), char *);  \
+        while (*_src++)                              \
+          ;                                          \
+        while ((_src - _dst) && (*--_src != '.'))    \
+          ;                                          \
+        for (*_src = '\0'; (_src - _dst); _src--)    \
+          if (IS_DIR_SEPARATOR(*_src))               \
+            break;                                   \
+        if (_src - _dst)                             \
+          while ((*_dst++ = *++_src))                \
+            ;                                        \
+        (file_name);                                 \
+     })                                              \
+   )
+
+#  define CANONICALIZE_PATH(path)                    \
+   (__gnuc_extension__                               \
+     ({                                              \
+        if ((path))                                  \
+        {                                            \
+          char *_p = unconst((path), char *);        \
+          for (; *_p; _p++)                          \
+            if (*_p == '\\')                         \
+              *_p = '/';                             \
+        }                                            \
+        (path);                                      \
+     })                                              \
+   )
+
+   /*
+       It is not possible to use st_ino to determinated
+       if .pag file is an hard link to .dir file.
+   */
+#  include <stdbool.h>
+#  define PAG_FILE_IS_HARD_LINK_TO_DIR_FILE(file_name)                                                             \
+   (__gnuc_extension__                                                                                             \
+     ({                                                                                                            \
+        bool _is_link = false;                                                                                     \
+        char *_dir_file, *_pag_file;                                                                               \
+        size_t length = (size_t)strlen(file_name);                                                                 \
+                                                                                                                   \
+        _dir_file = unconst((file_name), char *);                                                                  \
+        _pag_file = malloc(length + 1);                                                                            \
+        strcpy(_pag_file, _dir_file);                                                                              \
+        _pag_file[--length] = 'g';                                                                                 \
+        _pag_file[--length] = 'a';                                                                                 \
+        _pag_file[--length] = 'p';                                                                                 \
+                                                                                                                   \
+        if (!access(_dir_file, F_OK) && !access(_pag_file, F_OK))                                                  \
+        {                                                                                                          \
+          struct stat _sb_dir, _sb_pag;                                                                            \
+          if (!stat(_dir_file, &_sb_dir) && !stat(_pag_file, &_sb_pag))                                            \
+          {                                                                                                        \
+            if ((_sb_dir.st_dev == _sb_pag.st_dev) && (_sb_dir.st_size == _sb_pag.st_size))                        \
+            {                                                                                                      \
+              int _fd_dir = open(_dir_file, O_RDONLY | O_BINARY);                                                  \
+              int _fd_pag = open(_pag_file, O_RDONLY | O_BINARY);                                                  \
+              if ((_fd_dir > -1) && (_fd_pag > -1))                                                                \
+              {                                                                                                    \
+                char _buffer_dir[512], _buffer_pag[512];                                                           \
+                ssize_t _bytes_read_dir, _bytes_read_pag;                                                          \
+                                                                                                                   \
+                _bytes_read_dir = read(_fd_dir, _buffer_dir, 512);                                                 \
+                _bytes_read_pag = read(_fd_pag, _buffer_pag, 512);                                                 \
+                if ((_bytes_read_dir > -1) && (_bytes_read_pag > -1) && (_bytes_read_dir == _bytes_read_pag))      \
+                {                                                                                                  \
+                  ssize_t _i;                                                                                      \
+                  for (_i = 0; _i < _bytes_read_dir && _buffer_dir[_i] == _buffer_pag[_i]; _i++)                   \
+                    ;                                                                                              \
+                  if (_i != _bytes_read_dir)                                                                       \
+                    goto _finished;                                                                                \
+                                                                                                                   \
+                  off_t _pos_dir = lseek(_fd_dir, -512, SEEK_END);                                                 \
+                  off_t _pos_pag = lseek(_fd_pag, -512, SEEK_END);                                                 \
+                  if ((_pos_dir > -1) && (_pos_pag > -1) && (_pos_dir == _pos_pag))                                \
+                  {                                                                                                \
+                    _bytes_read_dir = read(_fd_dir, _buffer_dir, 512);                                             \
+                    _bytes_read_pag = read(_fd_pag, _buffer_pag, 512);                                             \
+                    if ((_bytes_read_dir > -1) && (_bytes_read_pag > -1) && (_bytes_read_dir == _bytes_read_pag))  \
+                    {                                                                                              \
+                      for (_i = 0; _i < _bytes_read_dir && _buffer_dir[_i] == _buffer_pag[_i]; _i++)               \
+                        ;                                                                                          \
+                      if (_i != _bytes_read_dir)                                                                   \
+                        goto _finished;                                                                            \
+                      _is_link = true;                                                                             \
+                    }                                                                                              \
+                  }                                                                                                \
+                }                                                                                                  \
+                                                                                                                   \
+_finished:                                                                                                         \
+                close(_fd_dir);                                                                                    \
+                close(_fd_pag);                                                                                    \
+              }                                                                                                    \
+            }                                                                                                      \
+          }                                                                                                        \
+        }                                                                                                          \
+        (_is_link);                                                                                                \
+     })                                                                                                            \
+   )
+
+#  define HAS_LFN_SUPPORT(name)  (pathconf ((name), _PC_NAME_MAX) > 12)
+
+#  define _GDBMTOOLRC                                                                       \
+   (__gnuc_extension__                                                                      \
+     ({                                                                                     \
+        char *gdbmtoolrc = HAS_LFN_SUPPORT(".gdbmtoolrc") ? ".gdbmtoolrc" : "_gdbmtoolrc";  \
+        gdbmtoolrc;                                                                         \
+     })                                                                                     \
+   )
+
+# else /* !__DJGPP__  */
+#  define STRIP_FULL_PATH_AND_EXTENSION(file_name)  (strrchr ((file_name), '/'))
+#  define CANONICALIZE_PATH(path)                   (path)
+#  define HAS_LFN_SUPPORT(name)                     (0)
+#  define _GDBMTOOLRC                               "_gdbmtoolrc"
+# endif /* !__DJGPP__  */
+#else /* not O_BINARY */
+# define O_BINARY
+# define IS_DIR_SEPARATOR(c)                        ((c) == '/')
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)   (strrchr ((file_name), '/'))
+# define CANONICALIZE_PATH(path)                    (path)
+# define HAS_LFN_SUPPORT(name)                      (1)
+# define _GDBMTOOLRC                                ".gdbmtoolrc"
+#endif /* not O_BINARY */
diff -aprNU5 gdbm-1.11.orig/src/var.c gdbm-1.11/src/var.c
--- gdbm-1.11.orig/src/var.c	2013-05-17 15:49:22 +0200
+++ gdbm-1.11/src/var.c	2014-03-03 19:34:50 +0100
@@ -26,11 +26,11 @@
 #define VAR_IS_SET(v) ((v)->flags & (VARF_SET|VARF_INIT))
 
 union value
 {
   char *string;
-  int bool;
+  int gdbm_bool;
   int num;
 };
 
 struct variable
 {
@@ -141,25 +141,25 @@ s2b (union value *vp, void *val, int fla
   char *p;
   
   for (i = 0; trueval[i]; i++)
     if (strcasecmp (trueval[i], val) == 0)
       {
-	vp->bool = 1;
+	vp->gdbm_bool = 1;
 	return VAR_OK;
       }
   
   for (i = 0; falseval[i]; i++)
     if (strcasecmp (falseval[i], val) == 0)
       {
-	vp->bool = 0;
+	vp->gdbm_bool = 0;
 	return VAR_OK;
       }
   
   n = strtoul (val, &p, 0);
   if (*p)
     return VAR_ERR_BADTYPE;
-  vp->bool = !!n;
+  vp->gdbm_bool = !!n;
   return VAR_OK;
 }
   
 static int
 s2i (union value *vp, void *val, int flags)
@@ -175,11 +175,11 @@ s2i (union value *vp, void *val, int fla
 }
 
 static int
 b2b (union value *vp, void *val, int flags)
 {
-  vp->bool = !!*(int*)val;
+  vp->gdbm_bool = !!*(int*)val;
   return VAR_OK;
 }
 
 static int
 b2i (union value *vp, void *val, int flags)
@@ -196,11 +196,11 @@ i2i (union value *vp, void *val, int fla
 }
 
 static int
 i2b (union value *vp, void *val, int flags)
 {
-  vp->bool = *(int*)val;
+  vp->gdbm_bool = *(int*)val;
   return VAR_OK;
 }
 
 static setvar_t setvar[3][3] = {
             /*    s     b    i */
@@ -292,11 +292,11 @@ variable_get (const char *name, int type
     case VART_STRING:
       *val = vp->v.string;
       break;
 
     case VART_BOOL:
-      *(int*)val = vp->v.bool;
+      *(int*)val = vp->v.gdbm_bool;
       break;
       
     case VART_INT:
       *(int*)val = vp->v.num;
       break;
@@ -340,11 +340,11 @@ variable_print_all (FILE *fp)
 	      fprintf (fp, (vp->flags & VARF_OCTAL) ? "%s=%03o" : "%s=%d",
 		       vp->name, vp->v.num);
 	      break;
 	      
 	    case VART_BOOL:
-	      fprintf (fp, "%s%s", vp->v.bool ? "" : "no", vp->name);
+	      fprintf (fp, "%s%s", vp->v.gdbm_bool ? "" : "no", vp->name);
 	      break;
 	      
 	    case VART_STRING:
 	      fprintf (fp, "%s=\"", vp->name);
 	      for (s = vp->v.string; *s; s++)
diff -aprNU5 gdbm-1.11.orig/tests/gtopt.c gdbm-1.11/tests/gtopt.c
--- gdbm-1.11.orig/tests/gtopt.c	2011-08-11 18:45:54 +0200
+++ gdbm-1.11/tests/gtopt.c	2014-03-02 19:25:46 +0100
@@ -29,10 +29,14 @@ int flags = 0;                  /* gdbm_
 int mode = GDBM_WRCREAT;        /* gdbm_open mode */
 int block_size = 0;             /* block size for the db. 0 means default */
 size_t mapped_size_max = 32768; /* size of the memory mapped region */
 size_t cache_size = 32;         /* cache size */
 
+#ifndef _SC_PAGESIZE
+# define _SC_PAGESIZE  65536
+#endif
+
 static size_t
 get_max_mmap_size (const char *arg)
 {
   char *p;
   size_t size;
