2 * Copyright (c) 2001 by Sun Microsystems, Inc.
6 #pragma ident "%Z%%M% %I% %E% SMI"
9 * The contents of this file are subject to the Netscape Public
10 * License Version 1.1 (the "License"); you may not use this file
11 * except in compliance with the License. You may obtain a copy of
12 * the License at http://www.mozilla.org/NPL/
14 * Software distributed under the License is distributed on an "AS
15 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
16 * implied. See the License for the specific language governing
17 * rights and limitations under the License.
19 * The Original Code is Mozilla Communicator client code, released
22 * The Initial Developer of the Original Code is Netscape
23 * Communications Corporation. Portions created by Netscape are
24 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
31 * Copyright (c) 1994 Regents of the University of Michigan.
32 * All rights reserved.
34 * Redistribution and use in source and binary forms are permitted
35 * provided that this notice is preserved and that due credit is given
36 * to the University of Michigan at Ann Arbor. The name of the University
37 * may not be used to endorse or promote products derived from this
38 * software without specific prior written permission. This software
39 * is provided ``as is'' without express or implied warranty.
46 * portable.h for LDAP -- this is where we define common stuff to make
47 * life easier on various Unix systems.
49 * Unless you are porting LDAP to a new platform, you should not need to
54 #if defined( hpux ) || defined( sunos5 ) || defined ( sgi ) || defined( SVR4 )
60 * under System V, use sysconf() instead of getdtablesize
62 #if !defined( USE_SYSCONF ) && defined( SYSV )
67 * under System V, daemons should use setsid() instead of detaching from their
70 #if !defined( USE_SETSID ) && defined( SYSV )
75 * System V has socket options in filio.h
77 #if !defined( NEED_FILIO ) && defined( SYSV ) && !defined( hpux ) && !defined( AIX )
82 * use lockf() under System V
84 #if !defined( USE_LOCKF ) && ( defined( SYSV ) || defined( aix ))
89 * on many systems, we should use waitpid() instead of waitN()
91 #if !defined( USE_WAITPID ) && ( defined( SYSV ) || defined( sunos4 ) || defined( ultrix ) || defined( aix ))
96 * define the wait status argument type
98 #if ( defined( SunOS ) && SunOS < 40 ) || defined( nextstep )
99 #define WAITSTATUSTYPE union wait
101 #define WAITSTATUSTYPE int
105 * define the flags for wait
108 #define WAIT_FLAGS ( WNOHANG | WUNTRACED | WCONTINUED )
110 #define WAIT_FLAGS ( WNOHANG | WUNTRACED )
114 * defined the options for openlog (syslog)
117 #define OPENLOG_OPTIONS LOG_PID
119 #define OPENLOG_OPTIONS ( LOG_PID | LOG_NOWAIT )
123 * some systems don't have the BSD re_comp and re_exec routines
125 #ifndef NEED_BSDREGEX
126 #if ( defined( SYSV ) || defined( VMS ) || defined( netbsd ) || defined( freebsd ) || defined( linux )) && !defined(sgi)
127 #define NEED_BSDREGEX
132 * many systems do not have the setpwfile() library routine... we just
133 * enable use for those systems we know have it.
135 #ifndef HAVE_SETPWFILE
136 #if defined( sunos4 ) || defined( ultrix ) || defined( OSF1 )
137 #define HAVE_SETPWFILE
142 * Are sys_errlist and sys_nerr declared in stdio.h?
144 #ifndef SYSERRLIST_IN_STDIO
145 #if defined( freebsd )
146 #define SYSERRLIST_IN_STDIO
152 * Is snprintf() part of the standard C runtime library?
154 #if !defined(HAVE_SNPRINTF)
155 #if defined(SOLARIS) || defined(LINUX) || defined(HPUX)
156 #define HAVE_SNPRINTF
162 * Async IO. Use a non blocking implementation of connect() and
165 #if !defined(LDAP_ASYNC_IO)
166 #if !defined(_WINDOWS) && !defined(macintosh)
167 #define LDAP_ASYNC_IO
168 #endif /* _WINDOWS */
174 #if !defined(WINSOCK) && !defined(_WINDOWS) && !defined(macintosh) && !defined(XP_OS2)
175 #if defined(hpux) || defined(LINUX) || defined(SUNOS4)
176 #include <sys/time.h>
178 #include <sys/select.h>
182 #define FD_SETSIZE 32
183 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
184 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
185 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
186 #define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
188 #endif /* !WINSOCK && !_WINDOWS && !macintosh */
192 * for connect() -- must we block signals when calling connect()? This
193 * is necessary on some buggy UNIXes.
195 #if !defined(LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED) && \
196 ( defined(AIX) || defined(IRIX) || defined(HPUX) || defined(SUNOS4) \
197 || defined(SOLARIS) || defined(OSF1) ||defined(freebsd))
198 #define LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED
203 * for signal() -- what do signal handling functions return?
207 # define SIG_FN void /* signal-catching functions return void */
210 # if (BSD >= 199006) || defined(NeXT) || defined(OSF1) || defined(sun) || defined(ultrix) || defined(apollo) || defined(POSIX_SIGNALS)
211 # define SIG_FN void /* signal-catching functions return void */
213 # define SIG_FN int /* signal-catching functions return int */
216 # define SIG_FN void /* signal-catching functions return void */
222 * toupper and tolower macros are different under bsd and sys v
224 #if defined( SYSV ) && !defined( hpux )
225 #define TOUPPER(c) (isascii(c) && islower(c) ? _toupper(c) : c)
226 #define TOLOWER(c) (isascii(c) && isupper(c) ? _tolower(c) : c)
228 #define TOUPPER(c) (isascii(c) && islower(c) ? toupper(c) : c)
229 #define TOLOWER(c) (isascii(c) && isupper(c) ? tolower(c) : c)
233 * put a cover on the tty-related ioctl calls we need to use
235 #if defined( NeXT ) || (defined(SunOS) && SunOS < 40)
236 #define TERMIO_TYPE struct sgttyb
237 #define TERMFLAG_TYPE int
238 #define GETATTR( fd, tiop ) ioctl((fd), TIOCGETP, (caddr_t)(tiop))
239 #define SETATTR( fd, tiop ) ioctl((fd), TIOCSETP, (caddr_t)(tiop))
240 #define GETFLAGS( tio ) (tio).sg_flags
241 #define SETFLAGS( tio, flags ) (tio).sg_flags = (flags)
244 #define TERMIO_TYPE struct termios
245 #define TERMFLAG_TYPE tcflag_t
246 #define GETATTR( fd, tiop ) tcgetattr((fd), (tiop))
247 #define SETATTR( fd, tiop ) tcsetattr((fd), TCSANOW /* 0 */, (tiop))
248 #define GETFLAGS( tio ) (tio).c_lflag
249 #define SETFLAGS( tio, flags ) (tio).c_lflag = (flags)
252 #if ( !defined( HPUX9 )) && ( !defined( sunos4 )) && ( !defined( SNI )) && \
253 ( !defined( HAVE_TIME_R ))
257 #if defined( sunos5 ) || defined( aix )
258 #define HAVE_GETPWNAM_R
259 #define HAVE_GETGRNAM_R
262 #if defined(SNI) || defined(LINUX1_2)
263 int strcasecmp(const char *, const char *);
265 int strncasecmp(const char *, const char *, int);
268 int strncasecmp(const char *, const char *, size_t);
269 #endif /* LINUX1_2 */
270 #endif /* SNI || LINUX1_2 */
272 #if defined(_WINDOWS) || defined(macintosh) || defined(XP_OS2)
273 #define GETHOSTBYNAME( n, r, b, l, e ) gethostbyname( n )
274 #define NSLDAPI_CTIME( c, b, l ) ctime( c )
275 #define STRTOK( s1, s2, l ) strtok( s1, s2 )
277 #if defined(sgi) || defined(HPUX9) || defined(LINUX1_2) || defined(SCOOS) || \
278 defined(UNIXWARE) || defined(SUNOS4) || defined(SNI) || defined(BSDI) || \
279 defined(NCR) || defined(OSF1) || defined(NEC) || \
280 ( defined(HPUX10) && !defined(_REENTRANT)) || defined(HPUX11) || \
281 defined(UnixWare) || defined(LINUX) || (defined(AIX) && !defined(USE_REENTRANT_LIBC))
282 #define GETHOSTBYNAME( n, r, b, l, e ) gethostbyname( n )
284 /* Maybe this is for another version of AIX?
285 Commenting out for AIX 4.1 for Nova
286 Replaced with following to lines, stolen from the #else below
287 #define GETHOSTBYNAME_BUF_T struct hostent_data
289 typedef char GETHOSTBYNAME_buf_t
[BUFSIZ
/* XXX might be too small */];
290 #define GETHOSTBYNAME_BUF_T GETHOSTBYNAME_buf_t
291 #define GETHOSTBYNAME( n, r, b, l, e ) \
292 (memset (&b, 0, l), gethostbyname_r (n, r, &b) ? NULL : r)
293 #elif defined(HPUX10)
294 #define GETHOSTBYNAME_BUF_T struct hostent_data
295 #define GETHOSTBYNAME( n, r, b, l, e ) nsldapi_compat_gethostbyname_r( n, r, (char *)&b, l, e )
297 #include <stdio.h> /* BUFSIZ */
298 typedef char GETHOSTBYNAME_buf_t
[BUFSIZ
/* XXX might be too small */];
299 #define GETHOSTBYNAME_BUF_T GETHOSTBYNAME_buf_t
300 #define GETHOSTBYNAME( n, r, b, l, e ) gethostbyname_r( n, r, b, l, e )
302 #if defined(HPUX9) || defined(LINUX1_2) || defined(LINUX2_0) || \
303 defined(LINUX2_1) || defined(SUNOS4) || defined(SNI) || \
304 defined(SCOOS) || defined(BSDI) || defined(NCR) || \
305 defined(NEC) || ( defined(HPUX10) && !defined(_REENTRANT)) || \
306 (defined(AIX) && !defined(USE_REENTRANT_LIBC))
307 #define NSLDAPI_CTIME( c, b, l ) ctime( c )
308 #elif defined(HPUX10) && defined(_REENTRANT) && !defined(HPUX11)
309 #define NSLDAPI_CTIME( c, b, l ) nsldapi_compat_ctime_r( c, b, l )
310 #elif defined( IRIX6_2 ) || defined( IRIX6_3 ) || defined(UNIXWARE) \
311 || defined(OSF1V4) || defined(AIX) || defined(UnixWare) || defined(hpux) || defined(HPUX11)
312 #define NSLDAPI_CTIME( c, b, l ) ctime_r( c, b )
313 #elif defined( OSF1V3 )
314 #define NSLDAPI_CTIME( c, b, l ) (ctime_r( c, b, l ) ? NULL : b)
316 #define NSLDAPI_CTIME( c, b, l ) ctime_r( c, b, l )
318 #if defined(hpux9) || defined(LINUX1_2) || defined(SUNOS4) || defined(SNI) || \
319 defined(SCOOS) || defined(BSDI) || defined(NCR) || \
320 defined(NEC) || defined(LINUX) || (defined(AIX) && !defined(USE_REENTRANT_LIBC))
321 #define STRTOK( s1, s2, l ) strtok( s1, s2 )
323 #define HAVE_STRTOK_R
324 char *strtok_r(char *, const char *, char **);
325 #define STRTOK( s1, s2, l ) (char *)strtok_r( s1, s2, l )
329 #if defined( ultrix ) || defined( nextstep )
330 extern char *strdup();
331 #endif /* ultrix || nextstep */
333 #if defined( sunos4 ) || defined( OSF1 )
334 #define BSD_TIME 1 /* for servers/slapd/log.h */
335 #endif /* sunos4 || osf */
337 #if !defined(_WINDOWS) && !defined(macintosh)
338 #include <netinet/in.h>
339 #include <arpa/inet.h> /* for inet_addr() */
343 * Define a portable type for IPv4 style Internet addresses (32 bits):
345 #if ( defined(sunos5) && defined(_IN_ADDR_T)) || \
346 defined(aix) || defined(HPUX11) || defined(OSF1) || defined(SOLARIS)
347 typedef in_addr_t nsldapi_in_addr_t
;
349 typedef unsigned long nsldapi_in_addr_t
;
353 #include <pcfs/pc_dir.h> /* for toupper() */
354 int fprintf(FILE *, char *, ...);
355 int fseek(FILE *, long, int);
356 int fread(char *, int, int, FILE *);
360 void *memmove(void *, const void *, size_t);
361 int strcasecmp(char *, char *);
362 int strncasecmp(char *, char *, int);
363 time_t time(time_t *);
365 int fputc(char, FILE *);
366 int fputs(char *, FILE *);
368 int socket(int, int, int);
369 void bzero(char *, int);
370 unsigned long inet_addr(char *);
371 char * inet_ntoa(struct in_addr
);
373 int connect(int, struct sockaddr
*, int);
376 /* #if defined(SUNOS4) || defined(SNI) */
378 int select(int, fd_set
*, fd_set
*, fd_set
*, struct timeval
*);
379 #endif /* SUNOS4 || SNI */
382 * SAFEMEMCPY is an overlap-safe copy from s to d of n bytes
383 * This is moved to lber.h in Solaris
387 #define SAFEMEMCPY( d, s, n ) BlockMoveData( (Ptr)s, (Ptr)d, n )
388 #else /* macintosh */
390 #define SAFEMEMCPY( d, s, n ) bcopy( s, d, n )
392 #define SAFEMEMCPY( d, s, n ) memmove( d, s, n )
394 #endif /* macintosh */
395 #endif /* ifndef _SOLARIS_SDK */
399 #define strcasecmp strcmpi
400 #define strncasecmp _strnicmp
401 #define bzero(a, b) memset( a, 0, b )
402 #define getpid _getpid
403 #define ioctl ioctlsocket
404 #define sleep(a) Sleep( a*1000 )
406 #define EMSGSIZE WSAEMSGSIZE
407 #define EWOULDBLOCK WSAEWOULDBLOCK
408 #define EHOSTUNREACH WSAEHOSTUNREACH
411 #define MAXPATHLEN _MAX_PATH
414 /* We'd like this number to be prime for the hash
415 * into the Connection table */
416 #define DS_MAX_NT_SOCKET_CONNECTIONS 2003
418 #elif defined(XP_OS2)
420 #define strcasecmp strcmpi
421 #define strncasecmp strnicmp
422 #define bzero(a, b) memset( a, 0, b )
424 #include <string.h> /*for strcmpi()*/
425 #include <time.h> /*for ctime()*/
430 #endif /* _PORTABLE_H */