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

Last change on this file since 21356 was 18060, checked in by mdewsnip, 15 years ago

Transferred Windows-specific customisations from the old GDBM package in common-src\packages\windows\gdbm\gdbm.

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/* Do we have flock? (BSD...) */
63
64#if HAVE_FLOCK
65
66#ifndef LOCK_SH
67#define LOCK_SH 1
68#endif
69
70#ifndef LOCK_EX
71#define LOCK_EX 2
72#endif
73
74#ifndef LOCK_NB
75#define LOCK_NB 4
76#endif
77
78#ifndef LOCK_UN
79#define LOCK_UN 8
80#endif
81
82#define UNLOCK_FILE(dbf) flock (dbf->desc, LOCK_UN)
83#define READLOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_SH + LOCK_NB)
84#define WRITELOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_EX + LOCK_NB)
85
86#else
87
88#ifdef MSDOS
89#define MY_UNLOCK 0
90#define MY_READLOCK 1
91#define MY_WRITELOCK 2
92int my_locking(int fh, int lmode, long lockoffset, long nbytes);
93
94#define UNLOCK_FILE(dbf) my_locking(dbf->desc,MY_UNLOCK,0,10)
95#define READLOCK_FILE(dbf) lock_val=my_locking(dbf->desc,MY_READLOCK,0,10)
96#define WRITELOCK_FILE(dbf) lock_val=my_locking(dbf->desc,MY_WRITELOCK,0,10)
97
98#else
99
100/* Assume it is done like System V. */
101
102#define UNLOCK_FILE(dbf) \
103 { \
104 struct flock flock; \
105 flock.l_type = F_UNLCK; \
106 flock.l_whence = SEEK_SET; \
107 flock.l_start = flock.l_len = 0L; \
108 fcntl (dbf->desc, F_SETLK, &flock); \
109 }
110#define READLOCK_FILE(dbf) \
111 { \
112 struct flock flock; \
113 flock.l_type = F_RDLCK; \
114 flock.l_whence = SEEK_SET; \
115 flock.l_start = flock.l_len = 0L; \
116 lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
117 }
118#define WRITELOCK_FILE(dbf) \
119 { \
120 struct flock flock; \
121 flock.l_type = F_WRLCK; \
122 flock.l_whence = SEEK_SET; \
123 flock.l_start = flock.l_len = 0L; \
124 lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
125 }
126#endif
127#endif
128
129/* Do we have bcopy? */
130#if !HAVE_BCOPY
131#if HAVE_MEMORY_H
132#include <memory.h>
133#endif
134#define bcmp(d1, d2, n) memcmp(d1, d2, n)
135#define bcopy(d1, d2, n) memcpy(d2, d1, n)
136#endif
137
138/* Do we have fsync? */
139#if !HAVE_FSYNC
140#ifdef MSDOS
141#define fsync(f)
142#else
143#define fsync(f) {sync(); sync();}
144#endif
145#endif
146
147/* Default block size. Some systems do not have blocksize in their
148 stat record. This code uses the BSD blocksize from stat. */
149
150#if HAVE_STRUCT_STAT_ST_BLKSIZE
151#define STATBLKSIZE file_stat.st_blksize
152#else
153#define STATBLKSIZE 1024
154#endif
155
156/* Do we have ftruncate? */
157#if HAVE_FTRUNCATE
158#define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
159#else
160#define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC, mode));
161#endif
162
163#ifndef STDERR_FILENO
164#define STDERR_FILENO 2
165#endif
Note: See TracBrowser for help on using the repository browser.