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