2002-10-25  Guerrero, Juan Manuel  <st001906@hrz1.hrz.tu-darmstadt.de>

	* Makefile.in: Remove BINOWN and BINGRP flags.
	  Add library libgdbm.la at link stage to binaries that need it.
	  Revert linking order of libraries to resolve unresolved references.
	  DOS filename restriction: gdbm.proto2 renamed to gdbm.pr2.
	  html and ps docs targets added.

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

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

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

	* gdbm.texinfo: Add additional library linking info.

	* 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.

	* gdbmsetopts.c (gdbm_setopt): The cases for GDBM_CENTFREE and
	  GDBM_COALESCEBLKS both set dbf->fast_write, which is an unrelated
	  flag, and do not set dbf->central_free or dbf->coalesce_blocks as
	  they should.

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

	* systems.h [__DJGPP__]: DJGPP 2.03 implementation of fcntl() does
	  not support F_GETLK, F_SETLK nor F_SETLKW. Macros UNLOCK_FILE,
	  READLOCK_FILE and WRITELOCK_FILE will always return success.
	  [O_BINARY] (open): New macro. Open file in binary mode.
	  [O_BINARY] (IS_DIR_SEPARATOR): New macro. Check for DOS-style
	  dir separators.

	* version.h: Add DJGPP specific version string.



diff -acrpNC5 gdbm-1.8.3.orig/Makefile.in gdbm-1.8.3.djgpp/Makefile.in
*** gdbm-1.8.3.orig/Makefile.in	Tue Oct  8 16:09:12 2002
--- gdbm-1.8.3.djgpp/Makefile.in	Fri Oct 25 19:32:32 2002
*************** INSTALL_DATA = @INSTALL_DATA@
*** 18,27 ****
--- 18,28 ----
  BINOWN = bin
  BINGRP = bin
  
  MAKEINFO = makeinfo
  TEXI2DVI = texi2dvi
+ DVIPS = dvips
  
  DEFS =
  
  # Where the system [n]dbm routines are...
  LIBS = @LIBS@ -lc
