]>
git.saurik.com Git - apple/libinfo.git/blob - dns.subproj/portability.h
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
24 /* portability.h - include or define things that aren't present on all systems
25 * vixie@decwrl 26dec92 [new]
27 * $Id: portability.h,v 1.3 2004/10/28 21:58:14 emoy Exp $
34 * The Regents of the University of California. All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
66 * Permission to use, copy, modify, and distribute this software for any
67 * purpose with or without fee is hereby granted, provided that the above
68 * copyright notice and this permission notice appear in all copies, and that
69 * the name of Digital Equipment Corporation not be used in advertising or
70 * publicity pertaining to distribution of the document or software without
71 * specific, written prior permission.
73 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
74 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
75 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
76 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
77 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
78 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
79 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
85 /* XXX: this file has become a hopeless morass, and will be redone someday. */
88 #include <sys/types.h>
89 #include <sys/param.h>
90 #ifndef TIME_H_INCLUDED
91 # include <sys/time.h>
92 # define TIME_H_INCLUDED
96 # ifndef _POSIX_SOURCE
97 # define _POSIX_SOURCE
102 # define NEED_STRTOUL
103 # define NEED_FTRUNCATE
105 # include <sys/bsdtypes.h>
106 # include <sys/sioctl.h>
107 # include <sys/stream.h>
108 # include <net/errno.h>
111 #if defined(__convex__)
112 # if !defined(_POSIX_SOURCE)
113 # define _POSIX_SOURCE
120 # if !defined(_POSIX_SOURCE)
121 # define _POSIX_SOURCE
123 # define writev(a,b,c) __writev(a,b,c)
124 # define setitimer(a,b,c) __setitimer(a,b,c)
127 /* This is defined in the Makefile for ISC compiles. */
129 # define ftruncate(a,b) __ftruncate(a,b)
132 # define HAVE_FCHMOD 0
135 /* SCO UNIX defines only this unique symbol, apparently. */
137 /* XXX - why is this POSIX_SOURCE instead of _POSIX_SOURCE? */
139 # define POSIX_SIGNALS
140 # define HAVE_FCHMOD 0
141 # define writev(a,b,c) __writev(a,b,c)
142 # define ftruncate(a,b) __ftruncate(a,b)
145 #if defined(__APPLE__) && BSD < 199506
159 #if defined(_AUX_SOURCE)
161 # define NEED_STRERROR
162 # define NEED_STRTOUL
168 #if defined(SVR4) && !defined(SYSV)
172 #if defined(_POSIX_SOURCE) || defined(__sgi) || defined(__ultrix) || \
173 defined(__hpux) || (defined(BSD) && (BSD >= 199103)) || \
174 (defined(sun) && defined(SYSV))
178 #if defined(__ultrix) && !defined(BSD)
182 #if defined(host_mips) && defined(SYSTYPE_BSD43)
186 #if defined(SYSV) || defined(__ultrix) || defined(__osf__) \
187 || (defined(BSD) && BSD >= 199306) || defined(linux)
189 # define HAVE_SETVBUF
192 #if defined(SYSV) && !defined(SVR4)
196 #if defined(sun) || defined(SVR4)
197 # define NETREAD_BROKEN
200 #if defined(BSD) && BSD >= 199006 && !defined(i386) && !defined(RISCOS_BSD)
204 #if !defined(BSD) || (BSD <= 199006)
205 # if !defined(__APPLE__)
206 # define NEED_INETADDR
208 # define NEED_INETATON
212 # if defined(__STDC__)
213 # define select(a,b,c,d,e) select(a, (int *)b, (int *)c, (int *)d, e)
214 # define ctime(x) ctime((const time_t *)x)
218 # define setlinebuf(x) setvbuf(x, NULL, _IOLBF, BUFSIZ)
219 # if !defined(SIGWINCH) /*pre 9.0*/
220 # define SIGWINCH SIGWINDOW
223 /* XXX: better autodetection of the need for "struct linger" would be nice */
226 int l_onoff
; /* option on/off */
227 int l_linger
; /* linger time */
232 #if defined(_SEQUENT_)
233 # include <netinet/in_systm.h>
236 # define NEED_GETTIMEOFDAY
237 # define _TIMEZONE timezoneBSD
245 # if defined(__STDC__) || defined(__GNUC__)
253 # define _TIMEZONE timezone
256 #if defined(USE_POSIX)
263 # define NEED_STRTOUL
265 # define STDIN_FILENO 0
266 # define STDOUT_FILENO 1
267 # define STDERR_FILENO 2
269 extern char *getenv
__P((char *));
271 extern char *getenv
__P((const char *));
275 # if !defined(DMALLOC) && !defined(__APPLE__)
276 extern char *malloc(), *realloc(), *calloc();
284 extern int getdtablesize
__P((void));
286 extern long pathconf
__P((const char *path
, int name
));
293 # define UINT_MAX 4294967295u /* max value of an "unsigned int" */
295 # define UINT_MAX ((unsigned)4294967295) /* max value of an "unsigned int" */
297 # define ULONG_MAX UINT_MAX /* max decimal value of a "unsigned long" */
301 # define INT_MAX 2147483647 /* max decimal value of an "int" */
305 # define RAND_MAX 0x7fffffff
308 #ifndef IN_LOOPBACKNET
309 # define IN_LOOPBACKNET 127
313 # define INADDR_NONE 0xffffffff
317 /* Defined in /usr/include/netinet/in.h but doesn't work */
321 #if !defined(__STDC__) && !defined(const)
322 # define const /*constant*/
325 #if !defined(__convex__) && (!defined(BSD) || (BSD < 199103))
326 int strcasecmp
__P((const char *, const char *));
329 /* is USE_POSIX the right thing to use here? */
330 #if (!defined(BSD) || (BSD <= 43)) && \
332 !defined(__convex__) && \
335 extern void syslog();
337 extern char *ctime
__P((const time_t *clock
));
338 extern int close(), setitimer(), recv(), sendto(), sigsetmask(),
339 atoi(), getpid(), fork(), read(), ioctl(),
340 setsockopt(), socket(), bind();
343 #if !defined(bcopy) /* some machines have their own macros for this */
344 # if defined(USE_POSIX) || \
345 (defined(__STDC__) && !defined(sun) && !defined(sequent))
346 /* use ANSI C3.159-1989 (``ANSI C'') functions if possible;
347 * ideally we would change the code to use them and then
348 * define them in terms of bcopy et al if !defined(__STDC__)
349 * but that's more work.
351 #if defined(USE_MEMCPY)
352 # define bcopy(a,b,c) memcpy(b,a,c)
354 # define bcopy(a,b,c) memmove(b,a,c)
356 # define bzero(a,b) memset(a,0,b)
357 # define bcmp(a,b,c) memcmp(a,b,c)
365 #if (!defined(BSD) || (BSD < 43) || defined(RISCOS_BSD)) \
366 && !defined(USE_POSIX) && !defined(apollo) && !defined(sequent) \
368 # define NEED_STRERROR
369 #if !defined(ultrix) && !defined(NCR)
375 # define NEED_STRERROR
378 # define NEED_STRCASECMP
382 #if (!defined(BSD) || (BSD < 43))
383 # define NEED_MKSTEMP
384 # if !defined(__ultrix) && !defined(apollo)
385 # define NEED_STRCASECMP
388 # define NEED_STRPBRK
393 #if defined(USE_POSIX)
394 # define POSIX_SIGNALS
398 * Attempt to configure for type of function returned by signal-catching
399 * functions (which signal and sigvec.sv_handler take a pointer to).
400 * This can guess for BSD; otherwise, define SIG_FN externally.
404 # if (BSD >= 199006) || defined(__APPLE__) || defined(__osf__) || defined(sun) \
405 || defined(__ultrix) || defined(apollo) || defined(POSIX_SIGNALS)
406 # define SIG_FN void /* signal-catching functions return void */
408 # define SIG_FN int /* signal-catching functions return int */
411 # define SIG_FN void /* signal-catching functions return void */
415 #if !defined(ntohl) && !defined(htonl) && defined(BSD) && (BSD <= 43)
416 /* if these aren't null macros in netinet/in.h, extern them here. */
417 extern unsigned short htons(), ntohs();
418 extern unsigned long htonl(), ntohl();
421 #if defined(USE_POSIX) && !defined(sun) && !defined(__sgi) \
422 && !defined(__convex__) && !defined(__ultrix) && !defined(_AUX_SOURCE)
423 # define PORT_NONBLOCK O_NONBLOCK
424 # define PORT_WOULDBLK EAGAIN
426 # define PORT_NONBLOCK O_NDELAY
427 # define PORT_WOULDBLK EWOULDBLOCK
430 #if defined(USE_POSIX)
434 #if defined(USE_POSIX) || !defined(SYSV)
438 #if !defined(USE_POSIX)
439 #define waitpid(x,y,z) (wait3(y,z,(struct rusage *)NULL))
442 #if defined(__APPLE__) || defined(_AIX) || defined(sun386)
450 #define WEXITSTATUS(x) ((x).w_retcode)
451 #define WTERMSIG(x) ((x).w_termsig)
454 #if !defined(WIFEXITED)
455 # define WIFEXITED(x) (!(x & 0177))
457 #if !defined(WEXITSTATUS)
458 # define WEXITSTATUS(x) (x >> 8)
460 #if !defined(WIFSIGNALED)
461 # define WIFSIGNALED(x) ((x & 0177) && ((x & 0377) != 0177))
463 #if !defined(WTERMSIG)
464 # define WTERMSIG(x) (x & 0177)
469 # define S_IFMT 0170000
472 # define S_IFDIR 0040000
474 # define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
479 # define S_IFMT 0170000
482 # define S_IFREG 0100000
484 # define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
489 # define S_IFMT 0170000
492 # define S_IFIFO 0010000
494 # define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
497 #if defined(NEED_STRTOUL) && \
498 (defined(__ultrix) || defined(__osf__) || defined(NeXT))
502 #if defined(__ultrix) || defined(__osf__)
503 # define MAYBE_HESIOD
508 #define FD_SETSIZE 32
509 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
510 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
511 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
512 #define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
516 # define MIN(x, y) ((x > y) ?y :x)
519 # define MAX(x, y) ((x > y) ?x :y)
522 #if !defined(PATH_MAX)
523 # if defined(_POSIX_PATH_MAX)
524 # define PATH_MAX _POSIX_PATH_MAX
526 # if defined(MAXPATHLEN)
527 # define PATH_MAX MAXPATHLEN
532 #if defined(BSD) || defined(__osf__) || defined(__convex__)
533 # define HAVE_GETRUSAGE
536 /* May be set in the Makefile. */
537 #if defined(HAVE_GETRUSAGE)
538 # include <sys/resource.h>
542 * Because Convex has true library function feof() which is
543 * patently wrong (it test bit _IOREAD) we need feof() as
546 #if defined(__convex__) && !defined(feof)
547 # define feof(p) ((p)->_flag&_IOEOF)
550 #if defined(M_UNIX) || defined(linux)
551 # define SPURIOUS_ECONNREFUSED
555 * Assume that a system has fchmod() unless something above says otherwise.
557 #if !defined(HAVE_FCHMOD)
558 # define HAVE_FCHMOD 1
562 * Prototype the functions we'll be supplying.
565 extern int putenv
__P((char *));
568 #ifdef NEED_GETTIMEOFDAY
569 extern int gettimeofday
__P((struct timeval
*, struct _TIMEZONE
*));