home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / gdbm-1.7.1.tar.gz / gdbm-1.7.1.tar / gdbm-1.7.1 / systems.h < prev    next >
C/C++ Source or Header  |  1993-11-16  |  4KB  |  154 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. #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. #include <stdio.h>
  43. #if HAVE_SYS_FILE_H
  44. #include <sys/file.h>
  45. #endif
  46. #include <sys/stat.h>
  47. #if HAVE_STDLIB_H
  48. #include <stdlib.h>
  49. #endif
  50. #if HAVE_STRING_H
  51. #include <string.h>
  52. #else
  53. #include <strings.h>
  54. #endif
  55. #if HAVE_UNISTD_H
  56. #include <unistd.h>
  57. #endif
  58. #if HAVE_FCNTL_H
  59. #include <fcntl.h>
  60. #endif
  61.  
  62. #ifndef L_SET
  63. #define L_SET SEEK_SET
  64. #endif
  65.  
  66. /* Do we have flock?  (BSD...) */
  67.  
  68. #if HAVE_FLOCK
  69.  
  70. #ifndef LOCK_SH
  71. #define LOCK_SH    1
  72. #endif
  73.  
  74. #ifndef LOCK_EX
  75. #define LOCK_EX    2
  76. #endif
  77.  
  78. #ifndef LOCK_NB
  79. #define LOCK_NB 4
  80. #endif
  81.  
  82. #ifndef LOCK_UN
  83. #define LOCK_UN 8
  84. #endif
  85.  
  86. #define UNLOCK_FILE(dbf) flock (dbf->desc, LOCK_UN)
  87. #define READLOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_SH + LOCK_NB)
  88. #define WRITELOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_EX + LOCK_NB)
  89.  
  90. #else
  91.  
  92. /* Assume it is done like System V. */
  93.  
  94. #define UNLOCK_FILE(dbf) \
  95.     {                    \
  96.       struct flock flock;            \
  97.       flock.l_type = F_UNLCK;        \
  98.       flock.l_whence = 0;            \
  99.       flock.l_start = flock.l_len = 0L;    \
  100.       fcntl (dbf->desc, F_SETLK, &flock);    \
  101.     }
  102. #define READLOCK_FILE(dbf) \
  103.     {                    \
  104.       struct flock flock;            \
  105.       flock.l_type = F_RDLCK;        \
  106.       flock.l_whence = 0;            \
  107.       flock.l_start = flock.l_len = 0L;    \
  108.       lock_val = fcntl (dbf->desc, F_SETLK, &flock);    \
  109.     }
  110. #define WRITELOCK_FILE(dbf) \
  111.     {                    \
  112.       struct flock flock;            \
  113.       flock.l_type = F_WRLCK;        \
  114.       flock.l_whence = 0;            \
  115.       flock.l_start = flock.l_len = 0L;    \
  116.       lock_val = fcntl (dbf->desc, F_SETLK, &flock);    \
  117.     }
  118. #endif
  119.  
  120. /* Do we have bcopy?  */
  121. #if !HAVE_BCOPY
  122. #include <memory.h>
  123. #define bcmp(d1, d2, n)    memcmp(d1, d2, n)
  124. #define bcopy(d1, d2, n) memcpy(d2, d1, n)
  125. #endif
  126.  
  127. /* Do we have fsync? */
  128. #if !HAVE_FSYNC
  129. #define fsync(f) {sync(); sync();}
  130. #endif
  131.  
  132. /* Default block size.  Some systems do not have blocksize in their
  133.    stat record. This code uses the BSD blocksize from stat. */
  134.  
  135. #if HAVE_ST_BLKSIZE
  136. #define STATBLKSIZE file_stat.st_blksize
  137. #else
  138. #define STATBLKSIZE 1024
  139. #endif
  140.  
  141. /* Do we have ftruncate? */
  142. #if HAVE_FTRUNCATE
  143. #define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
  144. #else
  145. #define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC, mode));
  146. #endif
  147.  
  148. /* Do we have 32bit or 64bit longs? */
  149. #if LONG_64_BITS || !INT_16_BITS
  150. typedef int word_t;
  151. #else
  152. typedef long word_t;
  153. #endif
  154.