xref: /onnv-gate/usr/src/lib/libldap4/include/portable.h (revision 3857:21b9b714e4ab)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  *
3*3857Sstevel  * Portions Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
4*3857Sstevel  * Use is subject to license terms.
50Sstevel@tonic-gate  *
60Sstevel@tonic-gate  */
70Sstevel@tonic-gate 
80Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
90Sstevel@tonic-gate 
100Sstevel@tonic-gate /*
110Sstevel@tonic-gate  * Copyright (c) 1994 Regents of the University of Michigan.
120Sstevel@tonic-gate  * All rights reserved.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
150Sstevel@tonic-gate  * provided that this notice is preserved and that due credit is given
160Sstevel@tonic-gate  * to the University of Michigan at Ann Arbor. The name of the University
170Sstevel@tonic-gate  * may not be used to endorse or promote products derived from this
180Sstevel@tonic-gate  * software without specific prior written permission. This software
190Sstevel@tonic-gate  * is provided ``as is'' without express or implied warranty.
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate 
220Sstevel@tonic-gate #ifndef _PORTABLE_H
230Sstevel@tonic-gate #define _PORTABLE_H
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate  * portable.h for LDAP -- this is where we define common stuff to make
270Sstevel@tonic-gate  * life easier on various Unix systems.
280Sstevel@tonic-gate  *
290Sstevel@tonic-gate  * Unless you are porting LDAP to a new platform, you should not need to
300Sstevel@tonic-gate  * edit this file.
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate 
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #ifndef SYSV
350Sstevel@tonic-gate #if defined( hpux ) || defined( sunos5 ) || defined ( sgi ) || defined( SVR4 )
360Sstevel@tonic-gate #define SYSV
370Sstevel@tonic-gate #endif
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate 
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate  * under System V, use sysconf() instead of getdtablesize
430Sstevel@tonic-gate  */
440Sstevel@tonic-gate #if !defined( USE_SYSCONF ) && defined( SYSV )
450Sstevel@tonic-gate #define USE_SYSCONF
460Sstevel@tonic-gate #endif
470Sstevel@tonic-gate 
480Sstevel@tonic-gate 
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate  * under System V, daemons should use setsid() instead of detaching from their
510Sstevel@tonic-gate  * tty themselves
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate #if !defined( USE_SETSID ) && defined( SYSV )
540Sstevel@tonic-gate #define USE_SETSID
550Sstevel@tonic-gate #endif
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate  * System V has socket options in filio.h
600Sstevel@tonic-gate  */
610Sstevel@tonic-gate #if !defined( NEED_FILIO ) && defined( SYSV ) && !defined( hpux )
620Sstevel@tonic-gate #define NEED_FILIO
630Sstevel@tonic-gate #endif
640Sstevel@tonic-gate 
650Sstevel@tonic-gate /*
660Sstevel@tonic-gate  * use lockf() under System V
670Sstevel@tonic-gate  */
680Sstevel@tonic-gate #if !defined( USE_LOCKF ) && ( defined( SYSV ) || defined( aix ))
690Sstevel@tonic-gate #define USE_LOCKF
700Sstevel@tonic-gate #endif
710Sstevel@tonic-gate 
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate  * on many systems, we should use waitpid() instead of waitN()
740Sstevel@tonic-gate  */
750Sstevel@tonic-gate #if !defined( USE_WAITPID ) && ( defined( SYSV ) || defined( sunos4 ) || defined( ultrix ) || defined( aix ))
760Sstevel@tonic-gate #define USE_WAITPID
770Sstevel@tonic-gate #endif
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 
800Sstevel@tonic-gate /*
810Sstevel@tonic-gate  * define the wait status argument type
820Sstevel@tonic-gate  */
830Sstevel@tonic-gate #if ( defined( SunOS ) && SunOS < 40 ) || defined( nextstep )
840Sstevel@tonic-gate #define WAITSTATUSTYPE	union wait
850Sstevel@tonic-gate #else
860Sstevel@tonic-gate #define WAITSTATUSTYPE	int
870Sstevel@tonic-gate #endif
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate  * define the flags for wait
910Sstevel@tonic-gate  */
920Sstevel@tonic-gate #ifdef sunos5
930Sstevel@tonic-gate #define WAIT_FLAGS	( WNOHANG | WUNTRACED | WCONTINUED )
940Sstevel@tonic-gate #else
950Sstevel@tonic-gate #define WAIT_FLAGS	( WNOHANG | WUNTRACED )
960Sstevel@tonic-gate #endif
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate  * defined the options for openlog (syslog)
1010Sstevel@tonic-gate  */
1020Sstevel@tonic-gate #ifdef ultrix
1030Sstevel@tonic-gate #define OPENLOG_OPTIONS		LOG_PID
1040Sstevel@tonic-gate #else
1050Sstevel@tonic-gate #define OPENLOG_OPTIONS		( LOG_PID | LOG_NOWAIT )
1060Sstevel@tonic-gate #endif
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate /*
1100Sstevel@tonic-gate  * some systems don't have the BSD re_comp and re_exec routines
1110Sstevel@tonic-gate  */
1120Sstevel@tonic-gate #ifndef NEED_BSDREGEX
1130Sstevel@tonic-gate #if defined( SYSV ) || defined( VMS ) || defined( netbsd ) || defined( freebsd ) || defined( linux )
1140Sstevel@tonic-gate #define NEED_BSDREGEX
1150Sstevel@tonic-gate #endif
1160Sstevel@tonic-gate #endif
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate /*
1190Sstevel@tonic-gate  * many systems do not have the setpwfile() library routine... we just
1200Sstevel@tonic-gate  * enable use for those systems we know have it.
1210Sstevel@tonic-gate  */
1220Sstevel@tonic-gate #ifndef HAVE_SETPWFILE
1230Sstevel@tonic-gate #if defined( sunos4 ) || defined( ultrix ) || defined( __osf__ )
1240Sstevel@tonic-gate #define HAVE_SETPWFILE
1250Sstevel@tonic-gate #endif
1260Sstevel@tonic-gate #endif
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate /*
1290Sstevel@tonic-gate  * Are sys_errlist and sys_nerr declared in stdio.h?
1300Sstevel@tonic-gate  */
1310Sstevel@tonic-gate #ifndef SYSERRLIST_IN_STDIO
1320Sstevel@tonic-gate #if defined( freebsd )
1330Sstevel@tonic-gate #define SYSERRLIST_IN_STDIO
1340Sstevel@tonic-gate #endif
1350Sstevel@tonic-gate #endif
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate /*
1380Sstevel@tonic-gate  * for select()
1390Sstevel@tonic-gate  */
1400Sstevel@tonic-gate #if !defined(FD_SET) && !defined(WINSOCK)
1410Sstevel@tonic-gate #define NFDBITS         32
1420Sstevel@tonic-gate #define FD_SETSIZE      32
1430Sstevel@tonic-gate #define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
1440Sstevel@tonic-gate #define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
1450Sstevel@tonic-gate #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
1460Sstevel@tonic-gate #define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
1470Sstevel@tonic-gate #endif /* FD_SET */
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate #if defined( hpux ) && defined( __STDC__ )
1500Sstevel@tonic-gate /*
1510Sstevel@tonic-gate  * Under HP/UX, select seems to want (int *) instead of fd_set.  Non-ANSI
1520Sstevel@tonic-gate  * compilers don't like recursive macros, so ignore the problem if __STDC__
1530Sstevel@tonic-gate  * is not defined.
1540Sstevel@tonic-gate  */
1550Sstevel@tonic-gate #define select(a,b,c,d,e) select(a, (int *)b, (int *)c, (int *)d, e)
1560Sstevel@tonic-gate #endif /* hpux && __STDC__ */
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate /*
1600Sstevel@tonic-gate  * for signal() -- what do signal handling functions return?
1610Sstevel@tonic-gate  */
1620Sstevel@tonic-gate #ifndef SIG_FN
1630Sstevel@tonic-gate #ifdef sunos5
1640Sstevel@tonic-gate #   define SIG_FN void          /* signal-catching functions return void */
1650Sstevel@tonic-gate #else /* sunos5 */
1660Sstevel@tonic-gate # ifdef BSD
1670Sstevel@tonic-gate #  if (BSD >= 199006) || defined(NeXT) || defined(__osf__) || defined(sun) || defined(ultrix) || defined(apollo) || defined(POSIX_SIGNALS)
1680Sstevel@tonic-gate #   define SIG_FN void          /* signal-catching functions return void */
1690Sstevel@tonic-gate #  else
1700Sstevel@tonic-gate #   define SIG_FN int           /* signal-catching functions return int */
1710Sstevel@tonic-gate #  endif
1720Sstevel@tonic-gate # else /* BSD */
1730Sstevel@tonic-gate #  define SIG_FN void           /* signal-catching functions return void */
1740Sstevel@tonic-gate # endif /* BSD */
1750Sstevel@tonic-gate #endif /* sunos5 */
1760Sstevel@tonic-gate #endif /* SIG_FN */
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate /*
1790Sstevel@tonic-gate  * call signal or sigset (signal does not block the signal while
1800Sstevel@tonic-gate  * in the handler on sys v and sigset does not exist on bsd)
1810Sstevel@tonic-gate  */
1820Sstevel@tonic-gate #ifdef SYSV
1830Sstevel@tonic-gate #define SIGNAL sigset
1840Sstevel@tonic-gate #else
1850Sstevel@tonic-gate #define SIGNAL signal
1860Sstevel@tonic-gate #endif
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate /*
1890Sstevel@tonic-gate  * toupper and tolower macros are different under bsd and sys v
1900Sstevel@tonic-gate  */
1910Sstevel@tonic-gate #if defined( SYSV ) && !defined( hpux )
1920Sstevel@tonic-gate #define TOUPPER(c)	(isascii(c) && islower(c) ? _toupper(c) : c)
1930Sstevel@tonic-gate #define TOLOWER(c)	(isascii(c) && isupper(c) ? _tolower(c) : c)
1940Sstevel@tonic-gate #else
1950Sstevel@tonic-gate #define TOUPPER(c)	(isascii(c) && islower(c) ? toupper(c) : c)
1960Sstevel@tonic-gate #define TOLOWER(c)	(isascii(c) && isupper(c) ? tolower(c) : c)
1970Sstevel@tonic-gate #endif
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate /*
2000Sstevel@tonic-gate  * put a cover on the tty-related ioctl calls we need to use
2010Sstevel@tonic-gate  */
2020Sstevel@tonic-gate #if defined( NeXT ) || (defined(SunOS) && SunOS < 40)
2030Sstevel@tonic-gate #define TERMIO_TYPE struct sgttyb
2040Sstevel@tonic-gate #define TERMFLAG_TYPE int
2050Sstevel@tonic-gate #define GETATTR( fd, tiop )	ioctl((fd), TIOCGETP, (caddr_t)(tiop))
2060Sstevel@tonic-gate #define SETATTR( fd, tiop )	ioctl((fd), TIOCSETP, (caddr_t)(tiop))
2070Sstevel@tonic-gate #define GETFLAGS( tio )		(tio).sg_flags
2080Sstevel@tonic-gate #define SETFLAGS( tio, flags )	(tio).sg_flags = (flags)
2090Sstevel@tonic-gate #else
2100Sstevel@tonic-gate #define USE_TERMIOS
2110Sstevel@tonic-gate #define TERMIO_TYPE struct termios
2120Sstevel@tonic-gate #define TERMFLAG_TYPE tcflag_t
2130Sstevel@tonic-gate #define GETATTR( fd, tiop )	tcgetattr((fd), (tiop))
2140Sstevel@tonic-gate #define SETATTR( fd, tiop )	tcsetattr((fd), TCSANOW /* 0 */, (tiop))
2150Sstevel@tonic-gate #define GETFLAGS( tio )		(tio).c_lflag
2160Sstevel@tonic-gate #define SETFLAGS( tio, flags )	(tio).c_lflag = (flags)
2170Sstevel@tonic-gate #endif
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate #if defined( ultrix ) || defined( nextstep )
2210Sstevel@tonic-gate extern char *strdup();
2220Sstevel@tonic-gate #endif /* ultrix || nextstep */
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate #endif /* _PORTABLE_H */
225