1 /* 2 * Copyright (c) 2001 by Sun Microsystems, Inc. 3 * All rights reserved. 4 */ 5 6 #pragma ident "%Z%%M% %I% %E% SMI" 7 8 /* 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/ 13 * 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. 18 * 19 * The Original Code is Mozilla Communicator client code, released 20 * March 31, 1998. 21 * 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 25 * Rights Reserved. 26 * 27 * Contributor(s): 28 */ 29 30 /* 31 * Copyright (c) 1994 Regents of the University of Michigan. 32 * All rights reserved. 33 * 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. 40 */ 41 42 #ifndef _PORTABLE_H 43 #define _PORTABLE_H 44 45 /* 46 * portable.h for LDAP -- this is where we define common stuff to make 47 * life easier on various Unix systems. 48 * 49 * Unless you are porting LDAP to a new platform, you should not need to 50 * edit this file. 51 */ 52 53 #ifndef SYSV 54 #if defined( hpux ) || defined( sunos5 ) || defined ( sgi ) || defined( SVR4 ) 55 #define SYSV 56 #endif 57 #endif 58 59 /* 60 * under System V, use sysconf() instead of getdtablesize 61 */ 62 #if !defined( USE_SYSCONF ) && defined( SYSV ) 63 #define USE_SYSCONF 64 #endif 65 66 /* 67 * under System V, daemons should use setsid() instead of detaching from their 68 * tty themselves 69 */ 70 #if !defined( USE_SETSID ) && defined( SYSV ) 71 #define USE_SETSID 72 #endif 73 74 /* 75 * System V has socket options in filio.h 76 */ 77 #if !defined( NEED_FILIO ) && defined( SYSV ) && !defined( hpux ) && !defined( AIX ) 78 #define NEED_FILIO 79 #endif 80 81 /* 82 * use lockf() under System V 83 */ 84 #if !defined( USE_LOCKF ) && ( defined( SYSV ) || defined( aix )) 85 #define USE_LOCKF 86 #endif 87 88 /* 89 * on many systems, we should use waitpid() instead of waitN() 90 */ 91 #if !defined( USE_WAITPID ) && ( defined( SYSV ) || defined( sunos4 ) || defined( ultrix ) || defined( aix )) 92 #define USE_WAITPID 93 #endif 94 95 /* 96 * define the wait status argument type 97 */ 98 #if ( defined( SunOS ) && SunOS < 40 ) || defined( nextstep ) 99 #define WAITSTATUSTYPE union wait 100 #else 101 #define WAITSTATUSTYPE int 102 #endif 103 104 /* 105 * define the flags for wait 106 */ 107 #ifdef sunos5 108 #define WAIT_FLAGS ( WNOHANG | WUNTRACED | WCONTINUED ) 109 #else 110 #define WAIT_FLAGS ( WNOHANG | WUNTRACED ) 111 #endif 112 113 /* 114 * defined the options for openlog (syslog) 115 */ 116 #ifdef ultrix 117 #define OPENLOG_OPTIONS LOG_PID 118 #else 119 #define OPENLOG_OPTIONS ( LOG_PID | LOG_NOWAIT ) 120 #endif 121 122 /* 123 * some systems don't have the BSD re_comp and re_exec routines 124 */ 125 #ifndef NEED_BSDREGEX 126 #if ( defined( SYSV ) || defined( VMS ) || defined( netbsd ) || defined( freebsd ) || defined( linux )) && !defined(sgi) 127 #define NEED_BSDREGEX 128 #endif 129 #endif 130 131 /* 132 * many systems do not have the setpwfile() library routine... we just 133 * enable use for those systems we know have it. 134 */ 135 #ifndef HAVE_SETPWFILE 136 #if defined( sunos4 ) || defined( ultrix ) || defined( OSF1 ) 137 #define HAVE_SETPWFILE 138 #endif 139 #endif 140 141 /* 142 * Are sys_errlist and sys_nerr declared in stdio.h? 143 */ 144 #ifndef SYSERRLIST_IN_STDIO 145 #if defined( freebsd ) 146 #define SYSERRLIST_IN_STDIO 147 #endif 148 #endif 149 150 151 /* 152 * Is snprintf() part of the standard C runtime library? 153 */ 154 #if !defined(HAVE_SNPRINTF) 155 #if defined(SOLARIS) || defined(LINUX) || defined(HPUX) 156 #define HAVE_SNPRINTF 157 #endif 158 #endif 159 160 161 /* 162 * Async IO. Use a non blocking implementation of connect() and 163 * dns functions 164 */ 165 #if !defined(LDAP_ASYNC_IO) 166 #if !defined(_WINDOWS) && !defined(macintosh) 167 #define LDAP_ASYNC_IO 168 #endif /* _WINDOWS */ 169 #endif 170 171 /* 172 * for select() 173 */ 174 #if !defined(WINSOCK) && !defined(_WINDOWS) && !defined(macintosh) && !defined(XP_OS2) 175 #if defined(hpux) || defined(LINUX) || defined(SUNOS4) 176 #include <sys/time.h> 177 #else 178 #include <sys/select.h> 179 #endif 180 #if !defined(FD_SET) 181 #define NFDBITS 32 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))) 187 #endif /* !FD_SET */ 188 #endif /* !WINSOCK && !_WINDOWS && !macintosh */ 189 190 191 /* 192 * for connect() -- must we block signals when calling connect()? This 193 * is necessary on some buggy UNIXes. 194 */ 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 199 #endif 200 201 202 /* 203 * for signal() -- what do signal handling functions return? 204 */ 205 #ifndef SIG_FN 206 #ifdef sunos5 207 # define SIG_FN void /* signal-catching functions return void */ 208 #else /* sunos5 */ 209 # ifdef BSD 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 */ 212 # else 213 # define SIG_FN int /* signal-catching functions return int */ 214 # endif 215 # else /* BSD */ 216 # define SIG_FN void /* signal-catching functions return void */ 217 # endif /* BSD */ 218 #endif /* sunos5 */ 219 #endif /* SIG_FN */ 220 221 /* 222 * toupper and tolower macros are different under bsd and sys v 223 */ 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) 227 #else 228 #define TOUPPER(c) (isascii(c) && islower(c) ? toupper(c) : c) 229 #define TOLOWER(c) (isascii(c) && isupper(c) ? tolower(c) : c) 230 #endif 231 232 /* 233 * put a cover on the tty-related ioctl calls we need to use 234 */ 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) 242 #else 243 #define USE_TERMIOS 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) 250 #endif 251 252 #if ( !defined( HPUX9 )) && ( !defined( sunos4 )) && ( !defined( SNI )) && \ 253 ( !defined( HAVE_TIME_R )) 254 #define HAVE_TIME_R 255 #endif 256 257 #if defined( sunos5 ) || defined( aix ) 258 #define HAVE_GETPWNAM_R 259 #define HAVE_GETGRNAM_R 260 #endif 261 262 #if defined(SNI) || defined(LINUX1_2) 263 int strcasecmp(const char *, const char *); 264 #ifdef SNI 265 int strncasecmp(const char *, const char *, int); 266 #endif /* SNI */ 267 #ifdef LINUX1_2 268 int strncasecmp(const char *, const char *, size_t); 269 #endif /* LINUX1_2 */ 270 #endif /* SNI || LINUX1_2 */ 271 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 ) 276 #else /* UNIX */ 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 ) 283 #elif defined(AIX) 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 288 */ 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 ) 296 #else 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 ) 301 #endif 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) 315 #else 316 #define NSLDAPI_CTIME( c, b, l ) ctime_r( c, b, l ) 317 #endif 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 ) 322 #else 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 ) 326 #endif /* STRTOK */ 327 #endif /* UNIX */ 328 329 #if defined( ultrix ) || defined( nextstep ) 330 extern char *strdup(); 331 #endif /* ultrix || nextstep */ 332 333 #if defined( sunos4 ) || defined( OSF1 ) 334 #define BSD_TIME 1 /* for servers/slapd/log.h */ 335 #endif /* sunos4 || osf */ 336 337 #if !defined(_WINDOWS) && !defined(macintosh) 338 #include <netinet/in.h> 339 #include <arpa/inet.h> /* for inet_addr() */ 340 #endif 341 342 /* 343 * Define a portable type for IPv4 style Internet addresses (32 bits): 344 */ 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; 348 #else 349 typedef unsigned long nsldapi_in_addr_t; 350 #endif 351 352 #ifdef SUNOS4 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 *); 357 int fclose(FILE *); 358 int fflush(FILE *); 359 int rewind(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 *); 364 void perror(char *); 365 int fputc(char, FILE *); 366 int fputs(char *, FILE *); 367 int re_exec(char *); 368 int socket(int, int, int); 369 void bzero(char *, int); 370 unsigned long inet_addr(char *); 371 char * inet_ntoa(struct in_addr); 372 int getdtablesize(); 373 int connect(int, struct sockaddr *, int); 374 #endif /* SUNOS4 */ 375 376 /* #if defined(SUNOS4) || defined(SNI) */ 377 #if defined(SUNOS4) 378 int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); 379 #endif /* SUNOS4 || SNI */ 380 381 /* 382 * SAFEMEMCPY is an overlap-safe copy from s to d of n bytes 383 * This is moved to lber.h in Solaris 384 */ 385 #ifndef _SOLARIS_SDK 386 #ifdef macintosh 387 #define SAFEMEMCPY( d, s, n ) BlockMoveData( (Ptr)s, (Ptr)d, n ) 388 #else /* macintosh */ 389 #ifdef sunos4 390 #define SAFEMEMCPY( d, s, n ) bcopy( s, d, n ) 391 #else /* sunos4 */ 392 #define SAFEMEMCPY( d, s, n ) memmove( d, s, n ) 393 #endif /* sunos4 */ 394 #endif /* macintosh */ 395 #endif /* ifndef _SOLARIS_SDK */ 396 397 #ifdef _WINDOWS 398 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 ) 405 406 #define EMSGSIZE WSAEMSGSIZE 407 #define EWOULDBLOCK WSAEWOULDBLOCK 408 #define EHOSTUNREACH WSAEHOSTUNREACH 409 410 #ifndef MAXPATHLEN 411 #define MAXPATHLEN _MAX_PATH 412 #endif 413 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 417 418 #elif defined(XP_OS2) 419 420 #define strcasecmp strcmpi 421 #define strncasecmp strnicmp 422 #define bzero(a, b) memset( a, 0, b ) 423 #include "dirent.h" 424 #include <string.h> /*for strcmpi()*/ 425 #include <time.h> /*for ctime()*/ 426 427 #endif /* XP_OS2 */ 428 429 430 #endif /* _PORTABLE_H */ 431