*************** manext = 3
*** 55,65 ****
  .c.lo:
  	$(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(DEFS) -I. -I$(srcdir) $(CFLAGS) $<
  
  SHELL = /bin/sh
  
! PROGS = libgdbm.la testgdbm testdbm testndbm tndbm tdbm conv2gdbm
  
  DBM_CF = dbminit.c delete.c fetch.c store.c seq.c close.c
  
  NDBM_CF = dbmopen.c dbmdelete.c dbmfetch.c dbmstore.c dbmseq.c \
  	dbmclose.c dbmdirfno.c dbmpagfno.c dbmrdonly.c
--- 56,66 ----
  .c.lo:
  	$(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(DEFS) -I. -I$(srcdir) $(CFLAGS) $<
  
  SHELL = /bin/sh
  
! PROGS = libgdbm.la testgdbm testdbm testndbm conv2gdbm #tndbm tdbm
  
  DBM_CF = dbminit.c delete.c fetch.c store.c seq.c close.c
  
  NDBM_CF = dbmopen.c dbmdelete.c dbmfetch.c dbmstore.c dbmseq.c \
  	dbmclose.c dbmdirfno.c dbmpagfno.c dbmrdonly.c
*************** C_LOBJS = $(DBM_LOF) $(NDBM_LOF)
*** 113,123 ****
  
  HDRS = gdbmdefs.h extern.h gdbmerrno.h systems.h dbm.h ndbm.h gdbmconst.h \
  	proto.h
  
  MSCFILES = COPYING ChangeLog Makefile.in README gdbm.3 gdbm.texinfo \
! 	gdbm.info NEWS INSTALL gdbm.proto gdbm.proto2 conv2gdbm.c \
  	configure configure.in getopt.c getopt.h samp1.cc \
  	autoconf.h.in install-sh mkinstalldirs config.guess config.sub \
  	aclocal.m4 ltconfig ltmain.sh
  
  DISTFILES = $(SRCS) $(HDRS) $(MSCFILES)
--- 114,124 ----
  
  HDRS = gdbmdefs.h extern.h gdbmerrno.h systems.h dbm.h ndbm.h gdbmconst.h \
  	proto.h
  
  MSCFILES = COPYING ChangeLog Makefile.in README gdbm.3 gdbm.texinfo \
! 	gdbm.info NEWS INSTALL gdbm.proto gdbm.pr2 conv2gdbm.c \
  	configure configure.in getopt.c getopt.h samp1.cc \
  	autoconf.h.in install-sh mkinstalldirs config.guess config.sub \
  	aclocal.m4 ltconfig ltmain.sh
  
  DISTFILES = $(SRCS) $(HDRS) $(MSCFILES)
*************** DISTFILES = $(SRCS) $(HDRS) $(MSCFILES)
*** 125,154 ****
  all: libgdbm.la libgdbm_compat.la
  
  progs: $(PROGS)
  
  install: libgdbm.la gdbm.h gdbm.info
! 	$(srcdir)/mkinstalldirs $(INSTALL_ROOT)$(libdir) \
  		$(INSTALL_ROOT)$(includedir) $(INSTALL_ROOT)$(man3dir) \
  		$(INSTALL_ROOT)$(infodir)
  	$(LIBTOOL) $(INSTALL) -c libgdbm.la $(INSTALL_ROOT)$(libdir)/libgdbm.la
! 	$(INSTALL_DATA) -o $(BINOWN) -g $(BINGRP) gdbm.h \
! 		$(INSTALL_ROOT)$(includedir)/gdbm.h
! 	$(INSTALL_DATA) -o $(BINOWN) -g $(BINGRP) $(srcdir)/gdbm.3 \
! 		$(INSTALL_ROOT)$(man3dir)/gdbm.3
! 	$(INSTALL_DATA) -o $(BINOWN) -g $(BINGRP) $(srcdir)/gdbm.info \
! 		$(INSTALL_ROOT)$(infodir)/gdbm.info
  
  install-compat:
! 	$(srcdir)/mkinstalldirs $(INSTALL_ROOT)$(libdir) \
  		$(INSTALL_ROOT)$(includedir)
  	$(LIBTOOL) $(INSTALL) -c libgdbm_compat.la \
  		$(INSTALL_ROOT)$(libdir)/libgdbm_compat.la
! 	$(INSTALL_DATA) -o $(BINOWN) -g $(BINGRP) $(srcdir)/dbm.h \
! 		$(INSTALL_ROOT)$(includedir)/dbm.h
! 	$(INSTALL_DATA) -o $(BINOWN) -g $(BINGRP) $(srcdir)/ndbm.h \
! 		$(INSTALL_ROOT)$(includedir)/ndbm.h
  
  #libgdbm.a: $(OBJS) gdbm.h
  #	rm -f libgdbm.a
  #	ar q libgdbm.a $(OBJS)
  #	$(RANLIB) libgdbm.a
--- 126,150 ----
  all: libgdbm.la libgdbm_compat.la
  
  progs: $(PROGS)
  
  install: libgdbm.la gdbm.h gdbm.info
! 	-$(srcdir)/mkinstalldirs $(INSTALL_ROOT)$(libdir) \
  		$(INSTALL_ROOT)$(includedir) $(INSTALL_ROOT)$(man3dir) \
  		$(INSTALL_ROOT)$(infodir)
  	$(LIBTOOL) $(INSTALL) -c libgdbm.la $(INSTALL_ROOT)$(libdir)/libgdbm.la
! 	$(INSTALL_DATA) gdbm.h $(INSTALL_ROOT)$(includedir)/gdbm.h
! 	$(INSTALL_DATA) $(srcdir)/gdbm.3 $(INSTALL_ROOT)$(man3dir)/gdbm.3
! 	$(INSTALL_DATA) gdbm.info $(INSTALL_ROOT)$(infodir)/gdbm.info
  
  install-compat:
! 	-$(srcdir)/mkinstalldirs $(INSTALL_ROOT)$(libdir) \
  		$(INSTALL_ROOT)$(includedir)
  	$(LIBTOOL) $(INSTALL) -c libgdbm_compat.la \
  		$(INSTALL_ROOT)$(libdir)/libgdbm_compat.la
! 	$(INSTALL_DATA) $(srcdir)/dbm.h  $(INSTALL_ROOT)$(includedir)/dbm.h
! 	$(INSTALL_DATA) $(srcdir)/ndbm.h $(INSTALL_ROOT)$(includedir)/ndbm.h
  
  #libgdbm.a: $(OBJS) gdbm.h
  #	rm -f libgdbm.a
  #	ar q libgdbm.a $(OBJS)
  #	$(RANLIB) libgdbm.a
*************** libgdbm.la: $(LOBJS) gdbm.h
*** 161,203 ****
  libgdbm_compat.la: $(C_LOBJS) gdbm.h
  	rm -f libgdbm_compat.la
  	$(LIBTOOL) --mode=link $(CC) -o libgdbm_compat.la -rpath $(libdir) \
  		-version-info $(SHLIB_VER) $(C_LOBJS)
  
! gdbm.h:	gdbm.proto gdbmerrno.h gdbm.proto2
  	rm -f gdbm.h
  	cp $(srcdir)/gdbm.proto gdbm.h
  	chmod +w gdbm.h
  	grep _ $(srcdir)/gdbmerrno.h >> gdbm.h
! 	cat $(srcdir)/gdbm.proto2 >> gdbm.h
  	chmod -w gdbm.h
  
  testgdbm: testgdbm.o libgdbm.la @LIBOBJS@
  	$(LIBTOOL) $(CC) $(LDFLAGS) -o testgdbm testgdbm.o libgdbm.la @LIBOBJS@
  
  testdbm: testdbm.o libgdbm.la libgdbm_compat.la
! 	$(LIBTOOL) $(CC) $(LDFLAGS) -o testdbm testdbm.o libgdbm.la libgdbm_compat.la
  
  tdbm: testdbm.o
  	$(CC) $(LDFLAGS) -o tdbm testdbm.o $(LIBS)
  
  testndbm.o: testndbm.c
  	$(CC) -c -I. -I$(srcdir) $(CFLAGS) $(DEFS) -DGNU $(srcdir)/testndbm.c
  
  testndbm: testndbm.o libgdbm.la libgdbm_compat.la
! 	$(LIBTOOL) $(CC) $(LDFLAGS) -o testndbm testndbm.o libgdbm.la libgdbm_compat.la
  
  tndbm.o: testndbm.c
  	cp $(srcdir)/testndbm.c ./tndbm.c
  	$(CC) -c -I. -I$(srcdir) $(CFLAGS) $(DEFS) ./tndbm.c
  	rm -f ./tndbm.c
  
  tndbm: tndbm.o
  	$(CC) $(LDFLAGS) -o tndbm tndbm.o $(LIBS)
  
! conv2gdbm: conv2gdbm.o libgdbm.la @LIBOBJS@
! 	$(LIBTOOL) $(CC) $(LDFLAGS) -o conv2gdbm conv2gdbm.o $(LIBS) libgdbm.la @LIBOBJS@
  
  lintgdbm: 
  	lint $(DEFS) $(LFLAGS) $(DBM_CF) $(NDBM_CF) $(GDBM_CF) testgdbm.c
  
  TAGS: $(SRCS)
--- 157,199 ----
  libgdbm_compat.la: $(C_LOBJS) gdbm.h
  	rm -f libgdbm_compat.la
  	$(LIBTOOL) --mode=link $(CC) -o libgdbm_compat.la -rpath $(libdir) \
  		-version-info $(SHLIB_VER) $(C_LOBJS)
  
! gdbm.h:	gdbm.proto gdbmerrno.h gdbm.pr2
  	rm -f gdbm.h
  	cp $(srcdir)/gdbm.proto gdbm.h
  	chmod +w gdbm.h
  	grep _ $(srcdir)/gdbmerrno.h >> gdbm.h
! 	cat $(srcdir)/gdbm.pr2 >> gdbm.h
  	chmod -w gdbm.h
  
  testgdbm: testgdbm.o libgdbm.la @LIBOBJS@
  	$(LIBTOOL) $(CC) $(LDFLAGS) -o testgdbm testgdbm.o libgdbm.la @LIBOBJS@
  
  testdbm: testdbm.o libgdbm.la libgdbm_compat.la
! 	$(LIBTOOL) $(CC) $(LDFLAGS) -o testdbm testdbm.o libgdbm_compat.la libgdbm.la
  
  tdbm: testdbm.o
  	$(CC) $(LDFLAGS) -o tdbm testdbm.o $(LIBS)
  
  testndbm.o: testndbm.c
  	$(CC) -c -I. -I$(srcdir) $(CFLAGS) $(DEFS) -DGNU $(srcdir)/testndbm.c
  
  testndbm: testndbm.o libgdbm.la libgdbm_compat.la
! 	$(LIBTOOL) $(CC) $(LDFLAGS) -o testndbm testndbm.o libgdbm_compat.la libgdbm.la
  
  tndbm.o: testndbm.c
  	cp $(srcdir)/testndbm.c ./tndbm.c
  	$(CC) -c -I. -I$(srcdir) $(CFLAGS) $(DEFS) ./tndbm.c
  	rm -f ./tndbm.c
  
  tndbm: tndbm.o
  	$(CC) $(LDFLAGS) -o tndbm tndbm.o $(LIBS)
  
! conv2gdbm: conv2gdbm.o libgdbm.la libgdbm_compat.la @LIBOBJS@
! 	$(LIBTOOL) $(CC) $(LDFLAGS) -o conv2gdbm conv2gdbm.o $(LIBS) libgdbm_compat.la libgdbm.la @LIBOBJS@
  
  lintgdbm: 
  	lint $(DEFS) $(LFLAGS) $(DBM_CF) $(NDBM_CF) $(GDBM_CF) testgdbm.c
  
  TAGS: $(SRCS)
*************** gdbm.info: gdbm.texinfo
*** 211,222 ****
  dvi: gdbm.dvi
  
  gdbm.dvi: gdbm.texinfo
  	$(TEXI2DVI) $(srcdir)/gdbm.texinfo
  
  clean:
! 	rm -rf $(PROGS) $(TEX_F) *.a *.la *.o *.lo core *.core junk* \
  		.libs _libs
  
  mostlyclean: clean
  
  distclean: clean
--- 207,228 ----
  dvi: gdbm.dvi
  
  gdbm.dvi: gdbm.texinfo
  	$(TEXI2DVI) $(srcdir)/gdbm.texinfo
  
+ html: gdbm.html
+ 
+ gdbm.html:
+ 	perl $(srcdir)/djgpp/texi2html -expandinfo -number -monolithic $(srcdir)/gdbm.texinfo
+ 
+ ps: gdbm.ps
+ 
+ gdbm.ps: dvi
+ 	$(DVIPS) gdbm.dvi -o gdbm.ps
+ 
  clean:
! 	rm -rf $(PROGS) $(TEX_F) *.exe *.a *.la *.o *.lo core *.core junk* \
  		.libs _libs
  
  mostlyclean: clean
  
  distclean: clean
diff -acrpNC5 gdbm-1.8.3.orig/dbm.h gdbm-1.8.3.djgpp/dbm.h
*** gdbm-1.8.3.orig/dbm.h	Wed May 19 00:16:04 1999
--- gdbm-1.8.3.djgpp/dbm.h	Fri Oct 25 15:32:20 2002
***************
*** 25,35 ****
                  Bellingham, WA 98226
         
  *************************************************************************/
  
  /* The data and key structure.  This structure is defined for compatibility. */
! typedef struct {
  	char *dptr;
  	int   dsize;
        } datum;
  
  
--- 25,35 ----
                  Bellingham, WA 98226
         
  *************************************************************************/
  
  /* The data and key structure.  This structure is defined for compatibility. */
! typedef struct __tag_datum {
  	char *dptr;
  	int   dsize;
        } datum;
  
  
diff -acrpNC5 gdbm-1.8.3.orig/gdbm.3 gdbm-1.8.3.djgpp/gdbm.3
*** gdbm-1.8.3.orig/gdbm.3	Tue Oct 15 22:00:48 2002
--- gdbm-1.8.3.djgpp/gdbm.3	Fri Oct 25 19:28:28 2002
*************** writer - if database does not exist crea
*** 282,292 ****
  .br
  .B GDBM_NEWDB
  writer - create new database regardless if one exists
  .br
  For the last three (writers of the database) the following may be added
! added to \fIread_write\fR by bitwise or:
  .B GDBM_SYNC,
  which causes all database operations to be synchronized to the disk, and
  .B GDBM_NOLOCK,
  which prevents the library from performing any locking on the database file.
  The option
--- 282,292 ----
  .br
  .B GDBM_NEWDB
  writer - create new database regardless if one exists
  .br
  For the last three (writers of the database) the following may be added
! to \fIread_write\fR by bitwise or:
  .B GDBM_SYNC,
  which causes all database operations to be synchronized to the disk, and
  .B GDBM_NOLOCK,
  which prevents the library from performing any locking on the database file.
  The option
*************** parameter to the compile line, e.g.:
*** 539,549 ****
  	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
! 	gcc -o prog proc.c -lgdbm -lgdbm_compat
  
  .SH BUGS
  
  .SH "SEE ALSO"
  dbm, ndbm
--- 539,554 ----
  	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
! 	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.
  
  .SH BUGS
  
  .SH "SEE ALSO"
  dbm, ndbm
diff -acrpNC5 gdbm-1.8.3.orig/gdbm.proto gdbm-1.8.3.djgpp/gdbm.proto
*** gdbm-1.8.3.orig/gdbm.proto	Wed May 19 00:16:06 1999
--- gdbm-1.8.3.djgpp/gdbm.proto	Fri Oct 25 15:34:10 2002
***************
*** 51,68 ****
  #define  GDBM_SYNCMODE	3	/* Turn on or off sync operations. */
  #define  GDBM_CENTFREE  4	/* Keep all free blocks in the header. */
  #define  GDBM_COALESCEBLKS 5	/* Attempt to coalesce free blocks. */
  
  /* The data and key structure.  This structure is defined for compatibility. */
! typedef struct {
  	char *dptr;
  	int   dsize;
        } datum;
  
  
  /* The file information header. This is good enough for most applications. */
! typedef struct {int dummy[10];} *GDBM_FILE;
  
  /* Determine if the C(++) compiler requires complete function prototype  */
  #ifndef __P
  #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
  #define __P(x) x
--- 51,68 ----
  #define  GDBM_SYNCMODE	3	/* Turn on or off sync operations. */
  #define  GDBM_CENTFREE  4	/* Keep all free blocks in the header. */
  #define  GDBM_COALESCEBLKS 5	/* Attempt to coalesce free blocks. */
  
  /* The data and key structure.  This structure is defined for compatibility. */
! typedef struct __tag_datum {
  	char *dptr;
  	int   dsize;
        } datum;
  
  
  /* The file information header. This is good enough for most applications. */
! typedef struct __tag_gdbm_file {int dummy[10];} *GDBM_FILE;
  
  /* Determine if the C(++) compiler requires complete function prototype  */
  #ifndef __P
  #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
  #define __P(x) x
diff -acrpNC5 gdbm-1.8.3.orig/gdbm.texinfo gdbm-1.8.3.djgpp/gdbm.texinfo
*** gdbm-1.8.3.orig/gdbm.texinfo	Tue Oct 15 21:59:38 2002
--- gdbm-1.8.3.djgpp/gdbm.texinfo	Fri Oct 25 19:28:28 2002
*************** int dbm_rdonly(file);
*** 710,722 ****
  
  If you want to compile an old C program that used UNIX @code{dbm} or @code{ndbm}
  and want to use @code{gdbm} files, execute the following @code{cc} command:
  
  @example
! cc ... -L/usr/local/lib -lgdbm -lgdbm_compat
  @end example
  
  @node Conversion, Bugs, Compatibility, Top
  @chapter Converting @code{dbm} files to @code{gdbm} format.
  
  The program @code{conv2gdbm} has been provided to help you convert from @code{dbm}
  databases to @code{gdbm}. The usage is:
--- 710,727 ----
  
  If you want to compile an old C program that used UNIX @code{dbm} or @code{ndbm}
  and want to use @code{gdbm} files, execute the following @code{cc} command:
  
  @example
! 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.
+ 
  @node Conversion, Bugs, Compatibility, Top
  @chapter Converting @code{dbm} files to @code{gdbm} format.
  
  The program @code{conv2gdbm} has been provided to help you convert from @code{dbm}
  databases to @code{gdbm}. The usage is:
diff -acrpNC5 gdbm-1.8.3.orig/gdbmreorg.c gdbm-1.8.3.djgpp/gdbmreorg.c
*** gdbm-1.8.3.orig/gdbmreorg.c	Mon Oct  7 18:38:26 2002
--- gdbm-1.8.3.djgpp/gdbmreorg.c	Fri Oct 25 15:36:40 2002
*************** gdbm_reorganize (dbf)
*** 101,111 ****
        return -1;
      }
    strcpy (&new_name[0], dbf->name);
    new_name[len+2] = 0;
    new_name[len+1] = '#';
!   while ( (len > 0) && new_name[len-1] != '/')
      {
        new_name[len] = new_name[len-1];
        len -= 1;
      }
    new_name[len] = '#';
--- 101,111 ----
        return -1;
      }
    strcpy (&new_name[0], dbf->name);
    new_name[len+2] = 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] = '#';
