#ifndef _PORTABLE_H
#define _PORTABLE_H
#ifndef SYSV
#if defined( hpux ) || defined( sunos5 ) || defined ( sgi ) || defined( SVR4 )
#define SYSV
#endif
#endif
#if !defined( USE_SYSCONF ) && defined( SYSV )
#define USE_SYSCONF
#endif
#if !defined( USE_SETSID ) && defined( SYSV )
#define USE_SETSID
#endif
#if !defined( NEED_FILIO ) && defined( SYSV ) && !defined( hpux ) && !defined( AIX )
#define NEED_FILIO
#endif
#if !defined( USE_LOCKF ) && ( defined( SYSV ) || defined( aix ))
#define USE_LOCKF
#endif
#if !defined( USE_WAITPID ) && ( defined( SYSV ) || defined( sunos4 ) || defined( ultrix ) || defined( aix ))
#define USE_WAITPID
#endif
#if ( defined( SunOS ) && SunOS < 40 ) || defined( nextstep )
#define WAITSTATUSTYPE union wait
#else
#define WAITSTATUSTYPE int
#endif
#ifdef sunos5
#define WAIT_FLAGS ( WNOHANG | WUNTRACED | WCONTINUED )
#else
#define WAIT_FLAGS ( WNOHANG | WUNTRACED )
#endif
#ifdef ultrix
#define OPENLOG_OPTIONS LOG_PID
#else
#define OPENLOG_OPTIONS ( LOG_PID | LOG_NOWAIT )
#endif
#ifndef NEED_BSDREGEX
#if ( defined( SYSV ) || defined( VMS ) || defined( netbsd ) || defined( freebsd ) || defined( linux )) && !defined(sgi)
#define NEED_BSDREGEX
#endif
#endif
#ifndef HAVE_SETPWFILE
#if defined( sunos4 ) || defined( ultrix ) || defined( OSF1 )
#define HAVE_SETPWFILE
#endif
#endif
#ifndef SYSERRLIST_IN_STDIO
#if defined( freebsd )
#define SYSERRLIST_IN_STDIO
#endif
#endif
#if !defined(HAVE_SNPRINTF)
#if defined(SOLARIS) || defined(LINUX) || defined(HPUX)
#define HAVE_SNPRINTF
#endif
#endif
#if !defined(LDAP_ASYNC_IO)
#if !defined(_WINDOWS) && !defined(macintosh)
#define LDAP_ASYNC_IO
#endif
#endif
#if !defined(WINSOCK) && !defined(_WINDOWS) && !defined(macintosh) && !defined(XP_OS2)
#if defined(hpux) || defined(LINUX) || defined(SUNOS4)
#include <sys/time.h>
#else
#include <sys/select.h>
#endif
#if !defined(FD_SET)
#define NFDBITS 32
#define FD_SETSIZE 32
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
#endif
#endif
#if !defined(LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED) && \
( defined(AIX) || defined(IRIX) || defined(HPUX) || defined(SUNOS4) \
|| defined(SOLARIS) || defined(OSF1) ||defined(freebsd))
#define LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED
#endif
#ifndef SIG_FN
#ifdef sunos5
# define SIG_FN void
#else
# ifdef BSD
# if (BSD >= 199006) || defined(NeXT) || defined(OSF1) || defined(sun) || defined(ultrix) || defined(apollo) || defined(POSIX_SIGNALS)
# define SIG_FN void
# else
# define SIG_FN int
# endif
# else
# define SIG_FN void
# endif
#endif
#endif
#if defined( SYSV ) && !defined( hpux )
#define TOUPPER(c) (isascii(c) && islower(c) ? _toupper(c) : c)
#define TOLOWER(c) (isascii(c) && isupper(c) ? _tolower(c) : c)
#else
#define TOUPPER(c) (isascii(c) && islower(c) ? toupper(c) : c)
#define TOLOWER(c) (isascii(c) && isupper(c) ? tolower(c) : c)
#endif
#if defined( NeXT ) || (defined(SunOS) && SunOS < 40)
#define TERMIO_TYPE struct sgttyb
#define TERMFLAG_TYPE int
#define GETATTR( fd, tiop ) ioctl((fd), TIOCGETP, (caddr_t)(tiop))
#define SETATTR( fd, tiop ) ioctl((fd), TIOCSETP, (caddr_t)(tiop))
#define GETFLAGS( tio ) (tio).sg_flags
#define SETFLAGS( tio, flags ) (tio).sg_flags = (flags)
#else
#define USE_TERMIOS
#define TERMIO_TYPE struct termios
#define TERMFLAG_TYPE tcflag_t
#define GETATTR( fd, tiop ) tcgetattr((fd), (tiop))
#define SETATTR( fd, tiop ) tcsetattr((fd), TCSANOW , (tiop))
#define GETFLAGS( tio ) (tio).c_lflag
#define SETFLAGS( tio, flags ) (tio).c_lflag = (flags)
#endif
#if ( !defined( HPUX9 )) && ( !defined( sunos4 )) && ( !defined( SNI )) && \
( !defined( HAVE_TIME_R ))
#define HAVE_TIME_R
#endif
#if defined( sunos5 ) || defined( aix )
#define HAVE_GETPWNAM_R
#define HAVE_GETGRNAM_R
#endif
#if defined(SNI) || defined(LINUX1_2)
int strcasecmp(const char *, const char *);
#ifdef SNI
int strncasecmp(const char *, const char *, int);
#endif
#ifdef LINUX1_2
int strncasecmp(const char *, const char *, size_t);
#endif
#endif
#if defined(_WINDOWS) || defined(macintosh) || defined(XP_OS2)
#define GETHOSTBYNAME( n, r, b, l, e ) gethostbyname( n )
#define NSLDAPI_CTIME( c, b, l ) ctime( c )
#define STRTOK( s1, s2, l ) strtok( s1, s2 )
#else
#if defined(sgi) || defined(HPUX9) || defined(LINUX1_2) || defined(SCOOS) || \
defined(UNIXWARE) || defined(SUNOS4) || defined(SNI) || defined(BSDI) || \
defined(NCR) || defined(OSF1) || defined(NEC) || \
( defined(HPUX10) && !defined(_REENTRANT)) || defined(HPUX11) || \
defined(UnixWare) || defined(LINUX) || (defined(AIX) && !defined(USE_REENTRANT_LIBC))
#define GETHOSTBYNAME( n, r, b, l, e ) gethostbyname( n )
#elif defined(AIX)
typedef char GETHOSTBYNAME_buf_t [BUFSIZ ];
#define GETHOSTBYNAME_BUF_T GETHOSTBYNAME_buf_t
#define GETHOSTBYNAME( n, r, b, l, e ) \
(memset (&b, 0, l), gethostbyname_r (n, r, &b) ? NULL : r)
#elif defined(HPUX10)
#define GETHOSTBYNAME_BUF_T struct hostent_data
#define GETHOSTBYNAME( n, r, b, l, e ) nsldapi_compat_gethostbyname_r( n, r, (char *)&b, l, e )
#else
#include <stdio.h>
typedef char GETHOSTBYNAME_buf_t [BUFSIZ ];
#define GETHOSTBYNAME_BUF_T GETHOSTBYNAME_buf_t
#define GETHOSTBYNAME( n, r, b, l, e ) gethostbyname_r( n, r, b, l, e )
#endif
#if defined(HPUX9) || defined(LINUX1_2) || defined(LINUX2_0) || \
defined(LINUX2_1) || defined(SUNOS4) || defined(SNI) || \
defined(SCOOS) || defined(BSDI) || defined(NCR) || \
defined(NEC) || ( defined(HPUX10) && !defined(_REENTRANT)) || \
(defined(AIX) && !defined(USE_REENTRANT_LIBC))
#define NSLDAPI_CTIME( c, b, l ) ctime( c )
#elif defined(HPUX10) && defined(_REENTRANT) && !defined(HPUX11)
#define NSLDAPI_CTIME( c, b, l ) nsldapi_compat_ctime_r( c, b, l )
#elif defined( IRIX6_2 ) || defined( IRIX6_3 ) || defined(UNIXWARE) \
|| defined(OSF1V4) || defined(AIX) || defined(UnixWare) || defined(hpux) || defined(HPUX11)
#define NSLDAPI_CTIME( c, b, l ) ctime_r( c, b )
#elif defined( OSF1V3 )
#define NSLDAPI_CTIME( c, b, l ) (ctime_r( c, b, l ) ? NULL : b)
#else
#define NSLDAPI_CTIME( c, b, l ) ctime_r( c, b, l )
#endif
#if defined(hpux9) || defined(LINUX1_2) || defined(SUNOS4) || defined(SNI) || \
defined(SCOOS) || defined(BSDI) || defined(NCR) || \
defined(NEC) || defined(LINUX) || (defined(AIX) && !defined(USE_REENTRANT_LIBC))
#define STRTOK( s1, s2, l ) strtok( s1, s2 )
#else
#define HAVE_STRTOK_R
char *strtok_r(char *, const char *, char **);
#define STRTOK( s1, s2, l ) (char *)strtok_r( s1, s2, l )
#endif
#endif
#if defined( ultrix ) || defined( nextstep )
extern char *strdup();
#endif
#if defined( sunos4 ) || defined( OSF1 )
#define BSD_TIME 1
#endif
#if !defined(_WINDOWS) && !defined(macintosh)
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#if ( defined(sunos5) && defined(_IN_ADDR_T)) || \
defined(aix) || defined(HPUX11) || defined(OSF1) || defined(SOLARIS)
typedef in_addr_t nsldapi_in_addr_t;
#else
typedef unsigned long nsldapi_in_addr_t;
#endif
#ifdef SUNOS4
#include <pcfs/pc_dir.h>
int fprintf(FILE *, char *, ...);
int fseek(FILE *, long, int);
int fread(char *, int, int, FILE *);
int fclose(FILE *);
int fflush(FILE *);
int rewind(FILE *);
void *memmove(void *, const void *, size_t);
int strcasecmp(char *, char *);
int strncasecmp(char *, char *, int);
time_t time(time_t *);
void perror(char *);
int fputc(char, FILE *);
int fputs(char *, FILE *);
int re_exec(char *);
int socket(int, int, int);
void bzero(char *, int);
unsigned long inet_addr(char *);
char * inet_ntoa(struct in_addr);
int getdtablesize();
int connect(int, struct sockaddr *, int);
#endif
#if defined(SUNOS4)
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
#endif
#ifndef _SOLARIS_SDK
#ifdef macintosh
#define SAFEMEMCPY( d, s, n ) BlockMoveData( (Ptr)s, (Ptr)d, n )
#else
#ifdef sunos4
#define SAFEMEMCPY( d, s, n ) bcopy( s, d, n )
#else
#define SAFEMEMCPY( d, s, n ) memmove( d, s, n )
#endif
#endif
#endif
#ifdef _WINDOWS
#define strcasecmp strcmpi
#define strncasecmp _strnicmp
#define bzero(a, b) memset( a, 0, b )
#define getpid _getpid
#define ioctl ioctlsocket
#define sleep(a) Sleep( a*1000 )
#define EMSGSIZE WSAEMSGSIZE
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EHOSTUNREACH WSAEHOSTUNREACH
#ifndef MAXPATHLEN
#define MAXPATHLEN _MAX_PATH
#endif
#define DS_MAX_NT_SOCKET_CONNECTIONS 2003
#elif defined(XP_OS2)
#define strcasecmp strcmpi
#define strncasecmp strnicmp
#define bzero(a, b) memset( a, 0, b )
#include "dirent.h"
#include <string.h>
#include <time.h>
#endif
#endif