source: trunk/gsdl/packages/wingdbm/systems.h@ 18

Last change on this file since 18 was 18, checked in by sjboddie, 26 years ago

Added windows gdbm and mg versions

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
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#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 UNLOCK_FILE(dbf) /* later !!! */
103#define READLOCK_FILE(dbf) lock_val = 0;
104#define WRITELOCK_FILE(dbf) lock_val = 0;
105#else
106/* Assume it is done like System V. */
107
108#define UNLOCK_FILE(dbf) \
109 { \
110 struct flock flock; \
111 flock.l_type = F_UNLCK; \
112 flock.l_whence = SEEK_SET; \
113 flock.l_start = flock.l_len = 0L; \
114 fcntl (dbf->desc, F_SETLK, &flock); \
115 }
116#define READLOCK_FILE(dbf) \
117 { \
118 struct flock flock; \
119 flock.l_type = F_RDLCK; \
120 flock.l_whence = SEEK_SET; \
121 flock.l_start = flock.l_len = 0L; \
122 lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
123 }
124#define WRITELOCK_FILE(dbf) \
125 { \
126 struct flock flock; \
127 flock.l_type = F_WRLCK; \
128 flock.l_whence = SEEK_SET; \
129 flock.l_start = flock.l_len = 0L; \
130 lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
131 }
132#endif
133#endif
134
135/* Do we have bcopy? */
136#if !HAVE_BCOPY
137#if HAVE_MEMORY_H
138#include <memory.h>
139#endif
140#define bcmp(d1, d2, n) memcmp(d1, d2, n)
141#define bcopy(d1, d2, n) memcpy(d2, d1, n)
142#endif
143
144/* Do we have fsync? */
145#if !HAVE_FSYNC
146#ifdef MSDOS
147#define fsync(f)
148#else
149#define fsync(f) {sync(); sync();}
150#endif
151#endif
152
153/* Default block size. Some systems do not have blocksize in their
154 stat record. This code uses the BSD blocksize from stat. */
155
156#if HAVE_ST_BLKSIZE
157#define STATBLKSIZE file_stat.st_blksize
158#else
159#define STATBLKSIZE 1024
160#endif
161
162/* Do we have ftruncate? */
163#if HAVE_FTRUNCATE
164#define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
165#else
166#define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC|O_BINARY, mode));
167#endif
168
169/* Do we have 32bit or 64bit longs? */
170#if LONG_64_BITS || !INT_16_BITS
171typedef int word_t;
172#else
173typedef long word_t;
174#endif
Note: See TracBrowser for help on using the repository browser.