portable.h 13 KB

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