source: gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/systems.h@ 18038

Last change on this file since 18038 was 18019, checked in by mdewsnip, 15 years ago

Added gdbm-1.8.3 (downloaded as gdbm-1.8.3.tar.gz and unpacked), in preparation for adding code for reading both little and big endian databases.

File size: 3.5 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/* Assume it is done like System V. */
89
90#define UNLOCK_FILE(dbf) \
91 { \
92 struct flock flock; \
93 flock.l_type = F_UNLCK; \
94 flock.l_whence = SEEK_SET; \
95 flock.l_start = flock.l_len = 0L; \
96 fcntl (dbf->desc, F_SETLK, &flock); \
97 }
98#define READLOCK_FILE(dbf) \
99 { \
100 struct flock flock; \
101 flock.l_type = F_RDLCK; \
102 flock.l_whence = SEEK_SET; \
103 flock.l_start = flock.l_len = 0L; \
104 lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
105 }
106#define WRITELOCK_FILE(dbf) \
107 { \
108 struct flock flock; \
109 flock.l_type = F_WRLCK; \
110 flock.l_whence = SEEK_SET; \
111 flock.l_start = flock.l_len = 0L; \
112 lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
113 }
114#endif
115
116/* Do we have bcopy? */
117#if !HAVE_BCOPY
118#if HAVE_MEMORY_H
119#include <memory.h>
120#endif
121#define bcmp(d1, d2, n) memcmp(d1, d2, n)
122#define bcopy(d1, d2, n) memcpy(d2, d1, n)
123#endif
124
125/* Do we have fsync? */
126#if !HAVE_FSYNC
127#define fsync(f) {sync(); sync();}
128#endif
129
130/* Default block size. Some systems do not have blocksize in their
131 stat record. This code uses the BSD blocksize from stat. */
132
133#if HAVE_STRUCT_STAT_ST_BLKSIZE
134#define STATBLKSIZE file_stat.st_blksize
135#else
136#define STATBLKSIZE 1024
137#endif
138
139/* Do we have ftruncate? */
140#if HAVE_FTRUNCATE
141#define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
142#else
143#define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC, mode));
144#endif
145
146#ifndef STDERR_FILENO
147#define STDERR_FILENO 2
148#endif
Note: See TracBrowser for help on using the repository browser.