portable.h 11 KB

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