home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / n / bind / bind-4.001 / bind-4~ / bind-4.9.3-BETA9 / conf / portability.h < prev   
C/C++ Source or Header  |  1994-07-22  |  12KB  |  457 lines

  1. /* defs.h - include or define things that aren't present on all systems
  2.  * vixie@decwrl 26dec92 [new]
  3.  *
  4.  * $Id: portability.h,v 4.9.1.24 1994/07/22 08:42:30 vixie Exp $
  5.  */
  6.  
  7. /*
  8.  * ++Copyright++
  9.  * -
  10.  * Copyright (c) 
  11.  *    The Regents of the University of California.  All rights reserved.
  12.  * 
  13.  * Redistribution and use in source and binary forms, with or without
  14.  * modification, are permitted provided that the following conditions
  15.  * are met:
  16.  * 1. Redistributions of source code must retain the above copyright
  17.  *    notice, this list of conditions and the following disclaimer.
  18.  * 2. Redistributions in binary form must reproduce the above copyright
  19.  *    notice, this list of conditions and the following disclaimer in the
  20.  *    documentation and/or other materials provided with the distribution.
  21.  * 3. All advertising materials mentioning features or use of this software
  22.  *    must display the following acknowledgement:
  23.  *     This product includes software developed by the University of
  24.  *     California, Berkeley and its contributors.
  25.  * 4. Neither the name of the University nor the names of its contributors
  26.  *    may be used to endorse or promote products derived from this software
  27.  *    without specific prior written permission.
  28.  * 
  29.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  30.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  32.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  33.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  35.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  36.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  37.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  38.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  39.  * SUCH DAMAGE.
  40.  * -
  41.  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  42.  * 
  43.  * Permission to use, copy, modify, and distribute this software for any
  44.  * purpose with or without fee is hereby granted, provided that the above
  45.  * copyright notice and this permission notice appear in all copies, and that
  46.  * the name of Digital Equipment Corporation not be used in advertising or
  47.  * publicity pertaining to distribution of the document or software without
  48.  * specific, written prior permission.
  49.  * 
  50.  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  51.  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  52.  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
  53.  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  54.  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  55.  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  56.  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  57.  * SOFTWARE.
  58.  * -
  59.  * --Copyright--
  60.  */
  61.  
  62. /* XXX:    this file has become a hopeless morass, and will be redone someday. */
  63.  
  64. #include <string.h>
  65. #include <sys/types.h>
  66. #include <sys/param.h>
  67. #ifndef TIME_H_INCLUDED
  68. # include <sys/time.h>
  69. # define TIME_H_INCLUDED
  70. #endif
  71.  
  72. #if defined(__convex__)
  73. # if !defined(_POSIX_SOURCE)
  74. #  define _POSIX_SOURCE
  75. # endif
  76. # define USE_UTIME
  77. # define NEED_PUTENV
  78. #endif
  79.  
  80. #if defined(_CRAY)
  81. # if !defined(_POSIX_SOURCE)
  82. #  define _POSIX_SOURCE
  83. # endif
  84. # define writev(a,b,c) __writev(a,b,c)
  85. # define setitimer(a,b,c) __setitimer(a,b,c)
  86. #endif
  87.  
  88. /* SCO UNIX defines only this unique symbol, apparently. */
  89. #if defined(M_UNIX)
  90. /* XXX - why is this POSIX_SOURCE instead of _POSIX_SOURCE? */
  91. # undef POSIX_SOURCE
  92. # define POSIX_SIGNALS
  93. # define HAVE_FCHMOD 0
  94. # define writev(a,b,c) __writev(a,b,c)
  95. # define ftruncate(a,b) __ftruncate(a,b)
  96. #endif
  97.  
  98. #ifdef NeXT
  99. # define NEED_PUTENV
  100. # define NEED_SETENV
  101. #endif
  102.  
  103. #if defined(__sgi)
  104. # define BSD 43
  105. # define vfork fork
  106. #endif
  107.  
  108. #if defined(SUNOS4)
  109. # define BSD 43
  110. #endif
  111.  
  112. #if defined(_POSIX_SOURCE) || defined(__sgi) || defined(ultrix) || \
  113.     defined(__hpux) || (defined(BSD) && (BSD >= 199103)) || \
  114.     (defined(sun) && defined(SYSV))
  115. # define USE_POSIX
  116. #endif
  117.  
  118. #if defined(ultrix) && !defined(BSD)
  119. # define BSD 42
  120. #endif
  121.  
  122. #if defined(host_mips) && defined(SYSTYPE_BSD43)
  123. # define RISCOS_BSD
  124. #endif
  125.  
  126. #if defined(SVR4) && !defined(SYSV)
  127. # define SYSV
  128. #endif
  129.  
  130. #if defined(SYSV) || defined(ultrix) || (defined(BSD) && BSD >= 199306)
  131. # define USE_UTIME
  132. #endif
  133.  
  134. #if defined(BSD) && BSD >= 199006 && !defined(i386) && !defined(RISCOS_BSD)
  135. # define HAVE_DAEMON
  136. #endif
  137.  
  138. #if defined(__hpux)
  139. # if defined(__STDC__)
  140. #  define select(a,b,c,d,e) select(a, (int *)b, (int *)c, (int *)d, e)
  141. #  define ctime(x) ctime((const time_t *)x)
  142. # endif /*__STDC__*/
  143. # ifndef SYSV
  144. # define USE_UTIME
  145. # define setlinebuf(x) setvbuf(x, NULL, _IOLBF, BUFSIZ)
  146. # define SIGWINCH SIGWINDOW
  147. # endif /*SYSV*/
  148. #endif /*__hpux*/
  149.  
  150. #if defined(_SEQUENT_)
  151. # include <netinet/in_systm.h>
  152. # define USE_UTIME
  153. # define USE_POSIX
  154. # define NEED_GETTIMEOFDAY
  155. # define _TIMEZONE timezoneBSD
  156. struct timezoneBSD {
  157.     int tz_minuteswest;
  158.     int tz_dsttime;
  159. };
  160. #endif
  161.  
  162. #ifndef __P
  163. # if defined(__STDC__) || defined(__GNUC__)
  164. #  define __P(x) x
  165. # else
  166. #  define __P(x) ()
  167. # endif
  168. #endif
  169.  
  170. #ifndef _TIMEZONE
  171. # define _TIMEZONE timezone
  172. #endif
  173.  
  174. #if defined(USE_POSIX)
  175. # include <stdlib.h>
  176. # include <unistd.h>
  177. # include <limits.h>
  178.  
  179. #else
  180.  
  181. # define NEED_STRTOUL
  182.  
  183. # define STDIN_FILENO    0
  184. # define STDOUT_FILENO    1
  185. # define STDERR_FILENO    2
  186. # ifndef NeXT
  187. extern char *getenv __P((char *));
  188. # else
  189. extern char *getenv __P((const char *));
  190. # endif
  191. extern int errno;
  192.  
  193. # if !defined(DMALLOC) && !defined(NeXT)
  194. extern char *malloc(), *realloc(), *calloc();
  195. #  if defined(sun)
  196. extern int free();
  197. #  else
  198. extern void free();
  199. #  endif
  200. # endif
  201.  
  202. extern int getdtablesize __P((void));
  203. # ifdef SHORT_FNAMES
  204. extern long pathconf __P((const char *path, int name));
  205. # endif
  206.  
  207. #endif /*USE_POSIX*/
  208.  
  209. #ifndef UINT_MAX
  210. # ifdef __STDC__
  211. #  define UINT_MAX    4294967295u             /* max value of an "u_int" */
  212. # else
  213. #  define UINT_MAX    ((unsigned)4294967295)  /* max value of an "u_int" */
  214. # endif
  215. #  define ULONG_MAX    UINT_MAX        /* max decimal value of a "u_long" */
  216. #endif
  217.  
  218. #ifndef INT_MAX
  219. # define INT_MAX    2147483647    /* max decimal value of an "int" */
  220. #endif
  221.  
  222. #ifndef    IN_LOOPBACKNET
  223. # define IN_LOOPBACKNET    127
  224. #endif
  225.  
  226. #ifndef    INADDR_NONE
  227. # define INADDR_NONE    0xffffffff
  228. #endif
  229.  
  230. #if defined(apollo)
  231.         /* Defined in /usr/include/netinet/in.h but doesn't work */
  232. #undef IP_OPTIONS
  233. #endif
  234.  
  235. #if !defined(__STDC__) && !defined(const)
  236. # define const /*constant*/
  237. #endif
  238.  
  239. #if !defined(__convex__) && (!defined(BSD) || (BSD < 199103))
  240. int      strcasecmp __P((const char *, const char *));
  241. #endif
  242.  
  243. /* is USE_POSIX the right thing to use here? */
  244. #if (!defined(BSD) || (BSD <= 43)) && \
  245.     !defined(NeXT) && \
  246.     !defined(__convex__) && \
  247.     !defined(USE_POSIX)
  248. extern void syslog();
  249. extern char *ctime __P((const time_t *clock));
  250. extern int    close(), setitimer(), recv(), sendto(), sigsetmask(),
  251.         atoi(), getpid(), fork(), read(), ioctl(),
  252.         setsockopt(), socket(), bind();
  253. #endif
  254.  
  255. #if !defined(bcopy)    /* some machines have their own macros for this */
  256. # if defined(USE_POSIX) || \
  257.      (defined(__STDC__) && !defined(sun) && !defined(sequent))
  258. /* use ANSI C3.159-1989 (``ANSI C'') functions if possible;
  259.  * ideally we would change the code to use them and then
  260.  * define them in terms of bcopy et al if !defined(__STDC__)
  261.  * but that's more work.
  262.  */
  263. #  define bcopy(a,b,c) memmove(b,a,c)
  264. #  define bzero(a,b) memset(a,0,b)
  265. #  define bcmp(a,b,c) memcmp(a,b,c)
  266. # else
  267. extern void bcopy();
  268. extern void bzero();
  269. extern int bcmp();
  270. # endif /* BSD */
  271. #endif /* bcopy */
  272.  
  273. #if (!defined(BSD) || (BSD < 43) || defined(RISCOS_BSD)) \
  274.     && !defined(USE_POSIX) && !defined(apollo) && !defined(sequent) \
  275.     && !defined(M_UNIX)
  276. # define NEED_STRERROR
  277. # define NEED_PUTENV
  278. #endif
  279.  
  280. #if defined(SUNOS4)
  281. # define NEED_STRERROR
  282. #endif
  283.  
  284. #if (!defined(BSD) || (BSD < 43))
  285. # define NEED_MKSTEMP
  286. # if !defined(ultrix) && !defined(apollo)
  287. #  define NEED_STRCASECMP
  288. #  define NEED_MKTEMP
  289. #  define NEED_STRPBRK
  290. # endif
  291. #endif
  292.  
  293. #if defined(USE_POSIX)
  294. # define POSIX_SIGNALS
  295. #endif
  296.  
  297. /*
  298.  * Attempt to configure for type of function returned by signal-catching
  299.  * functions (which signal and sigvec.sv_handler take a pointer to).
  300.  * This can guess for BSD; otherwise, define SIG_FN externally.
  301.  */
  302. #ifndef    SIG_FN
  303. # ifdef BSD
  304. #  if (BSD >= 199006) || defined(NeXT) || defined(__osf__) || defined(sun) \
  305.     || defined(ultrix) || defined(apollo) || defined(POSIX_SIGNALS)
  306. #   define SIG_FN void        /* signal-catching functions return void */
  307. #  else
  308. #   define SIG_FN int        /* signal-catching functions return int */
  309. #  endif
  310. # else /*BSD*/
  311. #  define SIG_FN void        /* signal-catching functions return void */
  312. # endif /*BSD*/
  313. #endif
  314.  
  315. #if !defined(ntohl) && !defined(htonl) && defined(BSD) && (BSD <= 43)
  316. /* if these aren't null macros in netinet/in.h, extern them here. */
  317. extern u_short htons(), ntohs();
  318. extern u_long htonl(), ntohl();
  319. #endif
  320.  
  321. #if defined(USE_POSIX) && !defined(sun) && !defined(__sgi) \
  322.     && !defined(__convex__) && !defined(ultrix)
  323. # define PORT_NONBLOCK    O_NONBLOCK
  324. # define PORT_WOULDBLK    EAGAIN
  325. #else
  326. # define PORT_NONBLOCK    O_NDELAY
  327. # define PORT_WOULDBLK    EWOULDBLOCK
  328. #endif
  329.  
  330. #if defined(USE_POSIX)
  331. # define USE_SETSID
  332. #endif
  333.  
  334. #if defined(USE_POSIX) || !defined(SYSV)
  335. #define USE_WAITPID
  336. #endif
  337.  
  338. #if !defined(USE_POSIX)
  339. #define waitpid(x,y,z) (wait3(y,z,(struct rusage *)NULL))
  340. #endif
  341.  
  342. #if defined(NeXT) || defined(_AIX)
  343. # undef WIFEXITED
  344. # undef WEXITSTATUS
  345. # undef WIFSIGNALED
  346. # undef WTERMSIG
  347. #endif /* NeXT */
  348.  
  349. #if defined(sequent)
  350. #define WEXITSTATUS(x)    ((x).w_retcode)
  351. #define WTERMSIG(x)    ((x).w_termsig)
  352. #endif /* sequent */
  353.  
  354. #if !defined(WIFEXITED)
  355. # define WIFEXITED(x) (!(x & 0200))
  356. #endif
  357. #if !defined(WEXITSTATUS)
  358. # define WEXITSTATUS(x) (x >> 8)
  359. #endif
  360. #if !defined(WIFSIGNALED)
  361. # define WIFSIGNALED(x) ((x & 0200) && ((x & 0200) != 0177))
  362. #endif
  363. #if !defined(WTERMSIG)
  364. # define WTERMSIG(x) (x & 0177)
  365. #endif
  366.  
  367. #ifndef S_ISDIR
  368. # ifndef S_IFMT
  369. #  define S_IFMT 0170000
  370. # endif
  371. # ifndef S_IFDIR
  372. #  define S_IFDIR 0040000
  373. # endif
  374. # define S_ISDIR(m)    ((m & S_IFMT) == S_IFDIR)
  375. #endif
  376.  
  377. #ifndef S_ISREG
  378. # ifndef S_IFMT
  379. #  define S_IFMT 0170000
  380. # endif
  381. # ifndef S_IFREG
  382. #  define S_IFREG 0100000
  383. # endif
  384. # define S_ISREG(m)    ((m & S_IFMT) == S_IFREG)
  385. #endif
  386.  
  387. #ifndef S_ISFIFO
  388. # ifndef S_IFMT
  389. #  define S_IFMT 0170000
  390. # endif
  391. # ifndef S_IFIFO
  392. #  define S_IFIFO 0010000
  393. # endif
  394. # define S_ISFIFO(m)    ((m & S_IFMT) == S_IFIFO)
  395. #endif
  396.  
  397. #if (defined(ultrix) || defined(__osf__)) && defined(NEED_STRTOUL)
  398. # undef NEED_STRTOUL
  399. #endif
  400.  
  401. #if defined(ultrix) || defined(__osf__)
  402. # define MAYBE_HESIOD
  403. #endif
  404.  
  405. #ifndef FD_SET
  406. #define    NFDBITS        32
  407. #define    FD_SETSIZE    32
  408. #define    FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  409. #define    FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  410. #define    FD_ISSET(n, p)    ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  411. #define FD_ZERO(p)    bzero((char *)(p), sizeof(*(p)))
  412. #endif
  413.  
  414. #ifndef MIN
  415. # define MIN(x, y)    ((x > y) ?y :x)
  416. #endif
  417. #ifndef MAX
  418. # define MAX(x, y)    ((x > y) ?x :y)
  419. #endif
  420.  
  421. #if !defined(PATH_MAX)
  422. # if defined(_POSIX_PATH_MAX)
  423. #  define PATH_MAX _POSIX_PATH_MAX
  424. # else
  425. #  if defined(MAXPATHLEN)
  426. #   define PATH_MAX MAXPATHLEN
  427. #  endif
  428. # endif
  429. #endif
  430.  
  431. /*
  432.  *  Because Convex has true library function feof() which is
  433.  *  patently wrong (it test bit _IOREAD) we need feof() as
  434.  *  a macro.
  435.  */
  436. #if defined(__convex__) && !defined(feof)
  437. #  define   feof(p)    ((p)->_flag&_IOEOF)
  438. #endif
  439.  
  440. /*
  441.  * Assume that a system has fchmod() unless something above says otherwise.
  442.  */
  443. #if !defined(HAVE_FCHMOD)
  444. # define HAVE_FCHMOD 1
  445. #endif
  446.  
  447. /*
  448.  * Prototype the functions we'll be supplying.
  449.  */
  450. #ifdef NEED_PUTENV
  451. extern int putenv __P((char *));
  452. #endif
  453.  
  454. #ifdef NEED_GETTIMEOFDAY
  455. extern int gettimeofday __P((struct timeval *, struct _TIMEZONE *));
  456. #endif
  457.