root/libdb/compat.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*-
   2  * Copyright (c) 1991, 1993
   3  *      The Regents of the University of California.  All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  * 1. Redistributions of source code must retain the above copyright
   9  *    notice, this list of conditions and the following disclaimer.
  10  * 2. Redistributions in binary form must reproduce the above copyright
  11  *    notice, this list of conditions and the following disclaimer in the
  12  *    documentation and/or other materials provided with the distribution.
  13  * 3. Neither the name of the University nor the names of its contributors
  14  *    may be used to endorse or promote products derived from this software
  15  *    without specific prior written permission.
  16  *
  17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27  * SUCH DAMAGE.
  28  */
  29 
  30 #ifndef _COMPAT_H_
  31 #define _COMPAT_H_
  32 
  33 /** @file */
  34 
  35 #include <sys/types.h>
  36 
  37 #if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__DJGPP__)
  38 typedef unsigned char   u_char;
  39 typedef unsigned int    u_int;
  40 typedef unsigned long   u_long;
  41 typedef unsigned short  u_short;
  42 #endif /* _WIN32 || __DJGPP__ */
  43 
  44 #ifdef  NO_POSIX_SIGNALS
  45 #define sigemptyset(set)        (*(set) = 0)
  46 #define sigfillset(set)         (*(set) = ~(sigset_t)0, 0)
  47 #define sigaddset(set,signo)    (*(set) |= sigmask(signo), 0)
  48 #define sigdelset(set,signo)    (*(set) &= ~sigmask(signo), 0)
  49 #define sigismember(set,signo)  ((*(set) & sigmask(signo)) != 0)
  50 
  51 #define SIG_BLOCK       1
  52 #define SIG_UNBLOCK     2
  53 #define SIG_SETMASK     3
  54 
  55 static int __sigtemp;           /**< For the use of #sigprocmask */
  56 
  57 /** @remark
  58  *      Repeated test of @CODE{oset != NULL} is to avoid @CODE{"*0"}.
  59  */
  60 #define sigprocmask(how, set, oset)                                     \
  61         ((__sigtemp =                                                   \
  62         (((how) == SIG_BLOCK) ?                                         \
  63                 sigblock(0) | *(set) :                                  \
  64         (((how) == SIG_UNBLOCK) ?                                       \
  65                 sigblock(0) & ~(*(set)) :                               \
  66         ((how) == SIG_SETMASK ?                                         \
  67                 *(set) : sigblock(0))))),                               \
  68         ((oset) ? (*(oset ? oset : set) = sigsetmask(__sigtemp)) :      \
  69                 sigsetmask(__sigtemp)), 0)
  70 #endif
  71 
  72 /**
  73  * @name BYTE_ORDER
  74  * @details
  75  * If your system doesn't have an include file with the appropriate
  76  * byte order set, make sure you specify the correct one.
  77  */
  78 /** @{ */
  79 #ifndef BYTE_ORDER
  80 #define LITTLE_ENDIAN   1234
  81 #define BIG_ENDIAN      4321
  82 #ifdef WORDS_BIGENDIAN
  83 #define BYTE_ORDER BIG_ENDIAN
  84 #else
  85 #define BYTE_ORDER LITTLE_ENDIAN
  86 #endif
  87 #endif
  88 /** @} */
  89 
  90 /** @name Compatibility macros */
  91 /*
  92  * Old definitions were rewritten using 'HAVE_XXX' macros.
  93  *
  94  * #if defined(SYSV) || defined(SYSTEM5)
  95  * #define      index(a, b)             strchr(a, b)
  96  * #define      rindex(a, b)            strrchr(a, b)
  97  * #define      bzero(a, b)             memset(a, 0, b)
  98  * #define      bcmp(a, b, n)           memcmp(a, b, n)
  99  * #define      bcopy(a, b, n)          memmove(b, a, n)
 100  * #endif
 101  * 
 102  * #if defined(BSD) || defined(BSD4_3)
 103  * #define      strchr(a, b)            index(a, b)
 104  * #define      strrchr(a, b)           rindex(a, b)
 105  * #define      memcmp(a, b, n)         bcmp(a, b, n)
 106  * #define      memmove(a, b, n)        bcopy(b, a, n)
 107  * #endif
 108 */
 109 /** @{ */
 110 #if !defined (HAVE_INDEX) && defined (HAVE_STRCHR)
 111 #define index(a, b)             strchr(a, b)
 112 #endif
 113 #if !defined (HAVE_RINDEX) && defined (HAVE_STRRCHR)
 114 #define rindex(a, b)            strrchr(a, b)
 115 #endif
 116 #if !defined (HAVE_BZERO) && defined (HAVE_MEMSET)
 117 #define bzero(a, b)             memset(a, 0, b)
 118 #endif
 119 #if !defined (HAVE_BCMP) && defined (HAVE_MEMCMP)
 120 #define bcmp(a, b, n)           memcmp(a, b, n)
 121 #endif
 122 #if !defined (HAVE_BCOPY) && defined (HAVE_MEMMOVE)
 123 #define bcopy(a, b, n)          memmove(b, a, n)
 124 #endif
 125 
 126 #if !defined (HAVE_STRCHR) && defined (HAVE_INDEX)
 127 #define strchr(a, b)            index(a, b)
 128 #endif
 129 #if !defined (HAVE_STRRCHR) && defined (HAVE_RINDEX)
 130 #define strrchr(a, b)           rindex(a, b)
 131 #endif
 132 #if !defined (HAVE_MEMCMP) && defined (HAVE_BCMP)
 133 #define memcmp(a, b, n)         bcmp(a, b, n)
 134 #endif
 135 #if !defined (HAVE_MEMMOVE) && defined (HAVE_BCOPY)
 136 #define memmove(a, b, n)        bcopy(b, a, n)
 137 #endif
 138 /** @} */
 139 
 140 /**
 141  * @def O_ACCMODE
 142  * @details
 143  * 32-bit machine.  The #DB routines are theoretically independent of
 144  * the size of @NAME{u_shorts} and @NAME{u_longs}, but I don't know that anyone has
 145  * ever actually tried it.  At a minimum, change the following @CODE{\#define}'s
 146  * if you are trying to compile on a different type of system.
 147  */
 148 /** @{ */
 149 #ifndef O_ACCMODE                       /** @NAME{POSIX 1003.1} access mode mask. */
 150 #define O_ACCMODE       (O_RDONLY|O_WRONLY|O_RDWR)
 151 #endif
 152 /** @} */
 153 
 154 #ifndef _POSIX2_RE_DUP_MAX              /** @NAME{POSIX 1003.2} RE limit. */
 155 #define _POSIX2_RE_DUP_MAX      255
 156 #endif
 157 
 158 /**
 159  * @details
 160  * If you can't provide lock values in the @XREF{open,2} call.  Note, this
 161  * allows races to happen.
 162  */
 163 /** @{ */
 164 #ifndef O_EXLOCK                        /** @NAME{4.4BSD} extension. */
 165 #define O_EXLOCK        0
 166 #endif
 167 /** @} */
 168 
 169 #ifndef O_SHLOCK                        /** @NAME{4.4BSD} extension. */
 170 #define O_SHLOCK        0
 171 #endif
 172 
 173 #ifndef O_BINARY        /** @NAME{UNIX} systems don't often have or need this */
 174 #define O_BINARY 0
 175 #endif
 176 
 177 #ifndef O_NONBLOCK      /** @NAME{Win32} systems doesn't have or need this */
 178 #define O_NONBLOCK      0
 179 #endif
 180 
 181 #ifndef EFTYPE          /** @NAME{POSIX 1003.1} format errno. */
 182 #define EFTYPE          EINVAL
 183 #endif
 184 
 185 /** @name POSIX 1003.1 seek values */
 186 /** @{ */
 187 #ifndef SEEK_END
 188 #define SEEK_SET        0
 189 #define SEEK_CUR        1
 190 #define SEEK_END        2
 191 #endif
 192 /** @} */
 193 
 194 #ifndef _POSIX2_RE_DUP_MAX      /** @NAME{POSIX 1003.2} values. */
 195 #define _POSIX2_RE_DUP_MAX      255
 196 #endif
 197 
 198 #ifndef NULL            /** @NAME{ANSI C} @CODE{\#define}s @VAR{NULL} everywhere. */
 199 #define NULL            0
 200 #endif
 201 
 202 #ifndef MAX                             /** Usually found in @FILE{\<sys/param.h\>}. */
 203 #define MAX(_a,_b)      ((_a)<(_b)?(_b):(_a))
 204 #endif
 205 #ifndef MIN                             /** Usually found in @FILE{\<sys/param.h\>}. */
 206 #define MIN(_a,_b)      ((_a)<(_b)?(_a):(_b))
 207 #endif
 208 
 209 /** @name POSIX 1003.1 file type tests. */
 210 /** @{ */
 211 #ifndef S_ISDIR
 212                 /** directory */
 213 #define S_ISDIR(m)      ((m & 0170000) == 0040000)
 214                 /** char special */
 215 #define S_ISCHR(m)      ((m & 0170000) == 0020000)
 216                 /** block special */
 217 #define S_ISBLK(m)      ((m & 0170000) == 0060000)
 218                 /** regular file */
 219 #define S_ISREG(m)      ((m & 0170000) == 0100000)
 220                 /** fifo */
 221 #define S_ISFIFO(m)     ((m & 0170000) == 0010000)
 222 #endif
 223 /** @} */
 224 
 225 #ifndef HAVE_LSTAT
 226 #define lstat   stat
 227 #endif
 228 #ifndef HAVE_GETCWD
 229 #define getcwd(buf, max) getwd (buf)
 230 #endif
 231 
 232 #endif /* !_COMPAT_H_ */

/* [previous][next][first][last][top][bottom][index][help] */