source: main/trunk/greenstone2/common-src/packages/gdbm/gdbm-1.8.3/systems.h@ 23770

Last change on this file since 23770 was 23770, checked in by davidb, 13 years ago

For Windows explicitly set HAVE_RENAME to 1. When compiling on Windows 7 64-bit we found that not only was HAVE_RENAME not defined, but 'link' was deprecated for Windows, and 'rename' should be used instead. The result of all this was the Greenstone 3 was not able to compile GDBM. GDBM provides a fallback routine for 'rename' when HAVE_RENAME is not defined. The trouble is uses the deprecated 'link' to provide this fallback. This change explicitly sets HAVE_RENAME to 1 for Windows only. Our reading of MSDN is that 'rename' has been around in the Visual Studio compiler since 2003 if not from before.

File size: 3.9 KB
Line 
1/* systems.h - Most of the system dependant code and defines are here. */
2
3/* This file is part of GDBM, the GNU data base manager, by Philip A. Nelson.
4 Copyright (C) 1990, 1991, 1993 Free Software Foundation, Inc.
5
6 GDBM is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GDBM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GDBM; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 You may contact the author by:
21 e-mail: [email protected]
22 us-mail: Philip A. Nelson
23 Computer Science Department
24 Western Washington University
25 Bellingham, WA 98226
26
27*************************************************************************/
28
29
30/* Include all system headers first. */
31#if HAVE_SYS_TYPES_H
32#include <sys/types.h>
33#endif
34#include <stdio.h>
35#if HAVE_SYS_FILE_H
36#include <sys/file.h>
37#endif
38#include <sys/stat.h>
39#if HAVE_STDLIB_H
40#include <stdlib.h>
41#endif
42#if HAVE_STRING_H
43#include <string.h>
44#else
45#include <strings.h>
46#endif
47#if HAVE_UNISTD_H
48#include <unistd.h>
49#endif
50#if HAVE_FCNTL_H
51#include <fcntl.h>
52#endif
53
54#ifndef SEEK_SET
55#define SEEK_SET 0
56#endif
57
58#ifndef L_SET
59#define L_SET SEEK_SET
60#endif
61
62
63#ifdef MSDOS
64#define HAVE_RENAME 1
65#endif
66
67/* Do we have flock? (BSD...) */
68
69#if HAVE_FLOCK
70
71#ifndef LOCK_SH
72#define LOCK_SH 1
73#endif
74
75#ifndef LOCK_EX
76#define LOCK_EX 2
77#endif
78
79#ifndef LOCK_NB
80#define LOCK_NB 4
81#endif
82
83#ifndef LOCK_UN
84#define LOCK_UN 8
85#endif
86
87#define UNLOCK_FILE(dbf) flock (dbf->desc, LOCK_UN)
88#define READLOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_SH + LOCK_NB)
89#define WRITELOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_EX + LOCK_NB)
90
91#else
92
93#ifdef MSDOS
94#define MY_UNLOCK 0
95#define MY_READLOCK 1
96#define MY_WRITELOCK 2
97int my_locking(int fh, int lmode, long lockoffset, long nbytes);
98
99#define UNLOCK_FILE(dbf) my_locking(dbf->desc,MY_UNLOCK,0,10)
100#define READLOCK_FILE(dbf) lock_val=my_locking(dbf->desc,MY_READLOCK,0,10)
101#define WRITELOCK_FILE(dbf) lock_val=my_locking(dbf->desc,MY_WRITELOCK,0,10)
102
103#else
104
105/* Assume it is done like System V. */
106
107#define UNLOCK_FILE(dbf) \
108 { \
109 struct flock flock; \
110 flock.l_type = F_UNLCK; \
111 flock.l_whence = SEEK_SET; \
112 flock.l_start = flock.l_len = 0L; \
113 fcntl (dbf->desc, F_SETLK, &flock); \
114 }
115#define READLOCK_FILE(dbf) \
116 { \
117 struct flock flock; \
118 flock.l_type = F_RDLCK; \
119 flock.l_whence = SEEK_SET; \
120 flock.l_start = flock.l_len = 0L; \
121 lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
122 }
123#define WRITELOCK_FILE(dbf) \
124 { \
125 struct flock flock; \
126 flock.l_type = F_WRLCK; \
127 flock.l_whence = SEEK_SET; \
128 flock.l_start = flock.l_len = 0L; \
129 lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
130 }
131#endif
132#endif
133
134/* Do we have bcopy? */
135#if !HAVE_BCOPY
136#if HAVE_MEMORY_H
137#include <memory.h>
138#endif
139#define bcmp(d1, d2, n) memcmp(d1, d2, n)
140#define bcopy(d1, d2, n) memcpy(d2, d1, n)
141#endif
142
143/* Do we have fsync? */
144#if !HAVE_FSYNC
145#ifdef MSDOS
146#define fsync(f)
147#else
148#define fsync(f) {sync(); sync();}
149#endif
150#endif
151
152/* Default block size. Some systems do not have blocksize in their
153 stat record. This code uses the BSD blocksize from stat. */
154
155#if HAVE_STRUCT_STAT_ST_BLKSIZE
156#define STATBLKSIZE file_stat.st_blksize
157#else
158#define STATBLKSIZE 1024
159#endif
160
161/* Do we have ftruncate? */
162#if HAVE_FTRUNCATE
163#define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
164#else
165#define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC, mode));
166#endif
167
168#ifndef STDERR_FILENO
169#define STDERR_FILENO 2
170#endif
Note: See TracBrowser for help on using the repository browser.