*************** gdbm_reorganize (dbf)
*** 161,170 ****
--- 161,225 ----
    gdbm_sync (new_dbf);
  
  
    /* 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);
*************** gdbm_reorganize (dbf)
*** 213,218 ****
--- 268,275 ----
    /* 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 -acrpNC5 gdbm-1.8.3.orig/gdbmsetopt.c gdbm-1.8.3.djgpp/gdbmsetopt.c
*** gdbm-1.8.3.orig/gdbmsetopt.c	Wed May 19 00:16:06 1999
--- gdbm-1.8.3.djgpp/gdbmsetopt.c	Fri Oct 25 15:43:30 2002
*************** gdbm_setopt(dbf, optflag, optval, optlen
*** 86,107 ****
  	  {
  	    gdbm_errno = GDBM_OPT_ILLEGAL;
  	    return(-1);
  	  }
  
! 	dbf->fast_write = *optval;
  	break;
  
        case GDBM_COALESCEBLKS:
        	/* Optval will point to either true or false. */
  	if ((*optval != TRUE) && (*optval != FALSE))
  	  {
  	    gdbm_errno = GDBM_OPT_ILLEGAL;
  	    return(-1);
  	  }
  
! 	dbf->fast_write = *optval;
  	break;
  
        default:
          gdbm_errno = GDBM_OPT_ILLEGAL;
          return(-1);
