[18019] | 1 | /* global.c - The external variables needed for "original" interface and
|
---|
| 2 | error messages. */
|
---|
| 3 |
|
---|
| 4 | /* This file is part of GDBM, the GNU data base manager, by Philip A. Nelson.
|
---|
| 5 | Copyright (C) 1990, 1991, 1993 Free Software Foundation, Inc.
|
---|
| 6 |
|
---|
| 7 | GDBM is free software; you can redistribute it and/or modify
|
---|
| 8 | it under the terms of the GNU General Public License as published by
|
---|
| 9 | the Free Software Foundation; either version 2, or (at your option)
|
---|
| 10 | any later version.
|
---|
| 11 |
|
---|
| 12 | GDBM is distributed in the hope that it will be useful,
|
---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | GNU General Public License for more details.
|
---|
| 16 |
|
---|
| 17 | You should have received a copy of the GNU General Public License
|
---|
| 18 | along with GDBM; see the file COPYING. If not, write to
|
---|
| 19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 20 |
|
---|
| 21 | You may contact the author by:
|
---|
| 22 | e-mail: [email protected]
|
---|
| 23 | us-mail: Philip A. Nelson
|
---|
| 24 | Computer Science Department
|
---|
| 25 | Western Washington University
|
---|
| 26 | Bellingham, WA 98226
|
---|
| 27 |
|
---|
| 28 | *************************************************************************/
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | /* include system configuration before all else. */
|
---|
| 32 | #include "autoconf.h"
|
---|
| 33 |
|
---|
| 34 | #include "gdbmdefs.h"
|
---|
| 35 | #include "gdbmerrno.h"
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | /* The global variables used for the "original" interface. */
|
---|
| 39 | gdbm_file_info *_gdbm_file = NULL;
|
---|
| 40 |
|
---|
| 41 | /* Memory for return data for the "original" interface. */
|
---|
| 42 | datum _gdbm_memory = {NULL, 0}; /* Used by firstkey and nextkey. */
|
---|
| 43 | char *_gdbm_fetch_val = NULL; /* Used by fetch. */
|
---|
| 44 |
|
---|
| 45 | /* The dbm error number is placed in the variable GDBM_ERRNO. */
|
---|
| 46 | gdbm_error gdbm_errno = GDBM_NO_ERROR;
|
---|
[18062] | 47 |
|
---|
| 48 | #ifdef MSDOS
|
---|
| 49 |
|
---|
| 50 | #include <io.h>
|
---|
| 51 | #include <windows.h>
|
---|
| 52 |
|
---|
| 53 | /* a simple locking function for windows that uses file descriptors */
|
---|
| 54 | int my_locking(int fh, int lmode, long lockoffset, long nbytes) {
|
---|
| 55 | int result = -1;
|
---|
| 56 | int trys = 10;
|
---|
| 57 |
|
---|
| 58 | lseek (fh, lockoffset, L_SET);
|
---|
| 59 |
|
---|
| 60 | while (trys > 0 && result != 0) {
|
---|
| 61 | if (lmode == MY_UNLOCK) {
|
---|
| 62 | if (UnlockFile((HANDLE)_get_osfhandle(fh),lockoffset,0,nbytes,0))
|
---|
| 63 | result = 0;
|
---|
| 64 |
|
---|
| 65 | } else if (lmode == MY_READLOCK) {
|
---|
| 66 | /* if (LockFileEx((HANDLE)_get_osfhandle(fh),0,0,nbytes,0,0))*/
|
---|
| 67 | if (LockFile((HANDLE)_get_osfhandle(fh),lockoffset,0,nbytes,0))
|
---|
| 68 | result = 0;
|
---|
| 69 |
|
---|
| 70 | } else if (lmode == MY_WRITELOCK) {
|
---|
| 71 | if (LockFile((HANDLE)_get_osfhandle(fh),lockoffset,0,nbytes,0))
|
---|
| 72 | result = 0;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | Sleep(100L);
|
---|
| 76 | trys--;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | return result;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | #endif
|
---|