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 | #ifdef __GNUC__
|
---|
31 | #define alloca __builtin_alloca
|
---|
32 | #else /* not __GNUC__ */
|
---|
33 | #ifdef HAVE_ALLOCA_H
|
---|
34 | #include <alloca.h>
|
---|
35 | #endif /* not HAVE_ALLOCA_H */
|
---|
36 | #endif /* not __GNUC__ */
|
---|
37 |
|
---|
38 | /* Include all system headers first. */
|
---|
39 | #if HAVE_SYS_TYPES_H
|
---|
40 | #include <sys/types.h>
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <stdio.h>
|
---|
44 | #if HAVE_SYS_FILE_H
|
---|
45 | #include <sys/file.h>
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | #include <sys/stat.h>
|
---|
49 | #if HAVE_STDLIB_H
|
---|
50 | #include <stdlib.h>
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | #if HAVE_STRING_H
|
---|
54 | #include <string.h>
|
---|
55 | #else
|
---|
56 | #include <strings.h>
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | #if HAVE_UNISTD_H
|
---|
60 | #include <unistd.h>
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | #if HAVE_FCNTL_H
|
---|
64 | #include <fcntl.h>
|
---|
65 | #endif
|
---|
66 |
|
---|
67 | #ifndef SEEK_SET
|
---|
68 | #define SEEK_SET 0
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | #ifndef L_SET
|
---|
72 | #define L_SET SEEK_SET
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | /* Do we have flock? (BSD...) */
|
---|
76 |
|
---|
77 | #if HAVE_FLOCK
|
---|
78 |
|
---|
79 | #ifndef LOCK_SH
|
---|
80 | #define LOCK_SH 1
|
---|
81 | #endif
|
---|
82 |
|
---|
83 | #ifndef LOCK_EX
|
---|
84 | #define LOCK_EX 2
|
---|
85 | #endif
|
---|
86 |
|
---|
87 | #ifndef LOCK_NB
|
---|
88 | #define LOCK_NB 4
|
---|
89 | #endif
|
---|
90 |
|
---|
91 | #ifndef LOCK_UN
|
---|
92 | #define LOCK_UN 8
|
---|
93 | #endif
|
---|
94 |
|
---|
95 | #define UNLOCK_FILE(dbf) flock (dbf->desc, LOCK_UN)
|
---|
96 | #define READLOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_SH + LOCK_NB)
|
---|
97 | #define WRITELOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_EX + LOCK_NB)
|
---|
98 |
|
---|
99 | #else
|
---|
100 |
|
---|
101 | #ifdef MSDOS
|
---|
102 | #define MY_UNLOCK 0
|
---|
103 | #define MY_READLOCK 1
|
---|
104 | #define MY_WRITELOCK 2
|
---|
105 | int my_locking(int fh, int lmode, long lockoffset, long nbytes);
|
---|
106 |
|
---|
107 | #define UNLOCK_FILE(dbf) my_locking(dbf->desc,MY_UNLOCK,0,10)
|
---|
108 | #define READLOCK_FILE(dbf) lock_val=my_locking(dbf->desc,MY_READLOCK,0,10)
|
---|
109 | #define WRITELOCK_FILE(dbf) lock_val=my_locking(dbf->desc,MY_WRITELOCK,0,10)
|
---|
110 |
|
---|
111 | #else
|
---|
112 | /* Assume it is done like System V. */
|
---|
113 |
|
---|
114 | #define UNLOCK_FILE(dbf) \
|
---|
115 | { \
|
---|
116 | struct flock flock; \
|
---|
117 | flock.l_type = F_UNLCK; \
|
---|
118 | flock.l_whence = SEEK_SET; \
|
---|
119 | flock.l_start = flock.l_len = 0L; \
|
---|
120 | fcntl (dbf->desc, F_SETLK, &flock); \
|
---|
121 | }
|
---|
122 | #define READLOCK_FILE(dbf) \
|
---|
123 | { \
|
---|
124 | struct flock flock; \
|
---|
125 | flock.l_type = F_RDLCK; \
|
---|
126 | flock.l_whence = SEEK_SET; \
|
---|
127 | flock.l_start = flock.l_len = 0L; \
|
---|
128 | lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
|
---|
129 | }
|
---|
130 | #define WRITELOCK_FILE(dbf) \
|
---|
131 | { \
|
---|
132 | struct flock flock; \
|
---|
133 | flock.l_type = F_WRLCK; \
|
---|
134 | flock.l_whence = SEEK_SET; \
|
---|
135 | flock.l_start = flock.l_len = 0L; \
|
---|
136 | lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
|
---|
137 | }
|
---|
138 | #endif
|
---|
139 | #endif
|
---|
140 |
|
---|
141 | /* Do we have bcopy? */
|
---|
142 | #if !HAVE_BCOPY
|
---|
143 | #if HAVE_MEMORY_H
|
---|
144 | #include <memory.h>
|
---|
145 | #endif
|
---|
146 | #define bcmp(d1, d2, n) memcmp(d1, d2, n)
|
---|
147 | #define bcopy(d1, d2, n) memcpy(d2, d1, n)
|
---|
148 | #endif
|
---|
149 |
|
---|
150 | /* Do we have fsync? */
|
---|
151 | #if !HAVE_FSYNC
|
---|
152 | #ifdef MSDOS
|
---|
153 | #define fsync(f)
|
---|
154 | #else
|
---|
155 | #define fsync(f) {sync(); sync();}
|
---|
156 | #endif
|
---|
157 | #endif
|
---|
158 |
|
---|
159 | /* Default block size. Some systems do not have blocksize in their
|
---|
160 | stat record. This code uses the BSD blocksize from stat. */
|
---|
161 |
|
---|
162 | #if HAVE_ST_BLKSIZE
|
---|
163 | #define STATBLKSIZE file_stat.st_blksize
|
---|
164 | #else
|
---|
165 | #define STATBLKSIZE 1024
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | /* Do we have ftruncate? */
|
---|
169 | #if HAVE_FTRUNCATE
|
---|
170 | #define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
|
---|
171 | #else
|
---|
172 | #define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC|O_BINARY, mode));
|
---|
173 | #endif
|
---|
174 |
|
---|
175 | /* Do we have 32bit or 64bit longs? */
|
---|
176 | #if LONG_64_BITS || !INT_16_BITS
|
---|
177 | typedef int word_t;
|
---|
178 | #else
|
---|
179 | typedef long word_t;
|
---|
180 | #endif
|
---|
181 |
|
---|
182 |
|
---|
183 | #include <io.h>
|
---|
184 |
|
---|
185 | #ifdef __GNUC__
|
---|
186 | #define alloca __builtin_alloca
|
---|
187 | #else /* not __GNUC__ */
|
---|
188 | #if defined (HAVE_ALLOCA_H) || (defined(sparc) && (defined(sun) || (!defined(USG) && !defined(SVR4) && !defined(__svr4__))))
|
---|
189 | #include <alloca.h>
|
---|
190 | #else
|
---|
191 | #ifndef _AIX
|
---|
192 | char *alloca ();
|
---|
193 | #endif
|
---|
194 | #endif /* alloca.h */
|
---|
195 | #endif /* not __GNUC__ */
|
---|