1 diff -urN gdbm-1.8.0.orig/configure.in gdbm-1.8.0.flock/configure.in
2 --- gdbm-1.8.0.orig/configure.in 1999-05-19 01:17:02.000000000 +0100
3 +++ gdbm-1.8.0.flock/configure.in 2008-10-03 16:55:30.000000000 +0100
11 dnl AC_WORDS_BIGENDIAN
13 AC_HAVE_HEADERS(memory.h)
14 AC_CHECK_LIB(dbm, main)
15 AC_CHECK_LIB(ndbm, main)
16 -AC_HAVE_FUNCS(rename ftruncate flock bcopy fsync)
17 -AC_REPLACE_FUNCS(getopt)
18 +AC_HAVE_FUNCS(rename ftruncate bcopy)
19 +AC_REPLACE_FUNCS(flock fsync getopt)
23 diff -urN gdbm-1.8.0.orig/dbminit.c gdbm-1.8.0.flock/dbminit.c
24 --- gdbm-1.8.0.orig/dbminit.c 1999-05-19 01:16:05.000000000 +0100
25 +++ gdbm-1.8.0.flock/dbminit.c 2008-10-03 17:07:20.000000000 +0100
30 +#if (!defined _WIN32 && !defined __WIN32__) || defined __CYGWIN__
31 /* If the database is new, link "file.dir" to "file.pag". This is done
32 so the time stamp on both files is the same. */
33 if (stat (dir_file, &dir_stat) == 0)
42 diff -urN gdbm-1.8.0.orig/dbmopen.c gdbm-1.8.0.flock/dbmopen.c
43 --- gdbm-1.8.0.orig/dbmopen.c 1999-05-19 01:16:05.000000000 +0100
44 +++ gdbm-1.8.0.flock/dbmopen.c 2008-10-03 17:07:33.000000000 +0100
49 +#if (!defined _WIN32 && !defined __WIN32__) || defined __CYGWIN__
50 /* If the database is new, link "file.dir" to "file.pag". This is done
51 so the time stamp on both files is the same. */
52 if (stat (dir_file, &dir_stat) == 0)
61 diff -urN gdbm-1.8.0.orig/flock.c gdbm-1.8.0.flock/flock.c
62 --- gdbm-1.8.0.orig/flock.c 1970-01-01 01:00:00.000000000 +0100
63 +++ gdbm-1.8.0.flock/flock.c 2008-10-03 17:02:01.000000000 +0100
65 +/* Emulate flock on platforms that lack it, primarily Windows and MinGW.
67 + This is derived from sqlite3 sources.
68 + http://www.sqlite.org/cvstrac/rlog?f=sqlite/src/os_win.c
69 + http://www.sqlite.org/copyright.html
71 + Written by Richard W.M. Jones <rjones.at.redhat.com>
73 + Copyright (C) 2008 Free Software Foundation, Inc.
75 + This library is free software; you can redistribute it and/or
76 + modify it under the terms of the GNU Lesser General Public
77 + License as published by the Free Software Foundation; either
78 + version 2.1 of the License, or (at your option) any later version.
80 + This library is distributed in the hope that it will be useful,
81 + but WITHOUT ANY WARRANTY; without even the implied warranty of
82 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
83 + Lesser General Public License for more details.
85 + You should have received a copy of the GNU General Public License
86 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
88 +#include <autoconf.h>
91 +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
97 +#define WIN32_LEAN_AND_MEAN
102 +/* Determine the current size of a file. Because the other braindead
103 + * APIs we'll call need lower/upper 32 bit pairs, keep the file size
107 +file_size (HANDLE h, DWORD * lower, DWORD * upper)
109 + *lower = GetFileSize (h, upper);
113 +/* LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems. */
114 +#ifndef LOCKFILE_FAIL_IMMEDIATELY
115 +# define LOCKFILE_FAIL_IMMEDIATELY 1
118 +/* Acquire a lock. */
120 +do_lock (HANDLE h, int non_blocking, int exclusive)
123 + DWORD size_lower, size_upper;
127 + /* We're going to lock the whole file, so get the file size. */
128 + res = file_size (h, &size_lower, &size_upper);
132 + /* Start offset is 0, and also zero the remaining members of this struct. */
133 + memset (&ovlp, 0, sizeof ovlp);
136 + flags |= LOCKFILE_FAIL_IMMEDIATELY;
138 + flags |= LOCKFILE_EXCLUSIVE_LOCK;
140 + return LockFileEx (h, flags, 0, size_lower, size_upper, &ovlp);
143 +/* Unlock reader or exclusive lock. */
145 +do_unlock (HANDLE h)
148 + DWORD size_lower, size_upper;
150 + res = file_size (h, &size_lower, &size_upper);
154 + return UnlockFile (h, 0, 0, size_lower, size_upper);
157 +/* Now our BSD-like flock operation. */
159 +flock (int fd, int operation)
161 + HANDLE h = (HANDLE) _get_osfhandle (fd);
165 + if (h == INVALID_HANDLE_VALUE)
171 + non_blocking = operation & LOCK_NB;
172 + operation &= ~LOCK_NB;
177 + res = do_lock (h, non_blocking, 0);
180 + res = do_lock (h, non_blocking, 1);
183 + res = do_unlock (h);
190 + /* Map Windows errors into Unix errnos. As usual MSDN fails to
191 + * document the permissible error codes.
195 + DWORD err = GetLastError ();
198 + /* This means someone else is holding a lock. */
199 + case ERROR_LOCK_VIOLATION:
203 + /* Out of memory. */
204 + case ERROR_NOT_ENOUGH_MEMORY:
208 + case ERROR_BAD_COMMAND:
212 + /* Unlikely to be other errors, but at least don't lose the
225 +#else /* !Windows */
227 +/* We know how to implement flock in terms of fcntl. */
233 +#ifdef HAVE_UNISTD_H
238 +flock (int fd, int operation)
243 + if (operation & LOCK_NB)
247 + operation &= ~LOCK_NB;
249 + memset (&fl, 0, sizeof fl);
250 + fl.l_whence = SEEK_SET;
251 + /* l_start & l_len are 0, which as a special case means "whole file". */
256 + fl.l_type = F_RDLCK;
259 + fl.l_type = F_WRLCK;
262 + fl.l_type = F_UNLCK;
269 + r = fcntl (fd, cmd, &fl);
270 + if (r == -1 && errno == EACCES)
276 +#endif /* !Windows */
277 diff -urN gdbm-1.8.0.orig/fsync.c gdbm-1.8.0.flock/fsync.c
278 --- gdbm-1.8.0.orig/fsync.c 1970-01-01 01:00:00.000000000 +0100
279 +++ gdbm-1.8.0.flock/fsync.c 2008-10-03 17:02:15.000000000 +0100
281 +/* Emulate fsync on platforms that lack it, primarily Windows and
282 + cross-compilers like MinGW.
284 + This is derived from sqlite3 sources.
285 + http://www.sqlite.org/cvstrac/rlog?f=sqlite/src/os_win.c
286 + http://www.sqlite.org/copyright.html
288 + Written by Richard W.M. Jones <rjones.at.redhat.com>
290 + Copyright (C) 2008 Free Software Foundation, Inc.
292 + This library is free software; you can redistribute it and/or
293 + modify it under the terms of the GNU Lesser General Public
294 + License as published by the Free Software Foundation; either
295 + version 2.1 of the License, or (at your option) any later version.
297 + This library is distributed in the hope that it will be useful,
298 + but WITHOUT ANY WARRANTY; without even the implied warranty of
299 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
300 + Lesser General Public License for more details.
302 + You should have received a copy of the GNU General Public License
303 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
305 +#include <autoconf.h>
306 +#include "systems.h"
309 +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
311 +/* _get_osfhandle */
314 +/* FlushFileBuffers */
315 +#define WIN32_LEAN_AND_MEAN
316 +#include <windows.h>
323 + HANDLE h = (HANDLE) _get_osfhandle (fd);
326 + if (h == INVALID_HANDLE_VALUE)
332 + if (!FlushFileBuffers (h))
334 + /* Translate some Windows errors into rough approximations of Unix
335 + * errors. MSDN is useless as usual - in this case it doesn't
336 + * document the full range of errors.
338 + err = GetLastError ();
341 + /* eg. Trying to fsync a tty. */
342 + case ERROR_INVALID_HANDLE:
355 +#else /* !Windows */
363 +#endif /* !Windows */
364 diff -urN gdbm-1.8.0.orig/Makefile.in gdbm-1.8.0.flock/Makefile.in
365 --- gdbm-1.8.0.orig/Makefile.in 2008-10-03 16:32:57.000000000 +0100
366 +++ gdbm-1.8.0.flock/Makefile.in 2008-10-03 17:12:25.000000000 +0100
370 # Where the system [n]dbm routines are...
374 # SunOS 4 users might wish to add '-fpcc-struct-return' to CFLAGS. see INSTALL.
375 CPPFLAGS = @CPPFLAGS@
376 @@ -132,10 +132,10 @@
377 # ar q libgdbm.a $(OBJS)
378 # $(RANLIB) libgdbm.a
380 -libgdbm.la: $(LOBJS) gdbm.h
381 +libgdbm.la: $(LOBJS) @LTLIBOBJS@ gdbm.h
383 $(LIBTOOL) --mode=link $(CC) -o libgdbm.la -rpath $(libdir) \
384 - -version-info $(SHLIB_VER) $(LOBJS)
385 + -version-info $(SHLIB_VER) -no-undefined $(LOBJS) @LTLIBOBJS@
387 gdbm.h: gdbm.proto gdbmerrno.h gdbm.proto2
389 @@ -146,19 +146,19 @@
392 testgdbm: testgdbm.o libgdbm.la @LIBOBJS@
393 - $(LIBTOOL) $(CC) $(LDFLAGS) -o testgdbm testgdbm.o libgdbm.la @LIBOBJS@
394 + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o testgdbm testgdbm.o libgdbm.la @LIBOBJS@
396 testdbm: testdbm.o libgdbm.la
397 - $(LIBTOOL) $(CC) $(LDFLAGS) -o testdbm testdbm.o libgdbm.la
398 + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o testdbm testdbm.o libgdbm.la
401 - $(CC) $(LDFLAGS) -o tdbm testdbm.o $(LIBS)
402 + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o tdbm testdbm.o libgdbm.la $(LIBS)
404 testndbm.o: testndbm.c
405 $(CC) -c -I. -I$(srcdir) $(CFLAGS) $(DEFS) -DGNU $(srcdir)/testndbm.c
407 testndbm: testndbm.o libgdbm.la
408 - $(LIBTOOL) $(CC) $(LDFLAGS) -o testndbm testndbm.o libgdbm.la
409 + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o testndbm testndbm.o libgdbm.la
412 cp $(srcdir)/testndbm.c ./tndbm.c
413 @@ -166,10 +166,10 @@
417 - $(CC) $(LDFLAGS) -o tndbm tndbm.o $(LIBS)
418 + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o tndbm tndbm.o libgdbm.la $(LIBS)
420 conv2gdbm: conv2gdbm.o libgdbm.la @LIBOBJS@
421 - $(LIBTOOL) $(CC) $(LDFLAGS) -o conv2gdbm conv2gdbm.o $(LIBS) libgdbm.la @LIBOBJS@
422 + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o conv2gdbm conv2gdbm.o $(LIBS) libgdbm.la @LIBOBJS@
425 lint $(DEFS) $(LFLAGS) $(DBM_CF) $(NDBM_CF) $(GDBM_CF) testgdbm.c
426 diff -urN gdbm-1.8.0.orig/systems.h gdbm-1.8.0.flock/systems.h
427 --- gdbm-1.8.0.orig/systems.h 1999-05-19 03:09:46.000000000 +0100
428 +++ gdbm-1.8.0.flock/systems.h 2008-10-03 16:54:09.000000000 +0100
430 #define L_SET SEEK_SET
433 -/* Do we have flock? (BSD...) */
437 +extern int flock (int fd, int operation);
443 #define READLOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_SH + LOCK_NB)
444 #define WRITELOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_EX + LOCK_NB)
448 -/* Assume it is done like System V. */
450 -#define UNLOCK_FILE(dbf) \
452 - struct flock flock; \
453 - flock.l_type = F_UNLCK; \
454 - flock.l_whence = SEEK_SET; \
455 - flock.l_start = flock.l_len = 0L; \
456 - fcntl (dbf->desc, F_SETLK, &flock); \
458 -#define READLOCK_FILE(dbf) \
460 - struct flock flock; \
461 - flock.l_type = F_RDLCK; \
462 - flock.l_whence = SEEK_SET; \
463 - flock.l_start = flock.l_len = 0L; \
464 - lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
466 -#define WRITELOCK_FILE(dbf) \
468 - struct flock flock; \
469 - flock.l_type = F_WRLCK; \
470 - flock.l_whence = SEEK_SET; \
471 - flock.l_start = flock.l_len = 0L; \
472 - lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
476 /* Do we have bcopy? */
480 #define bcopy(d1, d2, n) memcpy(d2, d1, n)
483 -/* Do we have fsync? */
485 -#define fsync(f) {sync(); sync();}
487 +extern int fsync (int fd);
490 /* Default block size. Some systems do not have blocksize in their