Back to index

lightning-sunbird  0.9+nobinonly
portable.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Communicator client code, released
00015  * March 31, 1998.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039  * Copyright (c) 1994 Regents of the University of Michigan.
00040  * All rights reserved.
00041  *
00042  * Redistribution and use in source and binary forms are permitted
00043  * provided that this notice is preserved and that due credit is given
00044  * to the University of Michigan at Ann Arbor. The name of the University
00045  * may not be used to endorse or promote products derived from this
00046  * software without specific prior written permission. This software
00047  * is provided ``as is'' without express or implied warranty.
00048  */
00049 
00050 #ifndef _PORTABLE_H
00051 #define _PORTABLE_H
00052 
00053 /*
00054  * portable.h for LDAP -- this is where we define common stuff to make
00055  * life easier on various Unix systems.
00056  *
00057  * Unless you are porting LDAP to a new platform, you should not need to
00058  * edit this file.
00059  */
00060 
00061 #ifndef SYSV
00062 #if defined( hpux ) || defined( sunos5 ) || defined ( sgi ) || defined( SVR4 )
00063 #define SYSV
00064 #endif
00065 #endif
00066 
00067 /*
00068  * under System V, use sysconf() instead of getdtablesize
00069  */
00070 #if !defined( USE_SYSCONF ) && defined( SYSV )
00071 #define USE_SYSCONF
00072 #endif
00073 
00074 /*
00075  * under System V, daemons should use setsid() instead of detaching from their
00076  * tty themselves
00077  */
00078 #if !defined( USE_SETSID ) && defined( SYSV )
00079 #define USE_SETSID
00080 #endif
00081 
00082 /*
00083  * System V has socket options in filio.h
00084  */
00085 #if !defined( NEED_FILIO ) && defined( SYSV ) && !defined( hpux ) && !defined( AIX )
00086 #define NEED_FILIO
00087 #endif
00088 
00089 /*
00090  * use lockf() under System V
00091  */
00092 #if !defined( USE_LOCKF ) && ( defined( SYSV ) || defined( aix ))
00093 #define USE_LOCKF
00094 #endif
00095 
00096 /*
00097  * on many systems, we should use waitpid() instead of waitN()
00098  */
00099 #if !defined( USE_WAITPID ) && ( defined( SYSV ) || defined( sunos4 ) || defined( ultrix ) || defined( aix ))
00100 #define USE_WAITPID
00101 #endif
00102 
00103 /*
00104  * define the wait status argument type
00105  */
00106 #if ( defined( SunOS ) && SunOS < 40 ) || defined( nextstep )
00107 #define WAITSTATUSTYPE      union wait
00108 #else
00109 #define WAITSTATUSTYPE      int
00110 #endif
00111 
00112 /*
00113  * define the flags for wait
00114  */
00115 #ifdef sunos5
00116 #define WAIT_FLAGS   ( WNOHANG | WUNTRACED | WCONTINUED )
00117 #else
00118 #define WAIT_FLAGS   ( WNOHANG | WUNTRACED )
00119 #endif
00120 
00121 /*
00122  * defined the options for openlog (syslog)
00123  */
00124 #ifdef ultrix
00125 #define OPENLOG_OPTIONS            LOG_PID
00126 #else
00127 #define OPENLOG_OPTIONS            ( LOG_PID | LOG_NOWAIT )
00128 #endif
00129 
00130 /*
00131  * some systems don't have the BSD re_comp and re_exec routines
00132  */
00133 #ifndef NEED_BSDREGEX
00134 #if ( defined( SYSV ) || defined( NETBSD ) || defined( freebsd ) || defined( linux ) || defined( DARWIN )) && !defined(sgi)
00135 #define NEED_BSDREGEX
00136 #endif
00137 #endif
00138 
00139 /*
00140  * many systems do not have the setpwfile() library routine... we just
00141  * enable use for those systems we know have it.
00142  */
00143 #ifndef HAVE_SETPWFILE
00144 #if defined( sunos4 ) || defined( ultrix ) || defined( OSF1 )
00145 #define HAVE_SETPWFILE
00146 #endif
00147 #endif
00148 
00149 /*
00150  * Are sys_errlist and sys_nerr declared in stdio.h?
00151  */
00152 #ifndef SYSERRLIST_IN_STDIO
00153 #if defined( freebsd ) 
00154 #define SYSERRLIST_IN_STDIO
00155 #endif
00156 #endif
00157 
00158 
00159 /*
00160  * Is snprintf() part of the standard C runtime library?
00161  */
00162 #if !defined(HAVE_SNPRINTF)
00163 #if defined(SOLARIS) || defined(LINUX) || defined(HPUX)
00164 #define HAVE_SNPRINTF
00165 #endif
00166 #endif
00167 
00168 
00169 /*
00170  * Async IO.  Use a non blocking implementation of connect() and 
00171  * dns functions
00172  */
00173 #if !defined(LDAP_ASYNC_IO)
00174 #if !defined(_WINDOWS) && !defined(macintosh)
00175 #define LDAP_ASYNC_IO
00176 #endif /* _WINDOWS */
00177 #endif
00178 
00179 /*
00180  * for select()
00181  */
00182 #if !defined(WINSOCK) && !defined(_WINDOWS) && !defined(macintosh) && !defined(XP_OS2)
00183 #if defined(hpux) || defined(LINUX) || defined(SUNOS4) || defined(XP_BEOS)
00184 #include <sys/time.h>
00185 #else
00186 #include <sys/select.h>
00187 #endif
00188 #if !defined(FD_SET)
00189 #define NFDBITS         32
00190 #define FD_SETSIZE      32
00191 #define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
00192 #define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
00193 #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
00194 #define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
00195 #endif /* !FD_SET */
00196 #endif /* !WINSOCK && !_WINDOWS && !macintosh */
00197 
00198 
00199 /*
00200  * for connect() -- must we block signals when calling connect()?  This
00201  * is necessary on some buggy UNIXes.
00202  */
00203 #if !defined(LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED) && \
00204        ( defined(AIX) || defined(IRIX) || defined(HPUX) || defined(SUNOS4) \
00205        || defined(SOLARIS) || defined(OSF1) ||defined(freebsd)) 
00206 #define LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED
00207 #endif
00208 
00209 
00210 /*
00211  * for signal() -- what do signal handling functions return?
00212  */
00213 #ifndef SIG_FN
00214 #ifdef sunos5
00215 #   define SIG_FN void          /* signal-catching functions return void */
00216 #else /* sunos5 */
00217 # ifdef BSD
00218 #  if (BSD >= 199006) || defined(NeXT) || defined(OSF1) || defined(sun) || defined(ultrix) || defined(apollo) || defined(POSIX_SIGNALS)
00219 #   define SIG_FN void          /* signal-catching functions return void */
00220 #  else
00221 #   define SIG_FN int           /* signal-catching functions return int */
00222 #  endif
00223 # else /* BSD */
00224 #  define SIG_FN void           /* signal-catching functions return void */
00225 # endif /* BSD */
00226 #endif /* sunos5 */
00227 #endif /* SIG_FN */
00228 
00229 /*
00230  * toupper and tolower macros are different under bsd and sys v
00231  */
00232 #if defined( SYSV ) && !defined( hpux )
00233 #define TOUPPER(c)   (isascii(c) && islower(c) ? _toupper(c) : c)
00234 #define TOLOWER(c)   (isascii(c) && isupper(c) ? _tolower(c) : c)
00235 #else
00236 #define TOUPPER(c)   (isascii(c) && islower(c) ? toupper(c) : c)
00237 #define TOLOWER(c)   (isascii(c) && isupper(c) ? tolower(c) : c)
00238 #endif
00239 
00240 /*
00241  * put a cover on the tty-related ioctl calls we need to use
00242  */
00243 #if defined( NeXT ) || (defined(SunOS) && SunOS < 40)
00244 #define TERMIO_TYPE struct sgttyb
00245 #define TERMFLAG_TYPE int
00246 #define GETATTR( fd, tiop ) ioctl((fd), TIOCGETP, (caddr_t)(tiop))
00247 #define SETATTR( fd, tiop ) ioctl((fd), TIOCSETP, (caddr_t)(tiop))
00248 #define GETFLAGS( tio )            (tio).sg_flags
00249 #define SETFLAGS( tio, flags )     (tio).sg_flags = (flags)
00250 #else
00251 #define USE_TERMIOS
00252 #define TERMIO_TYPE struct termios
00253 #define TERMFLAG_TYPE tcflag_t
00254 #define GETATTR( fd, tiop ) tcgetattr((fd), (tiop))
00255 #define SETATTR( fd, tiop ) tcsetattr((fd), TCSANOW /* 0 */, (tiop))
00256 #define GETFLAGS( tio )            (tio).c_lflag
00257 #define SETFLAGS( tio, flags )     (tio).c_lflag = (flags)
00258 #endif
00259 
00260 #if ( !defined( HPUX9 )) && ( !defined( sunos4 )) && ( !defined( SNI )) && \
00261        ( !defined( HAVE_TIME_R ))
00262 #define HAVE_TIME_R
00263 #endif
00264 
00265 #if defined( sunos5 ) || defined( aix )
00266 #define HAVE_GETPWNAM_R
00267 #define HAVE_GETGRNAM_R
00268 #endif
00269 
00270 #if defined(SNI) || defined(LINUX1_2)
00271 int strcasecmp(const char *, const char *);
00272 #ifdef SNI
00273 int strncasecmp(const char *, const char *, int);
00274 #endif /* SNI */
00275 #ifdef LINUX1_2
00276 int strncasecmp(const char *, const char *, size_t);
00277 #endif /* LINUX1_2 */
00278 #endif /* SNI || LINUX1_2 */
00279 
00280 #if defined(_WINDOWS) || defined(macintosh) || defined(XP_OS2) || defined(DARWIN)
00281 #define GETHOSTBYNAME( n, r, b, l, e )  gethostbyname( n )
00282 #define NSLDAPI_CTIME( c, b, l )   ctime( c )
00283 #define STRTOK( s1, s2, l )        strtok( s1, s2 )
00284 #elif defined(XP_BEOS)
00285 #define GETHOSTBYNAME( n, r, b, l, e )  gethostbyname( n )
00286 #define NSLDAPI_CTIME( c, b, l )                ctime_r( c, b )
00287 #define STRTOK( s1, s2, l )        strtok_r( s1, s2, l )
00288 #define HAVE_STRTOK_R
00289 #else /* UNIX */
00290 #if defined(sgi) || defined(HPUX9) || defined(LINUX1_2) || defined(SCOOS) || \
00291     defined(UNIXWARE) || defined(SUNOS4) || defined(SNI) || defined(BSDI) || \
00292     defined(NCR) || defined(OSF1) || defined(NEC) || defined(VMS) || \
00293     ( defined(HPUX10) && !defined(_REENTRANT)) || defined(HPUX11) || \
00294     defined(UnixWare) || defined(LINUX) || defined(NETBSD) || \
00295     defined(FREEBSD) || defined(OPENBSD) || \
00296     (defined(AIX) && !defined(USE_REENTRANT_LIBC))
00297 #define GETHOSTBYNAME( n, r, b, l, e )  gethostbyname( n )
00298 #elif defined(AIX)
00299 /* Maybe this is for another version of AIX?
00300    Commenting out for AIX 4.1 for Nova
00301    Replaced with following to lines, stolen from the #else below
00302 #define GETHOSTBYNAME_BUF_T struct hostent_data
00303 */
00304 typedef char GETHOSTBYNAME_buf_t [BUFSIZ /* XXX might be too small */];
00305 #define GETHOSTBYNAME_BUF_T GETHOSTBYNAME_buf_t
00306 #define GETHOSTBYNAME( n, r, b, l, e ) \
00307        (memset (&b, 0, l), gethostbyname_r (n, r, &b) ? NULL : r)
00308 #elif defined(HPUX10)
00309 #define GETHOSTBYNAME_BUF_T struct hostent_data
00310 #define GETHOSTBYNAME( n, r, b, l, e )    nsldapi_compat_gethostbyname_r( n, r, (char *)&b, l, e )
00311 #else
00312 #include <stdio.h> /* BUFSIZ */
00313 typedef char GETHOSTBYNAME_buf_t [BUFSIZ /* XXX might be too small */];
00314 #define GETHOSTBYNAME_BUF_T GETHOSTBYNAME_buf_t
00315 #define GETHOSTBYNAME( n, r, b, l, e )  gethostbyname_r( n, r, b, l, e )
00316 #endif
00317 #if defined(HPUX9) || defined(LINUX1_2) || defined(LINUX2_0) || \
00318     defined(LINUX2_1) || defined(SUNOS4) || defined(SNI) || \
00319     defined(SCOOS) || defined(BSDI) || defined(NCR) || \
00320     defined(NEC) || ( defined(HPUX10) && !defined(_REENTRANT)) || \
00321     (defined(AIX) && !defined(USE_REENTRANT_LIBC))
00322 #define NSLDAPI_CTIME( c, b, l )   ctime( c )
00323 #elif defined(HPUX10) && defined(_REENTRANT) && !defined(HPUX11)
00324 #define NSLDAPI_CTIME( c, b, l )   nsldapi_compat_ctime_r( c, b, l )
00325 #elif defined( IRIX6_2 ) || defined( IRIX6_3 ) || defined(UNIXWARE) \
00326        || defined(OSF1V4) || defined(AIX) || defined(UnixWare) \
00327         || defined(hpux) || defined(HPUX11) || defined(NETBSD) \
00328         || defined(IRIX6) || defined(FREEBSD) || defined(VMS) \
00329         || defined(NTO) || defined(OPENBSD)
00330 #define NSLDAPI_CTIME( c, b, l )        ctime_r( c, b )
00331 #elif defined( OSF1V3 )
00332 #define NSLDAPI_CTIME( c, b, l )   (ctime_r( c, b, l ) ? NULL : b)
00333 #else
00334 #define NSLDAPI_CTIME( c, b, l )   ctime_r( c, b, l )
00335 #endif
00336 #if defined(hpux9) || defined(LINUX1_2) || defined(SUNOS4) || defined(SNI) || \
00337     defined(SCOOS) || defined(BSDI) || defined(NCR) || defined(VMS) || \
00338     defined(NEC) || defined(LINUX) || (defined(AIX) && !defined(USE_REENTRANT_LIBC))
00339 #define STRTOK( s1, s2, l )        strtok( s1, s2 )
00340 #else
00341 #define HAVE_STRTOK_R
00342 char *strtok_r(char *, const char *, char **);
00343 #define STRTOK( s1, s2, l )        (char *)strtok_r( s1, s2, l )
00344 #endif /* STRTOK */
00345 #endif /* UNIX */
00346 
00347 #if defined( ultrix ) || defined( nextstep )
00348 extern char *strdup();
00349 #endif /* ultrix || nextstep */
00350 
00351 #if defined( sunos4 ) || defined( OSF1 )
00352 #define       BSD_TIME      1      /* for servers/slapd/log.h */
00353 #endif /* sunos4 || osf */
00354 
00355 #if defined(XP_OS2)
00356 #include <machine/endian.h>   /* for htonl, et.al. */
00357 #include <arpa/inet.h>            /* for inet_addr() */
00358 #elif !defined(_WINDOWS) && !defined(macintosh)
00359 #include <netinet/in.h>
00360 #if !defined(XP_BEOS)
00361 #include <arpa/inet.h>      /* for inet_addr() */
00362 #endif
00363 #endif
00364 
00365 /*
00366  * Define a portable type for IPv4 style Internet addresses (32 bits):
00367  */
00368 #if ( defined(sunos5) && defined(_IN_ADDR_T)) || \
00369     defined(aix) || defined(HPUX11) || defined(OSF1)
00370 typedef in_addr_t    nsldapi_in_addr_t;
00371 #else
00372 typedef unsigned long       nsldapi_in_addr_t;
00373 #endif
00374 
00375 #ifdef SUNOS4
00376 #include <pcfs/pc_dir.h>    /* for toupper() */
00377 int fprintf(FILE *, char *, ...);
00378 int fseek(FILE *, long, int);
00379 int fread(char *, int, int, FILE *);
00380 int fclose(FILE *);
00381 int fflush(FILE *);
00382 int rewind(FILE *);
00383 void *memmove(void *, const void *, size_t);
00384 int strcasecmp(char *, char *);
00385 int strncasecmp(char *, char *, int);
00386 time_t time(time_t *);
00387 void perror(char *);
00388 int fputc(char, FILE *);
00389 int fputs(char *, FILE *);
00390 int re_exec(char *);
00391 int socket(int, int, int);
00392 void bzero(char *, int);
00393 unsigned long inet_addr(char *);
00394 char * inet_ntoa(struct in_addr);
00395 int getdtablesize();
00396 int connect(int, struct sockaddr *, int);
00397 #endif /* SUNOS4 */
00398 
00399 /* #if defined(SUNOS4) || defined(SNI) */
00400 #if defined(SUNOS4)
00401 int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
00402 #endif /* SUNOS4 || SNI */
00403 
00404 /*
00405  * SAFEMEMCPY is an overlap-safe copy from s to d of n bytes
00406  */
00407 #ifdef macintosh
00408 #define SAFEMEMCPY( d, s, n )      BlockMoveData( (Ptr)s, (Ptr)d, n )
00409 #else /* macintosh */
00410 #ifdef sunos4
00411 #define SAFEMEMCPY( d, s, n )      bcopy( s, d, n )
00412 #else /* sunos4 */
00413 #define SAFEMEMCPY( d, s, n )      memmove( d, s, n )
00414 #endif /* sunos4 */
00415 #endif /* macintosh */
00416 
00417 #ifdef _WINDOWS
00418 
00419 #define strcasecmp strcmpi
00420 #define strncasecmp _strnicmp
00421 #define bzero(a, b) memset( a, 0, b )
00422 #define getpid _getpid
00423 #define ioctl ioctlsocket
00424 #define sleep(a) Sleep( a*1000 )
00425 
00426 #define EMSGSIZE WSAEMSGSIZE
00427 #define EWOULDBLOCK WSAEWOULDBLOCK
00428 #define EHOSTUNREACH WSAEHOSTUNREACH
00429 
00430 #ifndef MAXPATHLEN
00431 #define MAXPATHLEN _MAX_PATH
00432 #endif
00433 
00434 /* We'd like this number to be prime for the hash
00435  * into the Connection table */
00436 #define DS_MAX_NT_SOCKET_CONNECTIONS 2003
00437 
00438 #elif defined(XP_OS2)
00439 
00440 #define strcasecmp stricmp
00441 #define strncasecmp strnicmp
00442 #define bzero(a, b) memset( a, 0, b )
00443 #include <string.h> /*for strcmpi()*/
00444 #include <time.h>   /*for ctime()*/
00445 
00446 #endif /* XP_OS2 */
00447 
00448 
00449 #endif /* _PORTABLE_H */