Add license files to doc section.
[fedora-mingw.git] / gdbm / mingw32-gdbm-1.8.0-windows.patch
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
4 @@ -5,6 +5,7 @@
5  AC_PROG_CC
6  AC_PROG_CPP
7  AC_PROG_INSTALL
8 +AC_LIBTOOL_WIN32_DLL
9  AM_PROG_LIBTOOL
10  dnl AC_PROG_RANLIB
11  dnl AC_WORDS_BIGENDIAN
12 @@ -13,8 +14,8 @@
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)
20  AC_OFF_T
21  AC_ST_BLKSIZE
22  AC_OUTPUT(Makefile)
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
26 @@ -91,6 +91,7 @@
27         }
28      }
29  
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)
34 @@ -116,6 +117,7 @@
35           goto done;
36         }
37      }
38 +#endif
39  
40    ret = 0;
41  
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
45 @@ -105,6 +105,7 @@
46        goto done;
47      }
48  
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)
53 @@ -130,6 +131,7 @@
54           goto done;
55         }
56      }
57 +#endif
58  
59  done:
60    free (pag_file);
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
64 @@ -0,0 +1,212 @@
65 +/* Emulate flock on platforms that lack it, primarily Windows and MinGW.
66 +
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
70 +
71 +   Written by Richard W.M. Jones <rjones.at.redhat.com>
72 +
73 +   Copyright (C) 2008 Free Software Foundation, Inc.
74 +
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.
79 +
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.
84 +
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/>.  */
87 +
88 +#include <autoconf.h>
89 +#include "systems.h"
90 +
91 +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
92 +
93 +/* _get_osfhandle */
94 +#include <io.h>
95 +
96 +/* LockFileEx */
97 +#define WIN32_LEAN_AND_MEAN
98 +#include <windows.h>
99 +
100 +#include <errno.h>
101 +
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
104 + * like that too.
105 + */
106 +static BOOL
107 +file_size (HANDLE h, DWORD * lower, DWORD * upper)
108 +{
109 +  *lower = GetFileSize (h, upper);
110 +  return 1;
111 +}
112 +
113 +/* LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems. */
114 +#ifndef LOCKFILE_FAIL_IMMEDIATELY
115 +# define LOCKFILE_FAIL_IMMEDIATELY 1
116 +#endif
117 +
118 +/* Acquire a lock. */
119 +static BOOL
120 +do_lock (HANDLE h, int non_blocking, int exclusive)
121 +{
122 +  BOOL res;
123 +  DWORD size_lower, size_upper;
124 +  OVERLAPPED ovlp;
125 +  int flags = 0;
126 +
127 +  /* We're going to lock the whole file, so get the file size. */
128 +  res = file_size (h, &size_lower, &size_upper);
129 +  if (!res)
130 +    return 0;
131 +
132 +  /* Start offset is 0, and also zero the remaining members of this struct. */
133 +  memset (&ovlp, 0, sizeof ovlp);
134 +
135 +  if (non_blocking)
136 +    flags |= LOCKFILE_FAIL_IMMEDIATELY;
137 +  if (exclusive)
138 +    flags |= LOCKFILE_EXCLUSIVE_LOCK;
139 +
140 +  return LockFileEx (h, flags, 0, size_lower, size_upper, &ovlp);
141 +}
142 +
143 +/* Unlock reader or exclusive lock. */
144 +static BOOL
145 +do_unlock (HANDLE h)
146 +{
147 +  int res;
148 +  DWORD size_lower, size_upper;
149 +
150 +  res = file_size (h, &size_lower, &size_upper);
151 +  if (!res)
152 +    return 0;
153 +
154 +  return UnlockFile (h, 0, 0, size_lower, size_upper);
155 +}
156 +
157 +/* Now our BSD-like flock operation. */
158 +int
159 +flock (int fd, int operation)
160 +{
161 +  HANDLE h = (HANDLE) _get_osfhandle (fd);
162 +  DWORD res;
163 +  int non_blocking;
164 +
165 +  if (h == INVALID_HANDLE_VALUE)
166 +    {
167 +      errno = EBADF;
168 +      return -1;
169 +    }
170 +
171 +  non_blocking = operation & LOCK_NB;
172 +  operation &= ~LOCK_NB;
173 +
174 +  switch (operation)
175 +    {
176 +    case LOCK_SH:
177 +      res = do_lock (h, non_blocking, 0);
178 +      break;
179 +    case LOCK_EX:
180 +      res = do_lock (h, non_blocking, 1);
181 +      break;
182 +    case LOCK_UN:
183 +      res = do_unlock (h);
184 +      break;
185 +    default:
186 +      errno = EINVAL;
187 +      return -1;
188 +    }
189 +
190 +  /* Map Windows errors into Unix errnos.  As usual MSDN fails to
191 +   * document the permissible error codes.
192 +   */
193 +  if (!res)
194 +    {
195 +      DWORD err = GetLastError ();
196 +      switch (err)
197 +       {
198 +         /* This means someone else is holding a lock. */
199 +       case ERROR_LOCK_VIOLATION:
200 +         errno = EAGAIN;
201 +         break;
202 +
203 +         /* Out of memory. */
204 +       case ERROR_NOT_ENOUGH_MEMORY:
205 +         errno = ENOMEM;
206 +         break;
207 +
208 +       case ERROR_BAD_COMMAND:
209 +         errno = EINVAL;
210 +         break;
211 +
212 +         /* Unlikely to be other errors, but at least don't lose the
213 +          * error code.
214 +          */
215 +       default:
216 +         errno = err;
217 +       }
218 +
219 +      return -1;
220 +    }
221 +
222 +  return 0;
223 +}
224 +
225 +#else /* !Windows */
226 +
227 +/* We know how to implement flock in terms of fcntl. */
228 +
229 +#ifdef HAVE_FCNTL_H
230 +#include <fcntl.h>
231 +#endif
232 +
233 +#ifdef HAVE_UNISTD_H
234 +#include <unistd.h>
235 +#endif
236 +
237 +int
238 +flock (int fd, int operation)
239 +{
240 +  int cmd, r;
241 +  struct flock fl;
242 +
243 +  if (operation & LOCK_NB)
244 +    cmd = F_SETLK;
245 +  else
246 +    cmd = F_SETLKW;
247 +  operation &= ~LOCK_NB;
248 +
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". */
252 +
253 +  switch (operation)
254 +    {
255 +    case LOCK_SH:
256 +      fl.l_type = F_RDLCK;
257 +      break;
258 +    case LOCK_EX:
259 +      fl.l_type = F_WRLCK;
260 +      break;
261 +    case LOCK_UN:
262 +      fl.l_type = F_UNLCK;
263 +      break;
264 +    default:
265 +      errno = EINVAL;
266 +      return -1;
267 +    }
268 +
269 +  r = fcntl (fd, cmd, &fl);
270 +  if (r == -1 && errno == EACCES)
271 +    errno = EAGAIN;
272 +
273 +  return r;
274 +}
275 +
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
280 @@ -0,0 +1,83 @@
281 +/* Emulate fsync on platforms that lack it, primarily Windows and
282 +   cross-compilers like MinGW.
283 +
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
287 +
288 +   Written by Richard W.M. Jones <rjones.at.redhat.com>
289 +
290 +   Copyright (C) 2008 Free Software Foundation, Inc.
291 +
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.
296 +
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.
301 +
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/>.  */
304 +
305 +#include <autoconf.h>
306 +#include "systems.h"
307 +#include <unistd.h>
308 +
309 +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
310 +
311 +/* _get_osfhandle */
312 +#include <io.h>
313 +
314 +/* FlushFileBuffers */
315 +#define WIN32_LEAN_AND_MEAN
316 +#include <windows.h>
317 +
318 +#include <errno.h>
319 +
320 +int
321 +fsync (int fd)
322 +{
323 +  HANDLE h = (HANDLE) _get_osfhandle (fd);
324 +  DWORD err;
325 +
326 +  if (h == INVALID_HANDLE_VALUE)
327 +    {
328 +      errno = EBADF;
329 +      return -1;
330 +    }
331 +
332 +  if (!FlushFileBuffers (h))
333 +    {
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.
337 +       */
338 +      err = GetLastError ();
339 +      switch (err)
340 +       {
341 +         /* eg. Trying to fsync a tty. */
342 +       case ERROR_INVALID_HANDLE:
343 +         errno = EINVAL;
344 +         break;
345 +
346 +       default:
347 +         errno = EIO;
348 +       }
349 +      return -1;
350 +    }
351 +
352 +  return 0;
353 +}
354 +
355 +#else /* !Windows */
356 +
357 +int fsync (int fd)
358 +{
359 +  sync ();
360 +  sync ();
361 +}
362 +
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
367 @@ -20,7 +20,7 @@
368  DEFS = @DEFS@
369  
370  # Where the system [n]dbm routines are...
371 -LIBS = @LIBS@ -lc
372 +LIBS = @LIBS@
373  
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
379  
380 -libgdbm.la: $(LOBJS) gdbm.h
381 +libgdbm.la: $(LOBJS) @LTLIBOBJS@ gdbm.h
382         rm -f libgdbm.la
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@
386  
387  gdbm.h:        gdbm.proto gdbmerrno.h gdbm.proto2
388         rm -f gdbm.h
389 @@ -146,19 +146,19 @@
390         chmod -w gdbm.h
391  
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@
395  
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
399  
400  tdbm: testdbm.o
401 -       $(CC) $(LDFLAGS) -o tdbm testdbm.o $(LIBS)
402 +       $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o tdbm testdbm.o libgdbm.la $(LIBS)
403  
404  testndbm.o: testndbm.c
405         $(CC) -c -I. -I$(srcdir) $(CFLAGS) $(DEFS) -DGNU $(srcdir)/testndbm.c
406  
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
410  
411  tndbm.o: testndbm.c
412         cp $(srcdir)/testndbm.c ./tndbm.c
413 @@ -166,10 +166,10 @@
414         rm -f ./tndbm.c
415  
416  tndbm: tndbm.o
417 -       $(CC) $(LDFLAGS) -o tndbm tndbm.o $(LIBS)
418 +       $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o tndbm tndbm.o libgdbm.la $(LIBS)
419  
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@
423  
424  lintgdbm: 
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
429 @@ -59,9 +59,9 @@
430  #define L_SET SEEK_SET
431  #endif
432  
433 -/* Do we have flock?  (BSD...) */
434 -
435 -#if HAVE_FLOCK
436 +#ifndef HAVE_FLOCK
437 +extern int flock (int fd, int operation);
438 +#endif
439  
440  #ifndef LOCK_SH
441  #define LOCK_SH        1
442 @@ -83,36 +83,6 @@
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)
445  
446 -#else
447 -
448 -/* Assume it is done like System V. */
449 -
450 -#define UNLOCK_FILE(dbf) \
451 -       {                                       \
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);   \
457 -       }
458 -#define READLOCK_FILE(dbf) \
459 -       {                                       \
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);        \
465 -       }
466 -#define WRITELOCK_FILE(dbf) \
467 -       {                                       \
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);        \
473 -       }
474 -#endif
475 -
476  /* Do we have bcopy?  */
477  #if !HAVE_BCOPY
478  #if HAVE_MEMORY_H
479 @@ -122,9 +92,8 @@
480  #define bcopy(d1, d2, n) memcpy(d2, d1, n)
481  #endif
482  
483 -/* Do we have fsync? */
484 -#if !HAVE_FSYNC
485 -#define fsync(f) {sync(); sync();}
486 +#ifndef HAVE_FSYNC
487 +extern int fsync (int fd);
488  #endif
489  
490  /* Default block size.  Some systems do not have blocksize in their