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

Last change on this file since 26772 was 26772, checked in by davidb, 11 years ago

Updated configure.in which separates test for bcopy and bcmp. Previously if the test for bcopy was OK, then assumed bcmp OK also. This wasn't the case on Android

File size: 4.0 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 bcopy(d1, d2, n) memcpy(d2, d1, n)
140#endif
141
142/* Do we have bcmp? */
143#if !HAVE_BCMP
144#if HAVE_MEMORY_H
145#include <memory.h>
146#endif
147#define bcmp(d1, d2, n) memcmp(d1, d2, 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_STRUCT_STAT_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, mode));
173#endif
174
175#ifndef STDERR_FILENO
176#define STDERR_FILENO 2
177#endif
Note: See TracBrowser for help on using the repository browser.