portable.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /*
  42. * Copyright (c) 1994 Regents of the University of Michigan.
  43. * All rights reserved.
  44. *
  45. * Redistribution and use in source and binary forms are permitted
  46. * provided that this notice is preserved and that due credit is given
  47. * to the University of Michigan at Ann Arbor. The name of the University
  48. * may not be used to endorse or promote products derived from this
  49. * software without specific prior written permission. This software
  50. * is provided ``as is'' without express or implied warranty.
  51. */
  52. #ifndef _PORTABLE_H
  53. #define _PORTABLE_H
  54. /*
  55. * portable.h for LDAP -- this is where we define common stuff to make
  56. * life easier on various Unix systems.
  57. *
  58. * Unless you are porting LDAP to a new platform, you should not need to
  59. * edit this file.
  60. */
  61. #ifndef SYSV
  62. #if defined( hpux ) || defined( sunos5 ) || defined ( sgi ) || defined( SVR4 )
  63. #define SYSV
  64. #endif
  65. #endif
  66. /*
  67. * under System V, use sysconf() instead of getdtablesize
  68. */
  69. #if !defined( USE_SYSCONF ) && defined( SYSV )
  70. #define USE_SYSCONF
  71. #endif
  72. /*
  73. * under System V, daemons should use setsid() instead of detaching from their
  74. * tty themselves
  75. */
  76. #if !defined( USE_SETSID ) && defined( SYSV )
  77. #define USE_SETSID
  78. #endif
  79. /*
  80. * System V has socket options in filio.h
  81. */
  82. #if !defined( NEED_FILIO ) && defined( SYSV ) && !defined( hpux ) && !defined( AIX )
  83. #define NEED_FILIO
  84. #endif
  85. /*
  86. * use lockf() under System V
  87. */
  88. #if !defined( USE_LOCKF ) && ( defined( SYSV ) || defined( aix ))
  89. #define USE_LOCKF
  90. #endif
  91. /*
  92. * on many systems, we should use waitpid() instead of waitN()
  93. */
  94. #if !defined( USE_WAITPID ) && ( defined( SYSV ) || defined( sunos4 ) || defined( ultrix ) || defined( aix ))
  95. #define USE_WAITPID
  96. #endif
  97. /*
  98. * define the wait status argument type
  99. */
  100. #if ( defined( SunOS ) && SunOS < 40 ) || defined( nextstep )
  101. #define WAITSTATUSTYPE union wait
  102. #else
  103. #define WAITSTATUSTYPE int
  104. #endif
  105. /*
  106. * define the flags for wait
  107. */
  108. #ifdef sunos5
  109. #define WAIT_FLAGS ( WNOHANG | WUNTRACED | WCONTINUED )
  110. #else
  111. #define WAIT_FLAGS ( WNOHANG | WUNTRACED )
  112. #endif
  113. /*
  114. * defined the options for openlog (syslog)
  115. */
  116. #ifdef ultrix
  117. #define OPENLOG_OPTIONS LOG_PID
  118. #else
  119. #define OPENLOG_OPTIONS ( LOG_PID | LOG_NOWAIT )
  120. #endif
  121. /*
  122. * We use the internal regex on all systems now.
  123. */
  124. #ifndef NEED_BSDREGEX
  125. #define NEED_BSDREGEX
  126. #endif
  127. /*
  128. * many systems do not have the setpwfile() library routine... we just
  129. * enable use for those systems we know have it.
  130. */
  131. #ifndef HAVE_SETPWFILE
  132. #if defined( sunos4 ) || defined( ultrix ) || defined( OSF1 )
  133. #define HAVE_SETPWFILE
  134. #endif
  135. #endif
  136. /*
  137. * Are sys_errlist and sys_nerr declared in stdio.h?
  138. */
  139. #ifndef SYSERRLIST_IN_STDIO
  140. #if defined( freebsd ) || defined(Linux)
  141. #define SYSERRLIST_IN_STDIO
  142. #endif
  143. #endif
  144. /*
  145. * for select()
  146. */
  147. #if !defined(WINSOCK) && !defined(_WINDOWS) && !defined(macintosh)
  148. #if defined(hpux) || defined(LINUX2_0)
  149. #include <sys/time.h>
  150. #else
  151. #include <sys/select.h>
  152. #endif
  153. #if !defined(FD_SET)
  154. #define NFDBITS 32
  155. #define FD_SETSIZE 32
  156. #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  157. #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  158. #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  159. #define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
  160. #endif /* !FD_SET */
  161. #endif /* !WINSOCK && !_WINDOWS && !macintosh */
  162. /*
  163. * for connect() -- must we block signals when calling connect()? This
  164. * is necessary on some buggy UNIXes.
  165. */
  166. #if !defined(LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED) && \
  167. ( defined(AIX) || defined(IRIX) || defined(HPUX) || defined(SUNOS4))
  168. #define LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED
  169. #endif
  170. /*
  171. * Some DNS resolver implementations, such as the one built into
  172. * Solaris <= 8, need to use one or more low numbered file
  173. * descriptors internally (probably because they use a deficient
  174. * implementation of stdio).
  175. */
  176. #if defined(SOLARIS) || defined(IRIX)
  177. #define RESOLVER_NEEDS_LOW_FILE_DESCRIPTORS
  178. #endif
  179. /*
  180. * for signal() -- what do signal handling functions return?
  181. */
  182. #ifndef SIG_FN
  183. #ifdef sunos5
  184. # define SIG_FN void /* signal-catching functions return void */
  185. #else /* sunos5 */
  186. # ifdef BSD
  187. # if (BSD >= 199006) || defined(NeXT) || defined(OSF1) || defined(sun) || defined(ultrix) || defined(apollo) || defined(POSIX_SIGNALS)
  188. # define SIG_FN void /* signal-catching functions return void */
  189. # else
  190. # define SIG_FN int /* signal-catching functions return int */
  191. # endif
  192. # else /* BSD */
  193. # define SIG_FN void /* signal-catching functions return void */
  194. # endif /* BSD */
  195. #endif /* sunos5 */
  196. #endif /* SIG_FN */
  197. /*
  198. * toupper and tolower macros are different under bsd and sys v
  199. */
  200. #if defined( SYSV ) && !defined( hpux )
  201. #define TOUPPER(c) (isascii(c) && islower(c) ? _toupper(c) : c)
  202. #define TOLOWER(c) (isascii(c) && isupper(c) ? _tolower(c) : c)
  203. #else
  204. #define TOUPPER(c) (isascii(c) && islower(c) ? toupper(c) : c)
  205. #define TOLOWER(c) (isascii(c) && isupper(c) ? tolower(c) : c)
  206. #endif
  207. /*
  208. * put a cover on the tty-related ioctl calls we need to use
  209. */
  210. #if defined( NeXT ) || (defined(SunOS) && SunOS < 40)
  211. #define TERMIO_TYPE struct sgttyb
  212. #define TERMFLAG_TYPE int
  213. #define GETATTR( fd, tiop ) ioctl((fd), TIOCGETP, (caddr_t)(tiop))
  214. #define SETATTR( fd, tiop ) ioctl((fd), TIOCSETP, (caddr_t)(tiop))
  215. #define GETFLAGS( tio ) (tio).sg_flags
  216. #define SETFLAGS( tio, flags ) (tio).sg_flags = (flags)
  217. #else
  218. #define USE_TERMIOS
  219. #define TERMIO_TYPE struct termios
  220. #define TERMFLAG_TYPE tcflag_t
  221. #define GETATTR( fd, tiop ) tcgetattr((fd), (tiop))
  222. #define SETATTR( fd, tiop ) tcsetattr((fd), TCSANOW /* 0 */, (tiop))
  223. #define GETFLAGS( tio ) (tio).c_lflag
  224. #define SETFLAGS( tio, flags ) (tio).c_lflag = (flags)
  225. #endif
  226. #if ( !defined( HPUX9 )) && ( !defined( sunos4 )) && ( !defined( SNI )) && \
  227. ( !defined( HAVE_TIME_R ) )
  228. #define HAVE_TIME_R
  229. #endif
  230. #if defined( sunos5 ) || defined( aix )
  231. #define HAVE_GETPWNAM_R
  232. #define HAVE_GETGRNAM_R
  233. #endif
  234. #if defined(SNI) || defined(LINUX1_2)
  235. int strcasecmp(const char *, const char *);
  236. #ifdef SNI
  237. int strncasecmp(const char *, const char *, int);
  238. #endif /* SNI */
  239. #ifdef LINUX1_2
  240. int strncasecmp(const char *, const char *, size_t);
  241. #endif /* LINUX1_2 */
  242. #endif /* SNI || LINUX1_2 */
  243. #if defined(_WINDOWS) || defined(macintosh)
  244. #define GETHOSTBYNAME( n, r, b, l, e ) gethostbyname( n )
  245. #define CTIME( c, b, l ) ctime( c )
  246. #define STRTOK( s1, s2, l ) strtok( s1, s2 )
  247. #else /* UNIX */
  248. #if defined(sgi) || defined(HPUX9) || defined(LINUX1_2) || defined(SCOOS) || \
  249. defined(UNIXWARE) || defined(SUNOS4) || defined(SNI) || defined(BSDI) || \
  250. defined(NCR) || defined(OSF1) || defined(NEC) || \
  251. ( defined(HPUX10) && !defined(_REENTRANT)) || defined(HPUX11) || \
  252. defined(UnixWare) || defined(LINUX2_0)
  253. #define GETHOSTBYNAME( n, r, b, l, e ) gethostbyname( n )
  254. #elif defined(AIX)
  255. #define GETHOSTBYNAME_BUF_T struct hostent_data
  256. #define GETHOSTBYNAME( n, r, b, l, e ) \
  257. (memset (&b, 0, l), gethostbyname_r (n, r, &b) ? NULL : r)
  258. #elif defined(HPUX10)
  259. #define GETHOSTBYNAME_BUF_T struct hostent_data
  260. #define GETHOSTBYNAME( n, r, b, l, e ) nsldapi_compat_gethostbyname_r( n, r, (char *)&b, l, e )
  261. #else
  262. #include <stdio.h> /* BUFSIZ */
  263. typedef char GETHOSTBYNAME_buf_t [BUFSIZ /* XXX might be too small */];
  264. #define GETHOSTBYNAME_BUF_T GETHOSTBYNAME_buf_t
  265. #define GETHOSTBYNAME( n, r, b, l, e ) gethostbyname_r( n, r, b, l, e )
  266. #endif
  267. /*
  268. * XXXmcs: GETHOSTBYADDR() is only defined for IRIX/SGI and Solaris for now.
  269. */
  270. #if defined(sgi)
  271. #define GETHOSTBYADDR( a, al, t, h, b, bl, e ) \
  272. gethostbyaddr( a, al, t )
  273. #elif defined(SOLARIS)
  274. #include <stdio.h> /* BUFSIZ */
  275. typedef char GETHOSTBYADDR_buf_t [BUFSIZ];
  276. #define GETHOSTBYADDR_BUF_T GETHOSTBYADDR_buf_t
  277. #define GETHOSTBYADDR( a, al, t, h, b, bl, e ) \
  278. gethostbyaddr_r( a, al, t, h, b, bl, e )
  279. #endif
  280. #if defined(HPUX9) || defined(LINUX1_2) || defined(SUNOS4) || defined(SNI) || \
  281. defined(SCOOS) || defined(BSDI) || defined(NCR) || \
  282. defined(NEC) || ( defined(HPUX10) && !defined(_REENTRANT))
  283. #define CTIME( c, b, l ) ctime( c )
  284. #elif defined( hpux10 )
  285. #define CTIME( c, b, l ) nsldapi_compat_ctime_r( c, b, l )
  286. #elif defined( IRIX ) || defined(UNIXWARE) || defined(LINUX) \
  287. || defined(OSF1V4) || defined(AIX) || defined(UnixWare) || defined (HPUX11)
  288. #define CTIME( c, b, l ) ctime_r( c, b )
  289. #elif defined( OSF1V3 )
  290. #define CTIME( c, b, l ) (ctime_r( c, b, l ) ? NULL : b)
  291. #else
  292. #define CTIME( c, b, l ) ctime_r( c, b, l )
  293. #endif
  294. #if defined(hpux9) || defined(LINUX1_2) || defined(SUNOS4) || defined(SNI) || \
  295. defined(SCOOS) || defined(BSDI) || defined(NCR) || \
  296. defined(NEC) || defined(LINUX2_0)
  297. /* strtok() is not MT safe, but it is okay to call here because used in mmt_protocol.xs which
  298. has been moved in the tetframewrok */
  299. #define STRTOK( s1, s2, l ) strtok( s1, s2 )
  300. #else
  301. #define HAVE_STRTOK_R
  302. char *strtok_r(char *, const char *, char **);
  303. #define STRTOK( s1, s2, l ) (char *)strtok_r( s1, s2, l )
  304. #endif /* STRTOK */
  305. #endif /* UNIX */
  306. #if defined( ultrix ) || defined( nextstep )
  307. extern char *strdup();
  308. #endif /* ultrix || nextstep */
  309. #if defined( sunos4 ) || defined( OSF1 )
  310. #define BSD_TIME 1 /* for servers/slapd/log.h */
  311. #endif /* sunos4 || osf */
  312. #ifdef SOLARIS
  313. #include <netinet/in.h>
  314. #include <arpa/inet.h> /* for inet_addr() */
  315. #endif /* SOLARIS */
  316. #ifdef SUNOS4
  317. #include <pcfs/pc_dir.h> /* for toupper() */
  318. int fprintf(FILE *, char *, ...);
  319. int fseek(FILE *, long, int);
  320. int fread(char *, int, int, FILE *);
  321. int fclose(FILE *);
  322. int fflush(FILE *);
  323. int rewind(FILE *);
  324. void *memmove(void *, const void *, size_t);
  325. int strcasecmp(char *, char *);
  326. int strncasecmp(char *, char *, int);
  327. time_t time(time_t *);
  328. void perror(char *);
  329. int fputc(char, FILE *);
  330. int fputs(char *, FILE *);
  331. int LDAP_CALL re_exec(char *);
  332. int socket(int, int, int);
  333. void bzero(char *, int);
  334. unsigned long inet_addr(char *);
  335. char * inet_ntoa(struct in_addr);
  336. int getdtablesize();
  337. int connect(int, struct sockaddr *, int);
  338. #endif /* SUNOS4 */
  339. /* #if defined(SUNOS4) || defined(SNI) */
  340. #if defined(SUNOS4)
  341. int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
  342. #endif /* SUNOS4 || SNI */
  343. /*
  344. * SAFEMEMCPY is an overlap-safe copy from s to d of n bytes
  345. */
  346. #ifdef macintosh
  347. #define SAFEMEMCPY( d, s, n ) BlockMoveData( (Ptr)s, (Ptr)d, n )
  348. #else /* macintosh */
  349. #ifdef sunos4
  350. #define SAFEMEMCPY( d, s, n ) bcopy( s, d, n )
  351. #else /* sunos4 */
  352. #define SAFEMEMCPY( d, s, n ) memmove( d, s, n )
  353. #endif /* sunos4 */
  354. #endif /* macintosh */
  355. #ifdef _WINDOWS
  356. #undef strcasecmp
  357. #define strcasecmp strcmpi
  358. #undef strncasecmp
  359. #define strncasecmp _strnicmp
  360. #define bzero(a, b) memset( a, 0, b )
  361. #define getpid _getpid
  362. #define ioctl ioctlsocket
  363. #undef sleep
  364. #define sleep(a) Sleep( a*1000 )
  365. #define EMSGSIZE WSAEMSGSIZE
  366. #define EWOULDBLOCK WSAEWOULDBLOCK
  367. #define EHOSTUNREACH WSAEHOSTUNREACH
  368. #if !defined(MAXPATHLEN)
  369. #define MAXPATHLEN _MAX_PATH
  370. #endif
  371. #endif
  372. #endif /* _PORTABLE_H */