home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / systems.h < prev    next >
C/C++ Source or Header  |  1992-01-19  |  5KB  |  169 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  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 1, 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.         phone:  (206) 676-3035
  27.  
  28. *************************************************************************/
  29.  
  30. #ifdef OS2
  31. #ifndef SYSV
  32. #define SYSV
  33. #endif
  34. #endif
  35.  
  36. /*         System V changes and defines.          */
  37. /**************************************************/
  38.  
  39. #ifdef SYSV
  40.  
  41. /* File seeking needs L_SET defined .*/
  42. #ifdef OS2
  43. #include <malloc.h>
  44. #include <io.h>
  45. #else /* not OS2 */
  46. #include <unistd.h>
  47. #endif /* not OS2 */
  48. #define L_SET SEEK_SET
  49.  
  50. /* Some files need fcntl.h for locking. */
  51. #include <fcntl.h>
  52. #ifdef OS2
  53. #define UNLOCK_FILE(dbf)    /* later !!!  */
  54. #define READLOCK_FILE(dbf)    lock_val = 0;
  55. #define WRITELOCK_FILE(dbf)    lock_val = 0;
  56. #else /* not OS2 */
  57. #define UNLOCK_FILE(dbf) \
  58.     {                    \
  59.       struct flock flock;            \
  60.       flock.l_type = F_UNLCK;        \
  61.       flock.l_whence = 0;            \
  62.       flock.l_start = flock.l_len = 0L;    \
  63.       fcntl (dbf->desc, F_SETLK, &flock);    \
  64.     }
  65. #define READLOCK_FILE(dbf) \
  66.     {                    \
  67.       struct flock flock;            \
  68.       flock.l_type = F_RDLCK;        \
  69.       flock.l_whence = 0;            \
  70.       flock.l_start = flock.l_len = 0L;    \
  71.       lock_val = fcntl (dbf->desc, F_SETLK, &flock);    \
  72.     }
  73. #define WRITELOCK_FILE(dbf) \
  74.     {                    \
  75.       struct flock flock;            \
  76.       flock.l_type = F_WRLCK;        \
  77.       flock.l_whence = 0;            \
  78.       flock.l_start = flock.l_len = 0L;    \
  79.       lock_val = fcntl (dbf->desc, F_SETLK, &flock);    \
  80.     }
  81. #endif /* not OS2 */
  82.  
  83. /* Send bcmp to the right place. */
  84. #include <memory.h>
  85. #define bcmp(d1, d2, n)    memcmp(d1, d2, n)
  86. #define bcopy(d1, d2, n) memcpy(d2, d1, n)
  87.  
  88. /* Sys V does not have fsync. */
  89. #ifdef OS2
  90. #define fsync(f)
  91. #else /* not OS2 */
  92. #define fsync(f) sync(); sync()
  93. #endif /* not OS2 */
  94.  
  95. /* Stat does not have a st_blksize field. */
  96. #define STATBLKSIZE 512
  97.  
  98. /* Does not have rename(). */
  99. #ifndef OS2
  100. #define NEED_RENAME
  101. #endif /* not OS2 */
  102.  
  103. /* Get string definitions. */
  104. #include <string.h>
  105. #define _HAVE_STRING
  106. #endif
  107.  
  108. /* Sys V does not have a truncate call, how primitive. */
  109. #define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC, mode));
  110.  
  111.  
  112. /*      End of System V changes and defines.      */
  113. /**************************************************/
  114.  
  115.  
  116. #ifndef OS2
  117. /* Alloca is builtin in gcc.  Use the builtin alloca if compiled with gcc. */
  118. #ifdef __GNUC__
  119. #define BUILTIN_ALLOCA
  120. #endif
  121.  
  122. /* Also, if this is a sun spark, use the builtin alloca. */
  123. #ifdef sun
  124. #ifdef sparc
  125. #define BUILTIN_ALLOCA
  126. #endif
  127. #endif
  128.  
  129. /* Define the proper alloca procedure. */
  130. #ifdef BUILTIN_ALLOCA
  131. #define alloca(x) __builtin_alloca(x)
  132. #else
  133. extern char *alloca();
  134. #endif
  135.  
  136. /* Malloc definition. */
  137. extern char *malloc();
  138. #endif /* not OS2 */
  139.  
  140. /* String definitions. */
  141. #ifndef _HAVE_STRING
  142. #include <strings.h>
  143. #endif
  144.  
  145. /* The BSD defines are the default defines.  If something is not
  146.    defined above in the above conditional code, it will be set
  147.    in the following code to the BSD code.  */
  148.  
  149. /* Default block size.  Some systems do not have blocksize in their
  150.    stat record. This code uses the BSD blocksize from stat. */
  151.  
  152. #ifndef STATBLKSIZE
  153. #define STATBLKSIZE file_stat.st_blksize
  154. #endif
  155.  
  156.  
  157. /* Locking is done differently on different systems.  Here is the BSD
  158.    locking routines.  */
  159.  
  160. #ifndef UNLOCK_FILE
  161. #define UNLOCK_FILE(dbf) flock (dbf->desc, LOCK_UN)
  162. #define READLOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_SH + LOCK_NB)
  163. #define WRITELOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_EX + LOCK_NB)
  164. #endif
  165.  
  166. #ifndef TRUNCATE
  167. #define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
  168. #endif
  169.