Imported Upstream version 1.10
[platform/upstream/gdbm.git] / src / systems.h
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.
4    Copyright (C) 1990, 1991, 1993, 2007, 2011 Free Software Foundation,
5    Inc.
6
7    GDBM is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3, or (at your option)
10    any later version.
11
12    GDBM is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GDBM. If not, see <http://www.gnu.org/licenses/>.    */
19
20 /* Include all system headers first. */
21 #if HAVE_SYS_TYPES_H
22 # include <sys/types.h>
23 #endif
24 #include <stdio.h>
25 #if HAVE_SYS_FILE_H
26 # include <sys/file.h>
27 #endif
28 #include <sys/stat.h>
29 #if HAVE_STDLIB_H
30 # include <stdlib.h>
31 #endif
32 #if HAVE_STRING_H
33 # include <string.h>
34 #else
35 # include <strings.h>
36 #endif
37 #if HAVE_UNISTD_H
38 # include <unistd.h>
39 #endif
40 #if HAVE_FCNTL_H
41 # include <fcntl.h>
42 #endif
43 #include <errno.h>
44
45 #ifndef SEEK_SET
46 # define SEEK_SET        0
47 #endif
48
49 #ifndef O_CLOEXEC
50 # define O_CLOEXEC 0
51 #endif
52
53 /* Default block size.  Some systems do not have blocksize in their
54    stat record. This code uses the BSD blocksize from stat. */
55
56 #if HAVE_STRUCT_STAT_ST_BLKSIZE
57 # define STATBLKSIZE file_stat.st_blksize
58 #else
59 # define STATBLKSIZE 1024
60 #endif
61
62 /* Do we have ftruncate? */
63 #if HAVE_FTRUNCATE
64 # define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
65 #else
66 # define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC, mode));
67 #endif
68
69 #ifndef STDERR_FILENO
70 # define STDERR_FILENO 2
71 #endif
72
73 /* I/O macros. */
74 #if HAVE_MMAP
75 # define __read(_dbf, _buf, _size)      _gdbm_mapped_read(_dbf, _buf, _size)
76 # define __write(_dbf, _buf, _size)     _gdbm_mapped_write(_dbf, _buf, _size)
77 # define __lseek(_dbf, _off, _whn)      _gdbm_mapped_lseek(_dbf, _off, _whn)
78 # define __fsync(_dbf)                  _gdbm_mapped_sync(_dbf)
79 #else
80 # define __read(_dbf, _buf, _size)      read(_dbf->desc, _buf, _size)
81 # define __write(_dbf, _buf, _size)     write(_dbf->desc, _buf, _size)
82 # define __lseek(_dbf, _off, _whn)      lseek(_dbf->desc, _off, _whn)
83 # if HAVE_FSYNC
84 #  define __fsync(_dbf)                 fsync(_dbf->desc)
85 # else
86 #  define __fsync(_dbf)                 { sync(); sync(); }
87 # endif
88 #endif
89