2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* portability.h - include or define things that aren't present on all systems
26 * vixie@decwrl 26dec92 [new]
28 * $Id: portability.h,v 1.2 1999/10/14 21:56:45 wsanchez Exp $
35 * The Regents of the University of California. All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
67 * Permission to use, copy, modify, and distribute this software for any
68 * purpose with or without fee is hereby granted, provided that the above
69 * copyright notice and this permission notice appear in all copies, and that
70 * the name of Digital Equipment Corporation not be used in advertising or
71 * publicity pertaining to distribution of the document or software without
72 * specific, written prior permission.
74 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
75 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
76 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
77 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
78 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
79 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
80 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
86 /* XXX: this file has become a hopeless morass, and will be redone someday. */
89 #include <sys/types.h>
90 #include <sys/param.h>
91 #ifndef TIME_H_INCLUDED
92 # include <sys/time.h>
93 # define TIME_H_INCLUDED
97 # ifndef _POSIX_SOURCE
98 # define _POSIX_SOURCE
103 # define NEED_STRTOUL
104 # define NEED_FTRUNCATE
106 # include <sys/bsdtypes.h>
107 # include <sys/sioctl.h>
108 # include <sys/stream.h>
109 # include <net/errno.h>
112 #if defined(__convex__)
113 # if !defined(_POSIX_SOURCE)
114 # define _POSIX_SOURCE
121 # if !defined(_POSIX_SOURCE)
122 # define _POSIX_SOURCE
124 # define writev(a,b,c) __writev(a,b,c)
125 # define setitimer(a,b,c) __setitimer(a,b,c)
128 /* This is defined in the Makefile for ISC compiles. */
130 # define ftruncate(a,b) __ftruncate(a,b)
133 # define HAVE_FCHMOD 0
136 /* SCO UNIX defines only this unique symbol, apparently. */
138 /* XXX - why is this POSIX_SOURCE instead of _POSIX_SOURCE? */
140 # define POSIX_SIGNALS
141 # define HAVE_FCHMOD 0
142 # define writev(a,b,c) __writev(a,b,c)
143 # define ftruncate(a,b) __ftruncate(a,b)
146 #if defined(__APPLE__) && BSD < 199506
160 #if defined(_AUX_SOURCE)
162 # define NEED_STRERROR
163 # define NEED_STRTOUL
169 #if defined(SVR4) && !defined(SYSV)
173 #if defined(_POSIX_SOURCE) || defined(__sgi) || defined(__ultrix) || \
174 defined(__hpux) || (defined(BSD) && (BSD >= 199103)) || \
175 (defined(sun) && defined(SYSV))
179 #if defined(__ultrix) && !defined(BSD)
183 #if defined(host_mips) && defined(SYSTYPE_BSD43)
187 #if defined(SYSV) || defined(__ultrix) || defined(__osf__) \
188 || (defined(BSD) && BSD >= 199306) || defined(linux)
190 # define HAVE_SETVBUF
193 #if defined(SYSV) && !defined(SVR4)
197 #if defined(sun) || defined(SVR4)
198 # define NETREAD_BROKEN
201 #if defined(BSD) && BSD >= 199006 && !defined(i386) && !defined(RISCOS_BSD)
205 #if !defined(BSD) || (BSD <= 199006)
206 # if !defined(__APPLE__)
207 # define NEED_INETADDR
209 # define NEED_INETATON
213 # if defined(__STDC__)
214 # define select(a,b,c,d,e) select(a, (int *)b, (int *)c, (int *)d, e)
215 # define ctime(x) ctime((const time_t *)x)
219 # define setlinebuf(x) setvbuf(x, NULL, _IOLBF, BUFSIZ)
220 # if !defined(SIGWINCH) /*pre 9.0*/
221 # define SIGWINCH SIGWINDOW
224 /* XXX: better autodetection of the need for "struct linger" would be nice */
227 int l_onoff
; /* option on/off */
228 int l_linger
; /* linger time */
233 #if defined(_SEQUENT_)
234 # include <netinet/in_systm.h>
237 # define NEED_GETTIMEOFDAY
238 # define _TIMEZONE timezoneBSD
246 # if defined(__STDC__) || defined(__GNUC__)
254 # define _TIMEZONE timezone
257 #if defined(USE_POSIX)
264 # define NEED_STRTOUL
266 # define STDIN_FILENO 0
267 # define STDOUT_FILENO 1
268 # define STDERR_FILENO 2
270 extern char *getenv
__P((char *));
272 extern char *getenv
__P((const char *));
276 # if !defined(DMALLOC) && !defined(__APPLE__)
277 extern char *malloc(), *realloc(), *calloc();
285 extern int getdtablesize
__P((void));
287 extern long pathconf
__P((const char *path
, int name
));
294 # define UINT_MAX 4294967295u /* max value of an "u_int" */
296 # define UINT_MAX ((unsigned)4294967295) /* max value of an "u_int" */
298 # define ULONG_MAX UINT_MAX /* max decimal value of a "u_long" */
302 # define INT_MAX 2147483647 /* max decimal value of an "int" */
306 # define RAND_MAX 0x7fffffff
309 #ifndef IN_LOOPBACKNET
310 # define IN_LOOPBACKNET 127
314 # define INADDR_NONE 0xffffffff
318 /* Defined in /usr/include/netinet/in.h but doesn't work */
322 #if !defined(__STDC__) && !defined(const)
323 # define const /*constant*/
326 #if !defined(__convex__) && (!defined(BSD) || (BSD < 199103))
327 int strcasecmp
__P((const char *, const char *));
330 /* is USE_POSIX the right thing to use here? */
331 #if (!defined(BSD) || (BSD <= 43)) && \
333 !defined(__convex__) && \
336 extern void syslog();
338 extern char *ctime
__P((const time_t *clock
));
339 extern int close(), setitimer(), recv(), sendto(), sigsetmask(),
340 atoi(), getpid(), fork(), read(), ioctl(),
341 setsockopt(), socket(), bind();
344 #if !defined(bcopy) /* some machines have their own macros for this */
345 # if defined(USE_POSIX) || \
346 (defined(__STDC__) && !defined(sun) && !defined(sequent))
347 /* use ANSI C3.159-1989 (``ANSI C'') functions if possible;
348 * ideally we would change the code to use them and then
349 * define them in terms of bcopy et al if !defined(__STDC__)
350 * but that's more work.
352 #if defined(USE_MEMCPY)
353 # define bcopy(a,b,c) memcpy(b,a,c)
355 # define bcopy(a,b,c) memmove(b,a,c)
357 # define bzero(a,b) memset(a,0,b)
358 # define bcmp(a,b,c) memcmp(a,b,c)
366 #if (!defined(BSD) || (BSD < 43) || defined(RISCOS_BSD)) \
367 && !defined(USE_POSIX) && !defined(apollo) && !defined(sequent) \
369 # define NEED_STRERROR
370 #if !defined(ultrix) && !defined(NCR)
376 # define NEED_STRERROR
379 # define NEED_STRCASECMP
383 #if (!defined(BSD) || (BSD < 43))
384 # define NEED_MKSTEMP
385 # if !defined(__ultrix) && !defined(apollo)
386 # define NEED_STRCASECMP
389 # define NEED_STRPBRK
394 #if defined(USE_POSIX)
395 # define POSIX_SIGNALS
399 * Attempt to configure for type of function returned by signal-catching
400 * functions (which signal and sigvec.sv_handler take a pointer to).
401 * This can guess for BSD; otherwise, define SIG_FN externally.
405 # if (BSD >= 199006) || defined(__APPLE__) || defined(__osf__) || defined(sun) \
406 || defined(__ultrix) || defined(apollo) || defined(POSIX_SIGNALS)
407 # define SIG_FN void /* signal-catching functions return void */
409 # define SIG_FN int /* signal-catching functions return int */
412 # define SIG_FN void /* signal-catching functions return void */
416 #if !defined(ntohl) && !defined(htonl) && defined(BSD) && (BSD <= 43)
417 /* if these aren't null macros in netinet/in.h, extern them here. */
418 extern u_short
htons(), ntohs();
419 extern u_long
htonl(), ntohl();
422 #if defined(USE_POSIX) && !defined(sun) && !defined(__sgi) \
423 && !defined(__convex__) && !defined(__ultrix) && !defined(_AUX_SOURCE)
424 # define PORT_NONBLOCK O_NONBLOCK
425 # define PORT_WOULDBLK EAGAIN
427 # define PORT_NONBLOCK O_NDELAY
428 # define PORT_WOULDBLK EWOULDBLOCK
431 #if defined(USE_POSIX)
435 #if defined(USE_POSIX) || !defined(SYSV)
439 #if !defined(USE_POSIX)
440 #define waitpid(x,y,z) (wait3(y,z,(struct rusage *)NULL))
443 #if defined(__APPLE__) || defined(_AIX) || defined(sun386)
451 #define WEXITSTATUS(x) ((x).w_retcode)
452 #define WTERMSIG(x) ((x).w_termsig)
455 #if !defined(WIFEXITED)
456 # define WIFEXITED(x) (!(x & 0177))
458 #if !defined(WEXITSTATUS)
459 # define WEXITSTATUS(x) (x >> 8)
461 #if !defined(WIFSIGNALED)
462 # define WIFSIGNALED(x) ((x & 0177) && ((x & 0377) != 0177))
464 #if !defined(WTERMSIG)
465 # define WTERMSIG(x) (x & 0177)
470 # define S_IFMT 0170000
473 # define S_IFDIR 0040000
475 # define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
480 # define S_IFMT 0170000
483 # define S_IFREG 0100000
485 # define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
490 # define S_IFMT 0170000
493 # define S_IFIFO 0010000
495 # define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
498 #if defined(NEED_STRTOUL) && \
499 (defined(__ultrix) || defined(__osf__) || defined(NeXT))
503 #if defined(__ultrix) || defined(__osf__)
504 # define MAYBE_HESIOD
509 #define FD_SETSIZE 32
510 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
511 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
512 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
513 #define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
517 # define MIN(x, y) ((x > y) ?y :x)
520 # define MAX(x, y) ((x > y) ?x :y)
523 #if !defined(PATH_MAX)
524 # if defined(_POSIX_PATH_MAX)
525 # define PATH_MAX _POSIX_PATH_MAX
527 # if defined(MAXPATHLEN)
528 # define PATH_MAX MAXPATHLEN
533 #if defined(BSD) || defined(__osf__) || defined(__convex__)
534 # define HAVE_GETRUSAGE
537 /* May be set in the Makefile. */
538 #if defined(HAVE_GETRUSAGE)
539 # include <sys/resource.h>
543 * Because Convex has true library function feof() which is
544 * patently wrong (it test bit _IOREAD) we need feof() as
547 #if defined(__convex__) && !defined(feof)
548 # define feof(p) ((p)->_flag&_IOEOF)
551 #if defined(M_UNIX) || defined(linux)
552 # define SPURIOUS_ECONNREFUSED
556 * Assume that a system has fchmod() unless something above says otherwise.
558 #if !defined(HAVE_FCHMOD)
559 # define HAVE_FCHMOD 1
563 * Prototype the functions we'll be supplying.
566 extern int putenv
__P((char *));
569 #ifdef NEED_GETTIMEOFDAY
570 extern int gettimeofday
__P((struct timeval
*, struct _TIMEZONE
*));