]> git.sur5r.net Git - openldap/blob - include/portable.h
Add NO_THREADS fix from tih@nhh.no
[openldap] / include / portable.h
1 /*
2  * Copyright (c) 1994 Regents of the University of Michigan.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of Michigan at Ann Arbor. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12
13 #ifndef _PORTABLE_H
14 #define _PORTABLE_H
15
16 /*
17  * portable.h for LDAP -- this is where we define common stuff to make
18  * life easier on various Unix systems.
19  *
20  * Unless you are porting LDAP to a new platform, you should not need to
21  * edit this file.
22  */
23
24
25 #ifndef SYSV
26 #if defined( hpux ) || defined( sunos5 ) || defined ( sgi ) || defined( SVR4 )
27 #define SYSV
28 #endif
29 #endif
30
31
32 /*
33  * under System V, use sysconf() instead of getdtablesize
34  */
35 #if !defined( USE_SYSCONF ) && defined( SYSV )
36 #define USE_SYSCONF
37 #endif
38
39
40 /*
41  * under System V, daemons should use setsid() instead of detaching from their
42  * tty themselves
43  */
44 #if !defined( USE_SETSID ) && defined( SYSV )
45 #define USE_SETSID
46 #endif
47
48
49 /*
50  * System V has socket options in filio.h
51  */
52 #if !defined( NEED_FILIO ) && defined( SYSV ) && !defined( hpux )
53 #define NEED_FILIO
54 #endif
55
56 /*
57  * use lockf() under System V
58  */
59 #if !defined( USE_LOCKF ) && ( defined( SYSV ) || defined( aix ))
60 #define USE_LOCKF
61 #endif
62
63 /*
64  * on most systems, we should use waitpid() instead of waitN()
65  */
66 #if !defined( USE_WAITPID ) && !defined( nextstep )
67 #define USE_WAITPID
68 #endif
69
70
71 /*
72  * define the wait status argument type
73  */
74 #if ( defined( SunOS ) && SunOS < 40 ) || defined( nextstep )
75 #define WAITSTATUSTYPE  union wait
76 #else
77 #define WAITSTATUSTYPE  int
78 #endif
79
80 /*
81  * define the flags for wait
82  */
83 #ifdef sunos5
84 #define WAIT_FLAGS      ( WNOHANG | WUNTRACED | WCONTINUED )
85 #else
86 #define WAIT_FLAGS      ( WNOHANG | WUNTRACED )
87 #endif
88
89
90 /*
91  * defined the options for openlog (syslog)
92  */
93 #ifdef ultrix
94 #define OPENLOG_OPTIONS         LOG_PID
95 #else
96 #define OPENLOG_OPTIONS         ( LOG_PID | LOG_NOWAIT )
97 #endif
98
99 /*
100  * many systems do not have the setpwfile() library routine... we just
101  * enable use for those systems we know have it.
102  */
103 #ifndef HAVE_SETPWFILE
104 #if defined( sunos4 ) || defined( ultrix ) || defined( __osf__ )
105 #define HAVE_SETPWFILE
106 #endif
107 #endif
108
109 /*
110  * Are sys_errlist and sys_nerr declared in stdio.h?
111  */
112 #ifndef SYSERRLIST_IN_STDIO
113 #if defined( freebsd ) || defined( netbsd ) || \
114         defined( __GLIBC__ ) && ( __GLIBC__ > 1 )
115 #define SYSERRLIST_IN_STDIO
116 #endif
117 #endif
118
119 /*
120  * for select()
121  */
122 #if !defined(FD_SET) && !defined(WINSOCK)
123 #define NFDBITS         32
124 #define FD_SETSIZE      32
125 #define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
126 #define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
127 #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
128 #define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
129 #endif /* FD_SET */
130
131 #if defined( hpux ) && defined( __STDC__ )
132 /*
133  * Under HP/UX, select seems to want (int *) instead of fd_set.  Non-ANSI
134  * compilers don't like recursive macros, so ignore the problem if __STDC__
135  * is not defined.
136  */
137 #define select(a,b,c,d,e) select(a, (int *)b, (int *)c, (int *)d, e)
138 #endif /* hpux && __STDC__ */
139
140
141 /*
142  * for signal() -- what do signal handling functions return?
143  */
144 #ifndef SIG_FN
145 #ifdef sunos5
146 #   define SIG_FN void          /* signal-catching functions return void */
147 #else /* sunos5 */
148 # ifdef BSD
149 #  if (BSD >= 199006) || defined(NeXT) || defined(__osf__) || defined(sun) || defined(ultrix) || defined(apollo) || defined(POSIX_SIGNALS)
150 #   define SIG_FN void          /* signal-catching functions return void */
151 #  else
152 #   define SIG_FN int           /* signal-catching functions return int */
153 #  endif
154 # else /* BSD */
155 #  define SIG_FN void           /* signal-catching functions return void */
156 # endif /* BSD */
157 #endif /* sunos5 */
158 #endif /* SIG_FN */
159
160 /*
161  * call signal or sigset (signal does not block the signal while
162  * in the handler on sys v and sigset does not exist on bsd)
163  */
164 #if defined(SYSV) && !defined(linux)
165 #define SIGNAL sigset
166 #else
167 #define SIGNAL signal
168 #endif
169
170 /*
171  * toupper and tolower macros are different under bsd and sys v
172  */
173 #if defined( SYSV ) && !defined( hpux )
174 #define TOUPPER(c)      (isascii(c) && islower(c) ? _toupper(c) : c)
175 #define TOLOWER(c)      (isascii(c) && isupper(c) ? _tolower(c) : c)
176 #else
177 #define TOUPPER(c)      (isascii(c) && islower(c) ? toupper(c) : c)
178 #define TOLOWER(c)      (isascii(c) && isupper(c) ? tolower(c) : c)
179 #endif
180
181 /*
182  * put a cover on the tty-related ioctl calls we need to use
183  */
184 #if defined( NeXT ) || (defined(SunOS) && SunOS < 40)
185 #define TERMIO_TYPE struct sgttyb
186 #define TERMFLAG_TYPE int
187 #define GETATTR( fd, tiop )     ioctl((fd), TIOCGETP, (caddr_t)(tiop))
188 #define SETATTR( fd, tiop )     ioctl((fd), TIOCSETP, (caddr_t)(tiop))
189 #define GETFLAGS( tio )         (tio).sg_flags
190 #define SETFLAGS( tio, flags )  (tio).sg_flags = (flags)
191 #else
192 #define USE_TERMIOS
193 #define TERMIO_TYPE struct termios
194 #define TERMFLAG_TYPE tcflag_t
195 #define GETATTR( fd, tiop )     tcgetattr((fd), (tiop))
196 #define SETATTR( fd, tiop )     tcsetattr((fd), TCSANOW /* 0 */, (tiop))
197 #define GETFLAGS( tio )         (tio).c_lflag
198 #define SETFLAGS( tio, flags )  (tio).c_lflag = (flags)
199 #endif
200
201
202 #if defined( ultrix ) || defined( nextstep )
203 extern char *strdup();
204 #endif /* ultrix || nextstep */
205
206 #endif /* _PORTABLE_H */