1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2001 by Sun Microsystems, Inc.
3*7c478bd9Sstevel@tonic-gate  * All rights reserved.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate 
6*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
7*7c478bd9Sstevel@tonic-gate 
8*7c478bd9Sstevel@tonic-gate /*
9*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the Netscape Public
10*7c478bd9Sstevel@tonic-gate  * License Version 1.1 (the "License"); you may not use this file
11*7c478bd9Sstevel@tonic-gate  * except in compliance with the License. You may obtain a copy of
12*7c478bd9Sstevel@tonic-gate  * the License at http://www.mozilla.org/NPL/
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * Software distributed under the License is distributed on an "AS
15*7c478bd9Sstevel@tonic-gate  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
16*7c478bd9Sstevel@tonic-gate  * implied. See the License for the specific language governing
17*7c478bd9Sstevel@tonic-gate  * rights and limitations under the License.
18*7c478bd9Sstevel@tonic-gate  *
19*7c478bd9Sstevel@tonic-gate  * The Original Code is Mozilla Communicator client code, released
20*7c478bd9Sstevel@tonic-gate  * March 31, 1998.
21*7c478bd9Sstevel@tonic-gate  *
22*7c478bd9Sstevel@tonic-gate  * The Initial Developer of the Original Code is Netscape
23*7c478bd9Sstevel@tonic-gate  * Communications Corporation. Portions created by Netscape are
24*7c478bd9Sstevel@tonic-gate  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
25*7c478bd9Sstevel@tonic-gate  * Rights Reserved.
26*7c478bd9Sstevel@tonic-gate  *
27*7c478bd9Sstevel@tonic-gate  * Contributor(s):
28*7c478bd9Sstevel@tonic-gate  */
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1994 Regents of the University of Michigan.
32*7c478bd9Sstevel@tonic-gate  * All rights reserved.
33*7c478bd9Sstevel@tonic-gate  *
34*7c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
35*7c478bd9Sstevel@tonic-gate  * provided that this notice is preserved and that due credit is given
36*7c478bd9Sstevel@tonic-gate  * to the University of Michigan at Ann Arbor. The name of the University
37*7c478bd9Sstevel@tonic-gate  * may not be used to endorse or promote products derived from this
38*7c478bd9Sstevel@tonic-gate  * software without specific prior written permission. This software
39*7c478bd9Sstevel@tonic-gate  * is provided ``as is'' without express or implied warranty.
40*7c478bd9Sstevel@tonic-gate  */
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #ifndef _PORTABLE_H
43*7c478bd9Sstevel@tonic-gate #define _PORTABLE_H
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  * portable.h for LDAP -- this is where we define common stuff to make
47*7c478bd9Sstevel@tonic-gate  * life easier on various Unix systems.
48*7c478bd9Sstevel@tonic-gate  *
49*7c478bd9Sstevel@tonic-gate  * Unless you are porting LDAP to a new platform, you should not need to
50*7c478bd9Sstevel@tonic-gate  * edit this file.
51*7c478bd9Sstevel@tonic-gate  */
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate #ifndef SYSV
54*7c478bd9Sstevel@tonic-gate #if defined( hpux ) || defined( sunos5 ) || defined ( sgi ) || defined( SVR4 )
55*7c478bd9Sstevel@tonic-gate #define SYSV
56*7c478bd9Sstevel@tonic-gate #endif
57*7c478bd9Sstevel@tonic-gate #endif
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate /*
60*7c478bd9Sstevel@tonic-gate  * under System V, use sysconf() instead of getdtablesize
61*7c478bd9Sstevel@tonic-gate  */
62*7c478bd9Sstevel@tonic-gate #if !defined( USE_SYSCONF ) && defined( SYSV )
63*7c478bd9Sstevel@tonic-gate #define USE_SYSCONF
64*7c478bd9Sstevel@tonic-gate #endif
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate /*
67*7c478bd9Sstevel@tonic-gate  * under System V, daemons should use setsid() instead of detaching from their
68*7c478bd9Sstevel@tonic-gate  * tty themselves
69*7c478bd9Sstevel@tonic-gate  */
70*7c478bd9Sstevel@tonic-gate #if !defined( USE_SETSID ) && defined( SYSV )
71*7c478bd9Sstevel@tonic-gate #define USE_SETSID
72*7c478bd9Sstevel@tonic-gate #endif
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate /*
75*7c478bd9Sstevel@tonic-gate  * System V has socket options in filio.h
76*7c478bd9Sstevel@tonic-gate  */
77*7c478bd9Sstevel@tonic-gate #if !defined( NEED_FILIO ) && defined( SYSV ) && !defined( hpux ) && !defined( AIX )
78*7c478bd9Sstevel@tonic-gate #define NEED_FILIO
79*7c478bd9Sstevel@tonic-gate #endif
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate /*
82*7c478bd9Sstevel@tonic-gate  * use lockf() under System V
83*7c478bd9Sstevel@tonic-gate  */
84*7c478bd9Sstevel@tonic-gate #if !defined( USE_LOCKF ) && ( defined( SYSV ) || defined( aix ))
85*7c478bd9Sstevel@tonic-gate #define USE_LOCKF
86*7c478bd9Sstevel@tonic-gate #endif
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate /*
89*7c478bd9Sstevel@tonic-gate  * on many systems, we should use waitpid() instead of waitN()
90*7c478bd9Sstevel@tonic-gate  */
91*7c478bd9Sstevel@tonic-gate #if !defined( USE_WAITPID ) && ( defined( SYSV ) || defined( sunos4 ) || defined( ultrix ) || defined( aix ))
92*7c478bd9Sstevel@tonic-gate #define USE_WAITPID
93*7c478bd9Sstevel@tonic-gate #endif
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate /*
96*7c478bd9Sstevel@tonic-gate  * define the wait status argument type
97*7c478bd9Sstevel@tonic-gate  */
98*7c478bd9Sstevel@tonic-gate #if ( defined( SunOS ) && SunOS < 40 ) || defined( nextstep )
99*7c478bd9Sstevel@tonic-gate #define WAITSTATUSTYPE	union wait
100*7c478bd9Sstevel@tonic-gate #else
101*7c478bd9Sstevel@tonic-gate #define WAITSTATUSTYPE	int
102*7c478bd9Sstevel@tonic-gate #endif
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate /*
105*7c478bd9Sstevel@tonic-gate  * define the flags for wait
106*7c478bd9Sstevel@tonic-gate  */
107*7c478bd9Sstevel@tonic-gate #ifdef sunos5
108*7c478bd9Sstevel@tonic-gate #define WAIT_FLAGS	( WNOHANG | WUNTRACED | WCONTINUED )
109*7c478bd9Sstevel@tonic-gate #else
110*7c478bd9Sstevel@tonic-gate #define WAIT_FLAGS	( WNOHANG | WUNTRACED )
111*7c478bd9Sstevel@tonic-gate #endif
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate /*
114*7c478bd9Sstevel@tonic-gate  * defined the options for openlog (syslog)
115*7c478bd9Sstevel@tonic-gate  */
116*7c478bd9Sstevel@tonic-gate #ifdef ultrix
117*7c478bd9Sstevel@tonic-gate #define OPENLOG_OPTIONS		LOG_PID
118*7c478bd9Sstevel@tonic-gate #else
119*7c478bd9Sstevel@tonic-gate #define OPENLOG_OPTIONS		( LOG_PID | LOG_NOWAIT )
120*7c478bd9Sstevel@tonic-gate #endif
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate /*
123*7c478bd9Sstevel@tonic-gate  * some systems don't have the BSD re_comp and re_exec routines
124*7c478bd9Sstevel@tonic-gate  */
125*7c478bd9Sstevel@tonic-gate #ifndef NEED_BSDREGEX
126*7c478bd9Sstevel@tonic-gate #if ( defined( SYSV ) || defined( VMS ) || defined( netbsd ) || defined( freebsd ) || defined( linux )) && !defined(sgi)
127*7c478bd9Sstevel@tonic-gate #define NEED_BSDREGEX
128*7c478bd9Sstevel@tonic-gate #endif
129*7c478bd9Sstevel@tonic-gate #endif
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate /*
132*7c478bd9Sstevel@tonic-gate  * many systems do not have the setpwfile() library routine... we just
133*7c478bd9Sstevel@tonic-gate  * enable use for those systems we know have it.
134*7c478bd9Sstevel@tonic-gate  */
135*7c478bd9Sstevel@tonic-gate #ifndef HAVE_SETPWFILE
136*7c478bd9Sstevel@tonic-gate #if defined( sunos4 ) || defined( ultrix ) || defined( OSF1 )
137*7c478bd9Sstevel@tonic-gate #define HAVE_SETPWFILE
138*7c478bd9Sstevel@tonic-gate #endif
139*7c478bd9Sstevel@tonic-gate #endif
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate /*
142*7c478bd9Sstevel@tonic-gate  * Are sys_errlist and sys_nerr declared in stdio.h?
143*7c478bd9Sstevel@tonic-gate  */
144*7c478bd9Sstevel@tonic-gate #ifndef SYSERRLIST_IN_STDIO
145*7c478bd9Sstevel@tonic-gate #if defined( freebsd )
146*7c478bd9Sstevel@tonic-gate #define SYSERRLIST_IN_STDIO
147*7c478bd9Sstevel@tonic-gate #endif
148*7c478bd9Sstevel@tonic-gate #endif
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate /*
152*7c478bd9Sstevel@tonic-gate  * Is snprintf() part of the standard C runtime library?
153*7c478bd9Sstevel@tonic-gate  */
154*7c478bd9Sstevel@tonic-gate #if !defined(HAVE_SNPRINTF)
155*7c478bd9Sstevel@tonic-gate #if defined(SOLARIS) || defined(LINUX) || defined(HPUX)
156*7c478bd9Sstevel@tonic-gate #define HAVE_SNPRINTF
157*7c478bd9Sstevel@tonic-gate #endif
158*7c478bd9Sstevel@tonic-gate #endif
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate /*
162*7c478bd9Sstevel@tonic-gate  * Async IO.  Use a non blocking implementation of connect() and
163*7c478bd9Sstevel@tonic-gate  * dns functions
164*7c478bd9Sstevel@tonic-gate  */
165*7c478bd9Sstevel@tonic-gate #if !defined(LDAP_ASYNC_IO)
166*7c478bd9Sstevel@tonic-gate #if !defined(_WINDOWS) && !defined(macintosh)
167*7c478bd9Sstevel@tonic-gate #define LDAP_ASYNC_IO
168*7c478bd9Sstevel@tonic-gate #endif /* _WINDOWS */
169*7c478bd9Sstevel@tonic-gate #endif
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate /*
172*7c478bd9Sstevel@tonic-gate  * for select()
173*7c478bd9Sstevel@tonic-gate  */
174*7c478bd9Sstevel@tonic-gate #if !defined(WINSOCK) && !defined(_WINDOWS) && !defined(macintosh) && !defined(XP_OS2)
175*7c478bd9Sstevel@tonic-gate #if defined(hpux) || defined(LINUX) || defined(SUNOS4)
176*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
177*7c478bd9Sstevel@tonic-gate #else
178*7c478bd9Sstevel@tonic-gate #include <sys/select.h>
179*7c478bd9Sstevel@tonic-gate #endif
180*7c478bd9Sstevel@tonic-gate #if !defined(FD_SET)
181*7c478bd9Sstevel@tonic-gate #define NFDBITS         32
182*7c478bd9Sstevel@tonic-gate #define FD_SETSIZE      32
183*7c478bd9Sstevel@tonic-gate #define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
184*7c478bd9Sstevel@tonic-gate #define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
185*7c478bd9Sstevel@tonic-gate #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
186*7c478bd9Sstevel@tonic-gate #define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
187*7c478bd9Sstevel@tonic-gate #endif /* !FD_SET */
188*7c478bd9Sstevel@tonic-gate #endif /* !WINSOCK && !_WINDOWS && !macintosh */
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate /*
192*7c478bd9Sstevel@tonic-gate  * for connect() -- must we block signals when calling connect()?  This
193*7c478bd9Sstevel@tonic-gate  * is necessary on some buggy UNIXes.
194*7c478bd9Sstevel@tonic-gate  */
195*7c478bd9Sstevel@tonic-gate #if !defined(LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED) && \
196*7c478bd9Sstevel@tonic-gate 	( defined(AIX) || defined(IRIX) || defined(HPUX) || defined(SUNOS4) \
197*7c478bd9Sstevel@tonic-gate 	|| defined(SOLARIS) || defined(OSF1) ||defined(freebsd))
198*7c478bd9Sstevel@tonic-gate #define LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED
199*7c478bd9Sstevel@tonic-gate #endif
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate /*
203*7c478bd9Sstevel@tonic-gate  * for signal() -- what do signal handling functions return?
204*7c478bd9Sstevel@tonic-gate  */
205*7c478bd9Sstevel@tonic-gate #ifndef SIG_FN
206*7c478bd9Sstevel@tonic-gate #ifdef sunos5
207*7c478bd9Sstevel@tonic-gate #   define SIG_FN void          /* signal-catching functions return void */
208*7c478bd9Sstevel@tonic-gate #else /* sunos5 */
209*7c478bd9Sstevel@tonic-gate # ifdef BSD
210*7c478bd9Sstevel@tonic-gate #  if (BSD >= 199006) || defined(NeXT) || defined(OSF1) || defined(sun) || defined(ultrix) || defined(apollo) || defined(POSIX_SIGNALS)
211*7c478bd9Sstevel@tonic-gate #   define SIG_FN void          /* signal-catching functions return void */
212*7c478bd9Sstevel@tonic-gate #  else
213*7c478bd9Sstevel@tonic-gate #   define SIG_FN int           /* signal-catching functions return int */
214*7c478bd9Sstevel@tonic-gate #  endif
215*7c478bd9Sstevel@tonic-gate # else /* BSD */
216*7c478bd9Sstevel@tonic-gate #  define SIG_FN void           /* signal-catching functions return void */
217*7c478bd9Sstevel@tonic-gate # endif /* BSD */
218*7c478bd9Sstevel@tonic-gate #endif /* sunos5 */
219*7c478bd9Sstevel@tonic-gate #endif /* SIG_FN */
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate /*
222*7c478bd9Sstevel@tonic-gate  * toupper and tolower macros are different under bsd and sys v
223*7c478bd9Sstevel@tonic-gate  */
224*7c478bd9Sstevel@tonic-gate #if defined( SYSV ) && !defined( hpux )
225*7c478bd9Sstevel@tonic-gate #define TOUPPER(c)	(isascii(c) && islower(c) ? _toupper(c) : c)
226*7c478bd9Sstevel@tonic-gate #define TOLOWER(c)	(isascii(c) && isupper(c) ? _tolower(c) : c)
227*7c478bd9Sstevel@tonic-gate #else
228*7c478bd9Sstevel@tonic-gate #define TOUPPER(c)	(isascii(c) && islower(c) ? toupper(c) : c)
229*7c478bd9Sstevel@tonic-gate #define TOLOWER(c)	(isascii(c) && isupper(c) ? tolower(c) : c)
230*7c478bd9Sstevel@tonic-gate #endif
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate /*
233*7c478bd9Sstevel@tonic-gate  * put a cover on the tty-related ioctl calls we need to use
234*7c478bd9Sstevel@tonic-gate  */
235*7c478bd9Sstevel@tonic-gate #if defined( NeXT ) || (defined(SunOS) && SunOS < 40)
236*7c478bd9Sstevel@tonic-gate #define TERMIO_TYPE struct sgttyb
237*7c478bd9Sstevel@tonic-gate #define TERMFLAG_TYPE int
238*7c478bd9Sstevel@tonic-gate #define GETATTR( fd, tiop )	ioctl((fd), TIOCGETP, (caddr_t)(tiop))
239*7c478bd9Sstevel@tonic-gate #define SETATTR( fd, tiop )	ioctl((fd), TIOCSETP, (caddr_t)(tiop))
240*7c478bd9Sstevel@tonic-gate #define GETFLAGS( tio )		(tio).sg_flags
241*7c478bd9Sstevel@tonic-gate #define SETFLAGS( tio, flags )	(tio).sg_flags = (flags)
242*7c478bd9Sstevel@tonic-gate #else
243*7c478bd9Sstevel@tonic-gate #define USE_TERMIOS
244*7c478bd9Sstevel@tonic-gate #define TERMIO_TYPE struct termios
245*7c478bd9Sstevel@tonic-gate #define TERMFLAG_TYPE tcflag_t
246*7c478bd9Sstevel@tonic-gate #define GETATTR( fd, tiop )	tcgetattr((fd), (tiop))
247*7c478bd9Sstevel@tonic-gate #define SETATTR( fd, tiop )	tcsetattr((fd), TCSANOW /* 0 */, (tiop))
248*7c478bd9Sstevel@tonic-gate #define GETFLAGS( tio )		(tio).c_lflag
249*7c478bd9Sstevel@tonic-gate #define SETFLAGS( tio, flags )	(tio).c_lflag = (flags)
250*7c478bd9Sstevel@tonic-gate #endif
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate #if ( !defined( HPUX9 )) && ( !defined( sunos4 )) && ( !defined( SNI )) && \
253*7c478bd9Sstevel@tonic-gate 	( !defined( HAVE_TIME_R ))
254*7c478bd9Sstevel@tonic-gate #define HAVE_TIME_R
255*7c478bd9Sstevel@tonic-gate #endif
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate #if defined( sunos5 ) || defined( aix )
258*7c478bd9Sstevel@tonic-gate #define HAVE_GETPWNAM_R
259*7c478bd9Sstevel@tonic-gate #define HAVE_GETGRNAM_R
260*7c478bd9Sstevel@tonic-gate #endif
261*7c478bd9Sstevel@tonic-gate 
262*7c478bd9Sstevel@tonic-gate #if defined(SNI) || defined(LINUX1_2)
263*7c478bd9Sstevel@tonic-gate int strcasecmp(const char *, const char *);
264*7c478bd9Sstevel@tonic-gate #ifdef SNI
265*7c478bd9Sstevel@tonic-gate int strncasecmp(const char *, const char *, int);
266*7c478bd9Sstevel@tonic-gate #endif /* SNI */
267*7c478bd9Sstevel@tonic-gate #ifdef LINUX1_2
268*7c478bd9Sstevel@tonic-gate int strncasecmp(const char *, const char *, size_t);
269*7c478bd9Sstevel@tonic-gate #endif /* LINUX1_2 */
270*7c478bd9Sstevel@tonic-gate #endif /* SNI || LINUX1_2 */
271*7c478bd9Sstevel@tonic-gate 
272*7c478bd9Sstevel@tonic-gate #if defined(_WINDOWS) || defined(macintosh) || defined(XP_OS2)
273*7c478bd9Sstevel@tonic-gate #define GETHOSTBYNAME( n, r, b, l, e )  gethostbyname( n )
274*7c478bd9Sstevel@tonic-gate #define NSLDAPI_CTIME( c, b, l )	ctime( c )
275*7c478bd9Sstevel@tonic-gate #define STRTOK( s1, s2, l )		strtok( s1, s2 )
276*7c478bd9Sstevel@tonic-gate #else /* UNIX */
277*7c478bd9Sstevel@tonic-gate #if defined(sgi) || defined(HPUX9) || defined(LINUX1_2) || defined(SCOOS) || \
278*7c478bd9Sstevel@tonic-gate     defined(UNIXWARE) || defined(SUNOS4) || defined(SNI) || defined(BSDI) || \
279*7c478bd9Sstevel@tonic-gate     defined(NCR) || defined(OSF1) || defined(NEC) || \
280*7c478bd9Sstevel@tonic-gate     ( defined(HPUX10) && !defined(_REENTRANT)) || defined(HPUX11) || \
281*7c478bd9Sstevel@tonic-gate     defined(UnixWare) || defined(LINUX) || (defined(AIX) && !defined(USE_REENTRANT_LIBC))
282*7c478bd9Sstevel@tonic-gate #define GETHOSTBYNAME( n, r, b, l, e )  gethostbyname( n )
283*7c478bd9Sstevel@tonic-gate #elif defined(AIX)
284*7c478bd9Sstevel@tonic-gate /* Maybe this is for another version of AIX?
285*7c478bd9Sstevel@tonic-gate    Commenting out for AIX 4.1 for Nova
286*7c478bd9Sstevel@tonic-gate    Replaced with following to lines, stolen from the #else below
287*7c478bd9Sstevel@tonic-gate #define GETHOSTBYNAME_BUF_T struct hostent_data
288*7c478bd9Sstevel@tonic-gate */
289*7c478bd9Sstevel@tonic-gate typedef char GETHOSTBYNAME_buf_t [BUFSIZ /* XXX might be too small */];
290*7c478bd9Sstevel@tonic-gate #define GETHOSTBYNAME_BUF_T GETHOSTBYNAME_buf_t
291*7c478bd9Sstevel@tonic-gate #define GETHOSTBYNAME( n, r, b, l, e ) \
292*7c478bd9Sstevel@tonic-gate 	(memset (&b, 0, l), gethostbyname_r (n, r, &b) ? NULL : r)
293*7c478bd9Sstevel@tonic-gate #elif defined(HPUX10)
294*7c478bd9Sstevel@tonic-gate #define GETHOSTBYNAME_BUF_T struct hostent_data
295*7c478bd9Sstevel@tonic-gate #define GETHOSTBYNAME( n, r, b, l, e )	nsldapi_compat_gethostbyname_r( n, r, (char *)&b, l, e )
296*7c478bd9Sstevel@tonic-gate #else
297*7c478bd9Sstevel@tonic-gate #include <stdio.h> /* BUFSIZ */
298*7c478bd9Sstevel@tonic-gate typedef char GETHOSTBYNAME_buf_t [BUFSIZ /* XXX might be too small */];
299*7c478bd9Sstevel@tonic-gate #define GETHOSTBYNAME_BUF_T GETHOSTBYNAME_buf_t
300*7c478bd9Sstevel@tonic-gate #define GETHOSTBYNAME( n, r, b, l, e )  gethostbyname_r( n, r, b, l, e )
301*7c478bd9Sstevel@tonic-gate #endif
302*7c478bd9Sstevel@tonic-gate #if defined(HPUX9) || defined(LINUX1_2) || defined(LINUX2_0) || \
303*7c478bd9Sstevel@tonic-gate     defined(LINUX2_1) || defined(SUNOS4) || defined(SNI) || \
304*7c478bd9Sstevel@tonic-gate     defined(SCOOS) || defined(BSDI) || defined(NCR) || \
305*7c478bd9Sstevel@tonic-gate     defined(NEC) || ( defined(HPUX10) && !defined(_REENTRANT)) || \
306*7c478bd9Sstevel@tonic-gate     (defined(AIX) && !defined(USE_REENTRANT_LIBC))
307*7c478bd9Sstevel@tonic-gate #define NSLDAPI_CTIME( c, b, l )	ctime( c )
308*7c478bd9Sstevel@tonic-gate #elif defined(HPUX10) && defined(_REENTRANT) && !defined(HPUX11)
309*7c478bd9Sstevel@tonic-gate #define NSLDAPI_CTIME( c, b, l )	nsldapi_compat_ctime_r( c, b, l )
310*7c478bd9Sstevel@tonic-gate #elif defined( IRIX6_2 ) || defined( IRIX6_3 ) || defined(UNIXWARE) \
311*7c478bd9Sstevel@tonic-gate 	|| defined(OSF1V4) || defined(AIX) || defined(UnixWare) || defined(hpux) || defined(HPUX11)
312*7c478bd9Sstevel@tonic-gate #define NSLDAPI_CTIME( c, b, l )        ctime_r( c, b )
313*7c478bd9Sstevel@tonic-gate #elif defined( OSF1V3 )
314*7c478bd9Sstevel@tonic-gate #define NSLDAPI_CTIME( c, b, l )	(ctime_r( c, b, l ) ? NULL : b)
315*7c478bd9Sstevel@tonic-gate #else
316*7c478bd9Sstevel@tonic-gate #define NSLDAPI_CTIME( c, b, l )	ctime_r( c, b, l )
317*7c478bd9Sstevel@tonic-gate #endif
318*7c478bd9Sstevel@tonic-gate #if defined(hpux9) || defined(LINUX1_2) || defined(SUNOS4) || defined(SNI) || \
319*7c478bd9Sstevel@tonic-gate     defined(SCOOS) || defined(BSDI) || defined(NCR) || \
320*7c478bd9Sstevel@tonic-gate     defined(NEC) || defined(LINUX) || (defined(AIX) && !defined(USE_REENTRANT_LIBC))
321*7c478bd9Sstevel@tonic-gate #define STRTOK( s1, s2, l )		strtok( s1, s2 )
322*7c478bd9Sstevel@tonic-gate #else
323*7c478bd9Sstevel@tonic-gate #define HAVE_STRTOK_R
324*7c478bd9Sstevel@tonic-gate char *strtok_r(char *, const char *, char **);
325*7c478bd9Sstevel@tonic-gate #define STRTOK( s1, s2, l )		(char *)strtok_r( s1, s2, l )
326*7c478bd9Sstevel@tonic-gate #endif /* STRTOK */
327*7c478bd9Sstevel@tonic-gate #endif /* UNIX */
328*7c478bd9Sstevel@tonic-gate 
329*7c478bd9Sstevel@tonic-gate #if defined( ultrix ) || defined( nextstep )
330*7c478bd9Sstevel@tonic-gate extern char *strdup();
331*7c478bd9Sstevel@tonic-gate #endif /* ultrix || nextstep */
332*7c478bd9Sstevel@tonic-gate 
333*7c478bd9Sstevel@tonic-gate #if defined( sunos4 ) || defined( OSF1 )
334*7c478bd9Sstevel@tonic-gate #define	BSD_TIME	1	/* for servers/slapd/log.h */
335*7c478bd9Sstevel@tonic-gate #endif /* sunos4 || osf */
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate #if !defined(_WINDOWS) && !defined(macintosh)
338*7c478bd9Sstevel@tonic-gate #include <netinet/in.h>
339*7c478bd9Sstevel@tonic-gate #include <arpa/inet.h>	/* for inet_addr() */
340*7c478bd9Sstevel@tonic-gate #endif
341*7c478bd9Sstevel@tonic-gate 
342*7c478bd9Sstevel@tonic-gate /*
343*7c478bd9Sstevel@tonic-gate  * Define a portable type for IPv4 style Internet addresses (32 bits):
344*7c478bd9Sstevel@tonic-gate  */
345*7c478bd9Sstevel@tonic-gate #if ( defined(sunos5) && defined(_IN_ADDR_T)) || \
346*7c478bd9Sstevel@tonic-gate     defined(aix) || defined(HPUX11) || defined(OSF1) || defined(SOLARIS)
347*7c478bd9Sstevel@tonic-gate typedef in_addr_t	nsldapi_in_addr_t;
348*7c478bd9Sstevel@tonic-gate #else
349*7c478bd9Sstevel@tonic-gate typedef unsigned long	nsldapi_in_addr_t;
350*7c478bd9Sstevel@tonic-gate #endif
351*7c478bd9Sstevel@tonic-gate 
352*7c478bd9Sstevel@tonic-gate #ifdef SUNOS4
353*7c478bd9Sstevel@tonic-gate #include <pcfs/pc_dir.h>	/* for toupper() */
354*7c478bd9Sstevel@tonic-gate int fprintf(FILE *, char *, ...);
355*7c478bd9Sstevel@tonic-gate int fseek(FILE *, long, int);
356*7c478bd9Sstevel@tonic-gate int fread(char *, int, int, FILE *);
357*7c478bd9Sstevel@tonic-gate int fclose(FILE *);
358*7c478bd9Sstevel@tonic-gate int fflush(FILE *);
359*7c478bd9Sstevel@tonic-gate int rewind(FILE *);
360*7c478bd9Sstevel@tonic-gate void *memmove(void *, const void *, size_t);
361*7c478bd9Sstevel@tonic-gate int strcasecmp(char *, char *);
362*7c478bd9Sstevel@tonic-gate int strncasecmp(char *, char *, int);
363*7c478bd9Sstevel@tonic-gate time_t time(time_t *);
364*7c478bd9Sstevel@tonic-gate void perror(char *);
365*7c478bd9Sstevel@tonic-gate int fputc(char, FILE *);
366*7c478bd9Sstevel@tonic-gate int fputs(char *, FILE *);
367*7c478bd9Sstevel@tonic-gate int re_exec(char *);
368*7c478bd9Sstevel@tonic-gate int socket(int, int, int);
369*7c478bd9Sstevel@tonic-gate void bzero(char *, int);
370*7c478bd9Sstevel@tonic-gate unsigned long inet_addr(char *);
371*7c478bd9Sstevel@tonic-gate char * inet_ntoa(struct in_addr);
372*7c478bd9Sstevel@tonic-gate int getdtablesize();
373*7c478bd9Sstevel@tonic-gate int connect(int, struct sockaddr *, int);
374*7c478bd9Sstevel@tonic-gate #endif /* SUNOS4 */
375*7c478bd9Sstevel@tonic-gate 
376*7c478bd9Sstevel@tonic-gate /* #if defined(SUNOS4) || defined(SNI) */
377*7c478bd9Sstevel@tonic-gate #if defined(SUNOS4)
378*7c478bd9Sstevel@tonic-gate int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
379*7c478bd9Sstevel@tonic-gate #endif /* SUNOS4 || SNI */
380*7c478bd9Sstevel@tonic-gate 
381*7c478bd9Sstevel@tonic-gate /*
382*7c478bd9Sstevel@tonic-gate  * SAFEMEMCPY is an overlap-safe copy from s to d of n bytes
383*7c478bd9Sstevel@tonic-gate  * This is moved to lber.h in Solaris
384*7c478bd9Sstevel@tonic-gate  */
385*7c478bd9Sstevel@tonic-gate #ifndef _SOLARIS_SDK
386*7c478bd9Sstevel@tonic-gate #ifdef macintosh
387*7c478bd9Sstevel@tonic-gate #define SAFEMEMCPY( d, s, n )	BlockMoveData( (Ptr)s, (Ptr)d, n )
388*7c478bd9Sstevel@tonic-gate #else /* macintosh */
389*7c478bd9Sstevel@tonic-gate #ifdef sunos4
390*7c478bd9Sstevel@tonic-gate #define SAFEMEMCPY( d, s, n )	bcopy( s, d, n )
391*7c478bd9Sstevel@tonic-gate #else /* sunos4 */
392*7c478bd9Sstevel@tonic-gate #define SAFEMEMCPY( d, s, n )	memmove( d, s, n )
393*7c478bd9Sstevel@tonic-gate #endif /* sunos4 */
394*7c478bd9Sstevel@tonic-gate #endif /* macintosh */
395*7c478bd9Sstevel@tonic-gate #endif /* ifndef _SOLARIS_SDK */
396*7c478bd9Sstevel@tonic-gate 
397*7c478bd9Sstevel@tonic-gate #ifdef _WINDOWS
398*7c478bd9Sstevel@tonic-gate 
399*7c478bd9Sstevel@tonic-gate #define strcasecmp strcmpi
400*7c478bd9Sstevel@tonic-gate #define strncasecmp _strnicmp
401*7c478bd9Sstevel@tonic-gate #define bzero(a, b) memset( a, 0, b )
402*7c478bd9Sstevel@tonic-gate #define getpid _getpid
403*7c478bd9Sstevel@tonic-gate #define ioctl ioctlsocket
404*7c478bd9Sstevel@tonic-gate #define sleep(a) Sleep( a*1000 )
405*7c478bd9Sstevel@tonic-gate 
406*7c478bd9Sstevel@tonic-gate #define EMSGSIZE WSAEMSGSIZE
407*7c478bd9Sstevel@tonic-gate #define EWOULDBLOCK WSAEWOULDBLOCK
408*7c478bd9Sstevel@tonic-gate #define EHOSTUNREACH WSAEHOSTUNREACH
409*7c478bd9Sstevel@tonic-gate 
410*7c478bd9Sstevel@tonic-gate #ifndef MAXPATHLEN
411*7c478bd9Sstevel@tonic-gate #define MAXPATHLEN _MAX_PATH
412*7c478bd9Sstevel@tonic-gate #endif
413*7c478bd9Sstevel@tonic-gate 
414*7c478bd9Sstevel@tonic-gate /* We'd like this number to be prime for the hash
415*7c478bd9Sstevel@tonic-gate  * into the Connection table */
416*7c478bd9Sstevel@tonic-gate #define DS_MAX_NT_SOCKET_CONNECTIONS 2003
417*7c478bd9Sstevel@tonic-gate 
418*7c478bd9Sstevel@tonic-gate #elif defined(XP_OS2)
419*7c478bd9Sstevel@tonic-gate 
420*7c478bd9Sstevel@tonic-gate #define strcasecmp strcmpi
421*7c478bd9Sstevel@tonic-gate #define strncasecmp strnicmp
422*7c478bd9Sstevel@tonic-gate #define bzero(a, b) memset( a, 0, b )
423*7c478bd9Sstevel@tonic-gate #include "dirent.h"
424*7c478bd9Sstevel@tonic-gate #include <string.h> /*for strcmpi()*/
425*7c478bd9Sstevel@tonic-gate #include <time.h>   /*for ctime()*/
426*7c478bd9Sstevel@tonic-gate 
427*7c478bd9Sstevel@tonic-gate #endif /* XP_OS2 */
428*7c478bd9Sstevel@tonic-gate 
429*7c478bd9Sstevel@tonic-gate 
430*7c478bd9Sstevel@tonic-gate #endif /* _PORTABLE_H */
431