--- 86,107 ----
  	  {
  	    gdbm_errno = GDBM_OPT_ILLEGAL;
  	    return(-1);
  	  }
  
! 	dbf->central_free = *optval;
  	break;
  
        case GDBM_COALESCEBLKS:
        	/* Optval will point to either true or false. */
  	if ((*optval != TRUE) && (*optval != FALSE))
  	  {
  	    gdbm_errno = GDBM_OPT_ILLEGAL;
  	    return(-1);
  	  }
  
! 	dbf->coalesce_blocks = *optval;
  	break;
  
        default:
          gdbm_errno = GDBM_OPT_ILLEGAL;
          return(-1);
diff -acrpNC5 gdbm-1.8.3.orig/ndbm.h gdbm-1.8.3.djgpp/ndbm.h
*** gdbm-1.8.3.orig/ndbm.h	Wed May 19 00:16:06 1999
--- gdbm-1.8.3.djgpp/ndbm.h	Fri Oct 25 15:44:16 2002
***************
*** 30,47 ****
  #define  DBM_INSERT  0
  #define  DBM_REPLACE 1
  
  
  /* The data and key structure.  This structure is defined for compatibility. */
! typedef struct {
  	char *dptr;
  	int   dsize;
        } datum;
  
  
  /* The file information header. This is good enough for most applications. */
