home *** CD-ROM | disk | FTP | other *** search
- /* systems.h - Most of the system dependant code and defines are here. */
-
- /* This file is part of GDBM, the GNU data base manager, by Philip A. Nelson.
- Copyright (C) 1990, 1991, 1993 Free Software Foundation, Inc.
-
- GDBM is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- GDBM is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GDBM; see the file COPYING. If not, write to
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
- You may contact the author by:
- e-mail: phil@wwu.edu
- us-mail: Philip A. Nelson
- Computer Science Department
- Western Washington University
- Bellingham, WA 98226
-
- *************************************************************************/
-
-
- /* Do we need to define L_SET? .*/
- #if HAVE_UNISTD_H
- #include <unistd.h>
- #endif
-
- #ifndef L_SET
- #define L_SET SEEK_SET
- #endif
-
- /* Do we have flock? (BSD...) */
-
- #if HAVE_FLOCK
-
- #define UNLOCK_FILE(dbf) flock (dbf->desc, LOCK_UN)
- #define READLOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_SH + LOCK_NB)
- #define WRITELOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_EX + LOCK_NB)
-
- #else
-
- /* Assume it is done like System V. */
-
- #include <fcntl.h>
- #define UNLOCK_FILE(dbf) \
- { \
- struct flock flock; \
- flock.l_type = F_UNLCK; \
- flock.l_whence = 0; \
- flock.l_start = flock.l_len = 0L; \
- fcntl (dbf->desc, F_SETLK, &flock); \
- }
- #define READLOCK_FILE(dbf) \
- { \
- struct flock flock; \
- flock.l_type = F_RDLCK; \
- flock.l_whence = 0; \
- flock.l_start = flock.l_len = 0L; \
- lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
- }
- #define WRITELOCK_FILE(dbf) \
- { \
- struct flock flock; \
- flock.l_type = F_WRLCK; \
- flock.l_whence = 0; \
- flock.l_start = flock.l_len = 0L; \
- lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
- }
- #endif
-
- /* Do we have bcopy? */
- #if !HAVE_BCOPY
- #include <memory.h>
- #define bcmp(d1, d2, n) memcmp(d1, d2, n)
- #define bcopy(d1, d2, n) memcpy(d2, d1, n)
- #endif
-
- /* Do we have fsync? */
- #if !HAVE_FSYNC
- #define fsync(f) sync(); sync()
- #endif
-
- /* Default block size. Some systems do not have blocksize in their
- stat record. This code uses the BSD blocksize from stat. */
-
- #if HAVE_ST_BLKSIZE
- #define STATBLKSIZE file_stat.st_blksize
- #else
- #define STATBLKSIZE 1024
- #endif
-
- /* Which string definitions? */
- #if HAVE_STRING_H
- #include <string.h>
- #else
- #include <strings.h>
- #endif
-
- /* Do we have ftruncate? */
- #if HAVE_FTRUNCATE
- #define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
- #else
- #define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC, mode));
- #endif
-
- /* Alloca is builtin in gcc. Use the builtin alloca if compiled with gcc. */
- #ifdef __GNUC__
- #define BUILTIN_ALLOCA
- #endif
-
- /* Also, if this is a sun spark, use the builtin alloca. */
- #ifdef sun
- #ifdef sparc
- #define BUILTIN_ALLOCA
- #endif
- #endif
-
- /* Define the proper alloca procedure. */
- #ifdef BUILTIN_ALLOCA
- #define alloca(x) __builtin_alloca(x)
- #else
- extern char *alloca();
- #endif
-
- /* Malloc definition. */
- extern char *malloc();
-