--- /dev/null
+diff -buNr gdbm-1.8.0.orig/falloc.c gdbm-1.8.0/falloc.c
+--- gdbm-1.8.0.orig/falloc.c Tue May 18 20:16:06 1999
++++ gdbm-1.8.0/falloc.c Thu Apr 25 18:20:45 2002
+@@ -180,6 +180,13 @@
+ avail_block *new_blk;
+ int index;
+
++ if (dbf->header->avail.count == dbf->header->avail.size)
++ {
++ /* We're kind of stuck here, so we re-split the header in order to
++ avoid crashing. Sigh. */
++ push_avail_block(dbf);
++ }
++
+ /* Set up variables. */
+ new_el.av_adr = dbf->header->avail.next_block;
+ new_el.av_size = ( ( (dbf->header->avail.size * sizeof (avail_elem)) >> 1)
+@@ -196,12 +203,24 @@
+ if (num_bytes != new_el.av_size) _gdbm_fatal (dbf, "read error");
+
+ /* Add the elements from the new block to the header. */
+- for (index = 0; index < new_blk->count; index++)
++ index = 0;
++ while (index < new_blk->count)
++ {
++ while(index < new_blk->count
++ && dbf->header->avail.count < dbf->header->avail.size)
+ {
+ /* With luck, this will merge a lot of blocks! */
+ _gdbm_put_av_elem(new_blk->av_table[index],
+ dbf->header->avail.av_table,
+- &dbf->header->avail.count, dbf->coalesce_blocks);
++ &dbf->header->avail.count, TRUE);
++ index++;
++ }
++ if (dbf->header->avail.count == dbf->header->avail.size)
++ {
++ /* We're kind of stuck here, so we re-split the header in order to
++ avoid crashing. Sigh. */
++ push_avail_block(dbf);
++ }
+ }
+
+ /* Fix next_block, as well. */
+@@ -210,9 +229,17 @@
+ /* We changed the header. */
+ dbf->header_changed = TRUE;
+
+- /* Free the previous avail block. */
++ /* Free the previous avail block. It is possible that the header table
++ is now FULL, which will cause us to overflow it! */
++ if (dbf->header->avail.count == dbf->header->avail.size)
++ {
++ /* We're kind of stuck here, so we re-split the header in order to
++ avoid crashing. Sigh. */
++ push_avail_block(dbf);
++ }
++
+ _gdbm_put_av_elem (new_el, dbf->header->avail.av_table,
+- &dbf->header->avail.count, dbf->coalesce_blocks);
++ &dbf->header->avail.count, TRUE);
+ free (new_blk);
+ }
+
--- /dev/null
+diff -urN gdbm-1.8.0.orig/configure.in gdbm-1.8.0.flock/configure.in
+--- gdbm-1.8.0.orig/configure.in 1999-05-19 01:17:02.000000000 +0100
++++ gdbm-1.8.0.flock/configure.in 2008-10-03 16:55:30.000000000 +0100
+@@ -5,6 +5,7 @@
+ AC_PROG_CC
+ AC_PROG_CPP
+ AC_PROG_INSTALL
++AC_LIBTOOL_WIN32_DLL
+ AM_PROG_LIBTOOL
+ dnl AC_PROG_RANLIB
+ dnl AC_WORDS_BIGENDIAN
+@@ -13,8 +14,8 @@
+ AC_HAVE_HEADERS(memory.h)
+ AC_CHECK_LIB(dbm, main)
+ AC_CHECK_LIB(ndbm, main)
+-AC_HAVE_FUNCS(rename ftruncate flock bcopy fsync)
+-AC_REPLACE_FUNCS(getopt)
++AC_HAVE_FUNCS(rename ftruncate bcopy)
++AC_REPLACE_FUNCS(flock fsync getopt)
+ AC_OFF_T
+ AC_ST_BLKSIZE
+ AC_OUTPUT(Makefile)
+diff -urN gdbm-1.8.0.orig/dbminit.c gdbm-1.8.0.flock/dbminit.c
+--- gdbm-1.8.0.orig/dbminit.c 1999-05-19 01:16:05.000000000 +0100
++++ gdbm-1.8.0.flock/dbminit.c 2008-10-03 17:07:20.000000000 +0100
+@@ -91,6 +91,7 @@
+ }
+ }
+
++#if (!defined _WIN32 && !defined __WIN32__) || defined __CYGWIN__
+ /* If the database is new, link "file.dir" to "file.pag". This is done
+ so the time stamp on both files is the same. */
+ if (stat (dir_file, &dir_stat) == 0)
+@@ -116,6 +117,7 @@
+ goto done;
+ }
+ }
++#endif
+
+ ret = 0;
+
+diff -urN gdbm-1.8.0.orig/dbmopen.c gdbm-1.8.0.flock/dbmopen.c
+--- gdbm-1.8.0.orig/dbmopen.c 1999-05-19 01:16:05.000000000 +0100
++++ gdbm-1.8.0.flock/dbmopen.c 2008-10-03 17:07:33.000000000 +0100
+@@ -105,6 +105,7 @@
+ goto done;
+ }
+
++#if (!defined _WIN32 && !defined __WIN32__) || defined __CYGWIN__
+ /* If the database is new, link "file.dir" to "file.pag". This is done
+ so the time stamp on both files is the same. */
+ if (stat (dir_file, &dir_stat) == 0)
+@@ -130,6 +131,7 @@
+ goto done;
+ }
+ }
++#endif
+
+ done:
+ free (pag_file);
+diff -urN gdbm-1.8.0.orig/flock.c gdbm-1.8.0.flock/flock.c
+--- gdbm-1.8.0.orig/flock.c 1970-01-01 01:00:00.000000000 +0100
++++ gdbm-1.8.0.flock/flock.c 2008-10-03 17:02:01.000000000 +0100
+@@ -0,0 +1,212 @@
++/* Emulate flock on platforms that lack it, primarily Windows and MinGW.
++
++ This is derived from sqlite3 sources.
++ http://www.sqlite.org/cvstrac/rlog?f=sqlite/src/os_win.c
++ http://www.sqlite.org/copyright.html
++
++ Written by Richard W.M. Jones <rjones.at.redhat.com>
++
++ Copyright (C) 2008 Free Software Foundation, Inc.
++
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Lesser General Public
++ License as published by the Free Software Foundation; either
++ version 2.1 of the License, or (at your option) any later version.
++
++ This library 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
++ Lesser General Public License for more details.
++
++ You should have received a copy of the GNU General Public License
++ along with this program. If not, see <http://www.gnu.org/licenses/>. */
++
++#include <autoconf.h>
++#include "systems.h"
++
++#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
++
++/* _get_osfhandle */
++#include <io.h>
++
++/* LockFileEx */
++#define WIN32_LEAN_AND_MEAN
++#include <windows.h>
++
++#include <errno.h>
++
++/* Determine the current size of a file. Because the other braindead
++ * APIs we'll call need lower/upper 32 bit pairs, keep the file size
++ * like that too.
++ */
++static BOOL
++file_size (HANDLE h, DWORD * lower, DWORD * upper)
++{
++ *lower = GetFileSize (h, upper);
++ return 1;
++}
++
++/* LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems. */
++#ifndef LOCKFILE_FAIL_IMMEDIATELY
++# define LOCKFILE_FAIL_IMMEDIATELY 1
++#endif
++
++/* Acquire a lock. */
++static BOOL
++do_lock (HANDLE h, int non_blocking, int exclusive)
++{
++ BOOL res;
++ DWORD size_lower, size_upper;
++ OVERLAPPED ovlp;
++ int flags = 0;
++
++ /* We're going to lock the whole file, so get the file size. */
++ res = file_size (h, &size_lower, &size_upper);
++ if (!res)
++ return 0;
++
++ /* Start offset is 0, and also zero the remaining members of this struct. */
++ memset (&ovlp, 0, sizeof ovlp);
++
++ if (non_blocking)
++ flags |= LOCKFILE_FAIL_IMMEDIATELY;
++ if (exclusive)
++ flags |= LOCKFILE_EXCLUSIVE_LOCK;
++
++ return LockFileEx (h, flags, 0, size_lower, size_upper, &ovlp);
++}
++
++/* Unlock reader or exclusive lock. */
++static BOOL
++do_unlock (HANDLE h)
++{
++ int res;
++ DWORD size_lower, size_upper;
++
++ res = file_size (h, &size_lower, &size_upper);
++ if (!res)
++ return 0;
++
++ return UnlockFile (h, 0, 0, size_lower, size_upper);
++}
++
++/* Now our BSD-like flock operation. */
++int
++flock (int fd, int operation)
++{
++ HANDLE h = (HANDLE) _get_osfhandle (fd);
++ DWORD res;
++ int non_blocking;
++
++ if (h == INVALID_HANDLE_VALUE)
++ {
++ errno = EBADF;
++ return -1;
++ }
++
++ non_blocking = operation & LOCK_NB;
++ operation &= ~LOCK_NB;
++
++ switch (operation)
++ {
++ case LOCK_SH:
++ res = do_lock (h, non_blocking, 0);
++ break;
++ case LOCK_EX:
++ res = do_lock (h, non_blocking, 1);
++ break;
++ case LOCK_UN:
++ res = do_unlock (h);
++ break;
++ default:
++ errno = EINVAL;
++ return -1;
++ }
++
++ /* Map Windows errors into Unix errnos. As usual MSDN fails to
++ * document the permissible error codes.
++ */
++ if (!res)
++ {
++ DWORD err = GetLastError ();
++ switch (err)
++ {
++ /* This means someone else is holding a lock. */
++ case ERROR_LOCK_VIOLATION:
++ errno = EAGAIN;
++ break;
++
++ /* Out of memory. */
++ case ERROR_NOT_ENOUGH_MEMORY:
++ errno = ENOMEM;
++ break;
++
++ case ERROR_BAD_COMMAND:
++ errno = EINVAL;
++ break;
++
++ /* Unlikely to be other errors, but at least don't lose the
++ * error code.
++ */
++ default:
++ errno = err;
++ }
++
++ return -1;
++ }
++
++ return 0;
++}
++
++#else /* !Windows */
++
++/* We know how to implement flock in terms of fcntl. */
++
++#ifdef HAVE_FCNTL_H
++#include <fcntl.h>
++#endif
++
++#ifdef HAVE_UNISTD_H
++#include <unistd.h>
++#endif
++
++int
++flock (int fd, int operation)
++{
++ int cmd, r;
++ struct flock fl;
++
++ if (operation & LOCK_NB)
++ cmd = F_SETLK;
++ else
++ cmd = F_SETLKW;
++ operation &= ~LOCK_NB;
++
++ memset (&fl, 0, sizeof fl);
++ fl.l_whence = SEEK_SET;
++ /* l_start & l_len are 0, which as a special case means "whole file". */
++
++ switch (operation)
++ {
++ case LOCK_SH:
++ fl.l_type = F_RDLCK;
++ break;
++ case LOCK_EX:
++ fl.l_type = F_WRLCK;
++ break;
++ case LOCK_UN:
++ fl.l_type = F_UNLCK;
++ break;
++ default:
++ errno = EINVAL;
++ return -1;
++ }
++
++ r = fcntl (fd, cmd, &fl);
++ if (r == -1 && errno == EACCES)
++ errno = EAGAIN;
++
++ return r;
++}
++
++#endif /* !Windows */
+diff -urN gdbm-1.8.0.orig/fsync.c gdbm-1.8.0.flock/fsync.c
+--- gdbm-1.8.0.orig/fsync.c 1970-01-01 01:00:00.000000000 +0100
++++ gdbm-1.8.0.flock/fsync.c 2008-10-03 17:02:15.000000000 +0100
+@@ -0,0 +1,83 @@
++/* Emulate fsync on platforms that lack it, primarily Windows and
++ cross-compilers like MinGW.
++
++ This is derived from sqlite3 sources.
++ http://www.sqlite.org/cvstrac/rlog?f=sqlite/src/os_win.c
++ http://www.sqlite.org/copyright.html
++
++ Written by Richard W.M. Jones <rjones.at.redhat.com>
++
++ Copyright (C) 2008 Free Software Foundation, Inc.
++
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Lesser General Public
++ License as published by the Free Software Foundation; either
++ version 2.1 of the License, or (at your option) any later version.
++
++ This library 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
++ Lesser General Public License for more details.
++
++ You should have received a copy of the GNU General Public License
++ along with this program. If not, see <http://www.gnu.org/licenses/>. */
++
++#include <autoconf.h>
++#include "systems.h"
++#include <unistd.h>
++
++#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
++
++/* _get_osfhandle */
++#include <io.h>
++
++/* FlushFileBuffers */
++#define WIN32_LEAN_AND_MEAN
++#include <windows.h>
++
++#include <errno.h>
++
++int
++fsync (int fd)
++{
++ HANDLE h = (HANDLE) _get_osfhandle (fd);
++ DWORD err;
++
++ if (h == INVALID_HANDLE_VALUE)
++ {
++ errno = EBADF;
++ return -1;
++ }
++
++ if (!FlushFileBuffers (h))
++ {
++ /* Translate some Windows errors into rough approximations of Unix
++ * errors. MSDN is useless as usual - in this case it doesn't
++ * document the full range of errors.
++ */
++ err = GetLastError ();
++ switch (err)
++ {
++ /* eg. Trying to fsync a tty. */
++ case ERROR_INVALID_HANDLE:
++ errno = EINVAL;
++ break;
++
++ default:
++ errno = EIO;
++ }
++ return -1;
++ }
++
++ return 0;
++}
++
++#else /* !Windows */
++
++int fsync (int fd)
++{
++ sync ();
++ sync ();
++}
++
++#endif /* !Windows */
+diff -urN gdbm-1.8.0.orig/Makefile.in gdbm-1.8.0.flock/Makefile.in
+--- gdbm-1.8.0.orig/Makefile.in 2008-10-03 16:32:57.000000000 +0100
++++ gdbm-1.8.0.flock/Makefile.in 2008-10-03 17:12:25.000000000 +0100
+@@ -20,7 +20,7 @@
+ DEFS = @DEFS@
+
+ # Where the system [n]dbm routines are...
+-LIBS = @LIBS@ -lc
++LIBS = @LIBS@
+
+ # SunOS 4 users might wish to add '-fpcc-struct-return' to CFLAGS. see INSTALL.
+ CPPFLAGS = @CPPFLAGS@
+@@ -132,10 +132,10 @@
+ # ar q libgdbm.a $(OBJS)
+ # $(RANLIB) libgdbm.a
+
+-libgdbm.la: $(LOBJS) gdbm.h
++libgdbm.la: $(LOBJS) @LTLIBOBJS@ gdbm.h
+ rm -f libgdbm.la
+ $(LIBTOOL) --mode=link $(CC) -o libgdbm.la -rpath $(libdir) \
+- -version-info $(SHLIB_VER) $(LOBJS)
++ -version-info $(SHLIB_VER) -no-undefined $(LOBJS) @LTLIBOBJS@
+
+ gdbm.h: gdbm.proto gdbmerrno.h gdbm.proto2
+ rm -f gdbm.h
+@@ -146,19 +146,19 @@
+ chmod -w gdbm.h
+
+ testgdbm: testgdbm.o libgdbm.la @LIBOBJS@
+- $(LIBTOOL) $(CC) $(LDFLAGS) -o testgdbm testgdbm.o libgdbm.la @LIBOBJS@
++ $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o testgdbm testgdbm.o libgdbm.la @LIBOBJS@
+
+ testdbm: testdbm.o libgdbm.la
+- $(LIBTOOL) $(CC) $(LDFLAGS) -o testdbm testdbm.o libgdbm.la
++ $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o testdbm testdbm.o libgdbm.la
+
+ tdbm: testdbm.o
+- $(CC) $(LDFLAGS) -o tdbm testdbm.o $(LIBS)
++ $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o tdbm testdbm.o libgdbm.la $(LIBS)
+
+ testndbm.o: testndbm.c
+ $(CC) -c -I. -I$(srcdir) $(CFLAGS) $(DEFS) -DGNU $(srcdir)/testndbm.c
+
+ testndbm: testndbm.o libgdbm.la
+- $(LIBTOOL) $(CC) $(LDFLAGS) -o testndbm testndbm.o libgdbm.la
++ $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o testndbm testndbm.o libgdbm.la
+
+ tndbm.o: testndbm.c
+ cp $(srcdir)/testndbm.c ./tndbm.c
+@@ -166,10 +166,10 @@
+ rm -f ./tndbm.c
+
+ tndbm: tndbm.o
+- $(CC) $(LDFLAGS) -o tndbm tndbm.o $(LIBS)
++ $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o tndbm tndbm.o libgdbm.la $(LIBS)
+
+ conv2gdbm: conv2gdbm.o libgdbm.la @LIBOBJS@
+- $(LIBTOOL) $(CC) $(LDFLAGS) -o conv2gdbm conv2gdbm.o $(LIBS) libgdbm.la @LIBOBJS@
++ $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o conv2gdbm conv2gdbm.o $(LIBS) libgdbm.la @LIBOBJS@
+
+ lintgdbm:
+ lint $(DEFS) $(LFLAGS) $(DBM_CF) $(NDBM_CF) $(GDBM_CF) testgdbm.c
+diff -urN gdbm-1.8.0.orig/systems.h gdbm-1.8.0.flock/systems.h
+--- gdbm-1.8.0.orig/systems.h 1999-05-19 03:09:46.000000000 +0100
++++ gdbm-1.8.0.flock/systems.h 2008-10-03 16:54:09.000000000 +0100
+@@ -59,9 +59,9 @@
+ #define L_SET SEEK_SET
+ #endif
+
+-/* Do we have flock? (BSD...) */
+-
+-#if HAVE_FLOCK
++#ifndef HAVE_FLOCK
++extern int flock (int fd, int operation);
++#endif
+
+ #ifndef LOCK_SH
+ #define LOCK_SH 1
+@@ -83,36 +83,6 @@
+ #define READLOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_SH + LOCK_NB)
+ #define WRITELOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_EX + LOCK_NB)
+
+-#else
+-
+-/* Assume it is done like System V. */
+-
+-#define UNLOCK_FILE(dbf) \
+- { \
+- struct flock flock; \
+- flock.l_type = F_UNLCK; \
+- flock.l_whence = SEEK_SET; \
+- flock.l_start = flock.l_len = 0L; \
+- fcntl (dbf->desc, F_SETLK, &flock); \
+- }
+-#define READLOCK_FILE(dbf) \
+- { \
+- struct flock flock; \
+- flock.l_type = F_RDLCK; \
+- flock.l_whence = SEEK_SET; \
+- flock.l_start = flock.l_len = 0L; \
+- lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
+- }
+-#define WRITELOCK_FILE(dbf) \
+- { \
+- struct flock flock; \
+- 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
+-
+ /* Do we have bcopy? */
+ #if !HAVE_BCOPY
+ #if HAVE_MEMORY_H
+@@ -122,9 +92,8 @@
+ #define bcopy(d1, d2, n) memcpy(d2, d1, n)
+ #endif
+
+-/* Do we have fsync? */
+-#if !HAVE_FSYNC
+-#define fsync(f) {sync(); sync();}
++#ifndef HAVE_FSYNC
++extern int fsync (int fd);
+ #endif
+
+ /* Default block size. Some systems do not have blocksize in their
--- /dev/null
+%define __strip %{_mingw32_strip}
+%define __objdump %{_mingw32_objdump}
+%define _use_internal_dependency_generator 0
+%define __find_requires %{_mingw32_findrequires}
+%define __find_provides %{_mingw32_findprovides}
+
+Name: mingw32-gdbm
+Version: 1.8.0
+Release: 1%{?dist}
+Summary: MinGW port of GNU database routines
+
+License: GPLv2+
+Group: Development/Libraries
+URL: http://www.gnu.org/software/gdbm/
+Source0: ftp://ftp.gnu.org/gnu/gdbm/gdbm-%{version}.tar.gz
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+
+Patch0: gdbm-1.8.0-jbj.patch
+Patch1: gdbm-1.8.0-fhs.patch
+Patch2: gdbm-1.8.0-cflags.patch
+Patch3: gdbm-1.8.0-64offset.patch
+
+Patch100: mingw32-gdbm-1.8.0-windows.patch
+
+BuildArch: noarch
+
+BuildRequires: mingw32-filesystem >= 26
+BuildRequires: mingw32-gcc
+BuildRequires: mingw32-binutils
+
+BuildRequires: libtool
+
+
+%description
+Gdbm is a GNU database indexing library, including routines which use
+extensible hashing. Gdbm works in a similar way to standard UNIX dbm
+routines. Gdbm is useful for developers who write C applications and
+need access to a simple and efficient database or who are building C
+applications which will use such a database.
+
+This is the MinGW Windows port of the libraries and development tools.
+
+
+%prep
+%setup -q -n gdbm-%{version}
+%patch0 -p 1 -b .jbj
+%patch1 -p 1 -b .fhs
+%patch2 -p 1 -b .cflags
+%patch3 -p1 -b .offset
+
+%patch100 -p1 -b .windows
+
+
+%build
+libtoolize --force --copy
+aclocal
+autoreconf
+%{_mingw32_configure}
+make libdir=%{_mingw32_libdir} all progs
+
+
+%install
+rm -rf $RPM_BUILD_ROOT
+make prefix=$RPM_BUILD_ROOT%{_mingw32_prefix} install
+
+# Install the binaries. Arguable whether we really want these.
+install conv2gdbm.exe tdbm.exe testdbm.exe testgdbm.exe testndbm.exe tndbm.exe \
+ $RPM_BUILD_ROOT%{_mingw32_bindir}
+
+# Native Fedora package seems to fluff this, but as far as I
+# can tell they are trying to create <gdbm/gdbm.h> which
+# links to <gdbm.h>.
+pushd $RPM_BUILD_ROOT%{_mingw32_includedir}
+mkdir gdbm
+cd gdbm
+ln -s ../gdbm.h
+popd
+
+# Remove the static library.
+rm $RPM_BUILD_ROOT%{_mingw32_libdir}/libgdbm.a
+
+# Remove man page and info file which duplicate what is in native package.
+rm -r $RPM_BUILD_ROOT%{_mingw32_prefix}/man
+rm -r $RPM_BUILD_ROOT%{_mingw32_prefix}/info
+
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+
+%files
+%defattr(-,root,root)
+%{_mingw32_bindir}/conv2gdbm.exe
+%{_mingw32_bindir}/tdbm.exe
+%{_mingw32_bindir}/testdbm.exe
+%{_mingw32_bindir}/testgdbm.exe
+%{_mingw32_bindir}/testndbm.exe
+%{_mingw32_bindir}/tndbm.exe
+%{_mingw32_bindir}/libgdbm-2.dll
+%{_mingw32_libdir}/libgdbm.dll.a
+%{_mingw32_libdir}/libgdbm.la
+%{_mingw32_includedir}/gdbm.h
+%{_mingw32_includedir}/gdbm
+
+
+%changelog
+* Fri Oct 3 2008 Richard W.M. Jones <rjones@redhat.com> - 1.8.0-1
+- Initial RPM release.