! typedef struct {int dummy[10];} DBM;
  
  
  /* These are the routines (with some macros defining them!) */
  
  extern DBM 	*dbm_open ();
--- 30,47 ----
  #define  DBM_INSERT  0
  #define  DBM_REPLACE 1
  
  
  /* The data and key structure.  This structure is defined for compatibility. */
! typedef struct __tag_datum {
  	char *dptr;
  	int   dsize;
        } datum;
  
  
  /* The file information header. This is good enough for most applications. */
! typedef struct __tag_dbm {int dummy[10];} DBM;
  
  
  /* These are the routines (with some macros defining them!) */
  
  extern DBM 	*dbm_open ();
diff -acrpNC5 gdbm-1.8.3.orig/systems.h gdbm-1.8.3.djgpp/systems.h
*** gdbm-1.8.3.orig/systems.h	Mon Oct  7 18:44:30 2002
--- gdbm-1.8.3.djgpp/systems.h	Fri Oct 25 15:48:22 2002
***************
*** 85,94 ****
--- 85,109 ----
  
  #else
  
  /* Assume it is done like System V. */
  
+ #ifdef __DJGPP__
+   /*
+      DJGPP 2.03 implementation of fcntl() does not support F_GETLK, F_SETLK
+      nor F_SETLKW. To make this package work, the macros below will *NEVER*
+      invoke fcntl() at all and *ALWAYS* return success.
+      All this means that READLOCK_FILE(dbf) and WRITELOCK_FILE(dbf)
+      will set lock_val = 0 simulating file locking/unlocking success
+      when there have been done **NO** file locking/unlocking at all.
+   */
+ 
+ # define UNLOCK_FILE(dbf)    0
+ # define READLOCK_FILE(dbf)  lock_val = 0; /* simulate success. */
+ # define WRITELOCK_FILE(dbf) lock_val = 0; /* simulate success. */
+ #else /* !__DJGPP */
+ 
  #define UNLOCK_FILE(dbf) \
  	{					\
  	  struct flock flock;			\
  	  flock.l_type = F_UNLCK;		\
  	  flock.l_whence = SEEK_SET;		\
***************
*** 109,118 ****
--- 124,134 ----
  	  flock.l_type = F_WRLCK;		\
  	  flock.l_whence = SEEK_SET;			\
  	  flock.l_start = flock.l_len = 0L;	\
  	  lock_val = fcntl (dbf->desc, F_SETLK, &flock);	\
  	}
