home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 1 / FFMCD01.bin / useful / dist / gnu / gdbm / gdbm-1.6-amiga / systems.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-19  |  3.4 KB  |  134 lines

  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:  phil@wwu.edu
  22.       us-mail:  Philip A. Nelson
  23.                 Computer Science Department
  24.                 Western Washington University
  25.                 Bellingham, WA 98226
  26.        
  27. *************************************************************************/
  28.  
  29.  
  30. /* Do we need to define L_SET? .*/
  31. #if HAVE_UNISTD_H
  32. #include <unistd.h>
  33. #endif
  34.  
  35. #ifndef L_SET
  36. #define L_SET SEEK_SET
  37. #endif
  38.  
  39. /* Do we have flock?  (BSD...) */
  40.  
  41. #if HAVE_FLOCK
  42.  
  43. #define UNLOCK_FILE(dbf) flock (dbf->desc, LOCK_UN)
  44. #define READLOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_SH + LOCK_NB)
  45. #define WRITELOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_EX + LOCK_NB)
  46.  
  47. #else
  48.  
  49. /* Assume it is done like System V. */
  50.  
  51. #include <fcntl.h>
  52. #define UNLOCK_FILE(dbf) \
  53.     {                    \
  54.       struct flock flock;            \
  55.       flock.l_type = F_UNLCK;        \
  56.       flock.l_whence = 0;            \
  57.       flock.l_start = flock.l_len = 0L;    \
  58.       fcntl (dbf->desc, F_SETLK, &flock);    \
  59.     }
  60. #define READLOCK_FILE(dbf) \
  61.     {                    \
  62.       struct flock flock;            \
  63.       flock.l_type = F_RDLCK;        \
  64.       flock.l_whence = 0;            \
  65.       flock.l_start = flock.l_len = 0L;    \
  66.       lock_val = fcntl (dbf->desc, F_SETLK, &flock);    \
  67.     }
  68. #define WRITELOCK_FILE(dbf) \
  69.     {                    \
  70.       struct flock flock;            \
  71.       flock.l_type = F_WRLCK;        \
  72.       flock.l_whence = 0;            \
  73.       flock.l_start = flock.l_len = 0L;    \
  74.       lock_val = fcntl (dbf->desc, F_SETLK, &flock);    \
  75.     }
  76. #endif
  77.  
  78. /* Do we have bcopy?  */
  79. #if !HAVE_BCOPY
  80. #include <memory.h>
  81. #define bcmp(d1, d2, n)    memcmp(d1, d2, n)
  82. #define bcopy(d1, d2, n) memcpy(d2, d1, n)
  83. #endif
  84.  
  85. /* Do we have fsync? */
  86. #if !HAVE_FSYNC
  87. #define fsync(f) sync(); sync()
  88. #endif
  89.  
  90. /* Default block size.  Some systems do not have blocksize in their
  91.    stat record. This code uses the BSD blocksize from stat. */
  92.  
  93. #if HAVE_ST_BLKSIZE
  94. #define STATBLKSIZE file_stat.st_blksize
  95. #else
  96. #define STATBLKSIZE 1024
  97. #endif
  98.  
  99. /* Which string definitions? */
  100. #if HAVE_STRING_H
  101. #include <string.h>
  102. #else
  103. #include <strings.h>
  104. #endif
  105.  
  106. /* Do we have ftruncate? */
  107. #if HAVE_FTRUNCATE
  108. #define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
  109. #else
  110. #define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC, mode));
  111. #endif
  112.  
  113. /* Alloca is builtin in gcc.  Use the builtin alloca if compiled with gcc. */
  114. #ifdef __GNUC__
  115. #define BUILTIN_ALLOCA
  116. #endif
  117.  
  118. /* Also, if this is a sun spark, use the builtin alloca. */
  119. #ifdef sun
  120. #ifdef sparc
  121. #define BUILTIN_ALLOCA
  122. #endif
  123. #endif
  124.  
  125. /* Define the proper alloca procedure. */
  126. #ifdef BUILTIN_ALLOCA
  127. #define alloca(x) __builtin_alloca(x)
  128. #else
  129. extern char *alloca();
  130. #endif
  131.  
  132. /* Malloc definition. */
  133. extern char *malloc();
  134.