+ #endif /* !__DJGPP */
  #endif
  
  /* Do we have bcopy?  */
  #if !HAVE_BCOPY
  #if HAVE_MEMORY_H
***************
*** 144,148 ****
--- 160,179 ----
  #endif
  
  #ifndef STDERR_FILENO
  #define STDERR_FILENO 2
  #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. */
+ # define open(x, y, z)  open ((x), (y) | O_BINARY, (z))
+ # define IS_DIR_SEPARATOR(c) ((c) == ':' || (c) == '/' || (c) == '\\')
+ #else /* not O_BINARY */
+ # define O_BINARY
+ # define IS_DIR_SEPARATOR(c) ((c) == '/')
+ #endif /* not O_BINARY */
diff -acrpNC5 gdbm-1.8.3.orig/version.c gdbm-1.8.3.djgpp/version.c
*** gdbm-1.8.3.orig/version.c	Tue Oct 15 22:00:42 2002
--- gdbm-1.8.3.djgpp/version.c	Fri Oct 25 15:49:46 2002
***************
*** 27,36 ****
  *************************************************************************/
  
  #include "autoconf.h"
  
  /* Keep a string with the version number in it! */
! const char * gdbm_version = "GDBM version 1.8.3. 10/15/2002"
  #if defined(__STDC__) && defined(__DATE__) && defined(__TIME__)
  		" (built " __DATE__ " " __TIME__ ")"
  #endif
  		;
--- 27,36 ----
  *************************************************************************/
  
  #include "autoconf.h"
  
  /* Keep a string with the version number in it! */
! const char * gdbm_version = "GDBM version 1.8.3. 10/15/2002 (DJGPP port 2002-10-25 (r1))"
  #if defined(__STDC__) && defined(__DATE__) && defined(__TIME__)
  		" (built " __DATE__ " " __TIME__ ")"
  #endif
  		;
