1
0

compat.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /* -*- Mode: C -*- */
  2. /* --- fake the preprocessor into handlng portability */
  3. /*
  4. * Time-stamp: "2007-02-03 17:41:06 bkorb"
  5. *
  6. * Author: Gary V Vaughan <gvaughan@oranda.demon.co.uk>
  7. * Created: Mon Jun 30 15:54:46 1997
  8. *
  9. * $Id: compat.h,v 4.15 2007/02/04 22:17:39 bkorb Exp $
  10. */
  11. #ifndef COMPAT_H_GUARD
  12. #define COMPAT_H_GUARD 1
  13. #if defined(HAVE_CONFIG_H)
  14. # include <config.h>
  15. #elif defined(_WIN32) && !defined(__CYGWIN__)
  16. # include "windows-config.h"
  17. #else
  18. # error "compat.h" requires "config.h"
  19. choke me.
  20. #endif
  21. #ifndef HAVE_STRSIGNAL
  22. char * strsignal( int signo );
  23. #endif
  24. #define _GNU_SOURCE 1 /* for strsignal in GNU's libc */
  25. #define __USE_GNU 1 /* exact same thing as above */
  26. #define __EXTENSIONS__ 1 /* and another way to call for it */
  27. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  28. *
  29. * SYSTEM HEADERS:
  30. */
  31. #include <sys/types.h>
  32. #ifdef HAVE_SYS_MMAN_H
  33. # include <sys/mman.h>
  34. #endif
  35. #include <sys/param.h>
  36. #if HAVE_SYS_PROCSET_H
  37. # include <sys/procset.h>
  38. #endif
  39. #include <sys/stat.h>
  40. #include <sys/wait.h>
  41. #if defined( HAVE_SOLARIS_SYSINFO )
  42. # include <sys/systeminfo.h>
  43. #elif defined( HAVE_UNAME_SYSCALL )
  44. # include <sys/utsname.h>
  45. #endif
  46. #ifdef DAEMON_ENABLED
  47. # if HAVE_SYS_STROPTS_H
  48. # include <sys/stropts.h>
  49. # endif
  50. # if HAVE_SYS_SOCKET_H
  51. # include <sys/socket.h>
  52. # endif
  53. # if ! defined(HAVE_SYS_POLL_H) && ! defined(HAVE_SYS_SELECT_H)
  54. # error This system cannot support daemon processing
  55. Choke Me.
  56. # endif
  57. # if HAVE_SYS_POLL_H
  58. # include <sys/poll.h>
  59. # endif
  60. # if HAVE_SYS_SELECT_H
  61. # include <sys/select.h>
  62. # endif
  63. # if HAVE_NETINET_IN_H
  64. # include <netinet/in.h>
  65. # endif
  66. # if HAVE_SYS_UN_H
  67. # include <sys/un.h>
  68. # endif
  69. #endif
  70. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  71. *
  72. * USER HEADERS:
  73. */
  74. #include <stdio.h>
  75. #include <assert.h>
  76. #include <ctype.h>
  77. /*
  78. * Directory opening stuff:
  79. */
  80. # if defined (_POSIX_SOURCE)
  81. /* Posix does not require that the d_ino field be present, and some
  82. systems do not provide it. */
  83. # define REAL_DIR_ENTRY(dp) 1
  84. # else /* !_POSIX_SOURCE */
  85. # define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
  86. # endif /* !_POSIX_SOURCE */
  87. # if defined (HAVE_DIRENT_H)
  88. # include <dirent.h>
  89. # define D_NAMLEN(dirent) strlen((dirent)->d_name)
  90. # else /* !HAVE_DIRENT_H */
  91. # define dirent direct
  92. # define D_NAMLEN(dirent) (dirent)->d_namlen
  93. # if defined (HAVE_SYS_NDIR_H)
  94. # include <sys/ndir.h>
  95. # endif /* HAVE_SYS_NDIR_H */
  96. # if defined (HAVE_SYS_DIR_H)
  97. # include <sys/dir.h>
  98. # endif /* HAVE_SYS_DIR_H */
  99. # if defined (HAVE_NDIR_H)
  100. # include <ndir.h>
  101. # endif /* HAVE_NDIR_H */
  102. # endif /* !HAVE_DIRENT_H */
  103. #include <errno.h>
  104. #ifdef HAVE_FCNTL_H
  105. # include <fcntl.h>
  106. #endif
  107. #ifndef O_NONBLOCK
  108. # define O_NONBLOCK FNDELAY
  109. #endif
  110. #if defined(HAVE_LIBGEN) && defined(HAVE_LIBGEN_H)
  111. # include <libgen.h>
  112. #endif
  113. #if defined(HAVE_LIMITS_H) /* this is also in options.h */
  114. # include <limits.h>
  115. #elif defined(HAVE_SYS_LIMITS_H)
  116. # include <sys/limits.h>
  117. #endif /* HAVE_LIMITS/SYS_LIMITS_H */
  118. #include <memory.h>
  119. #include <setjmp.h>
  120. #include <signal.h>
  121. #if defined( HAVE_STDINT_H )
  122. # include <stdint.h>
  123. #elif defined( HAVE_INTTYPES_H )
  124. # include <inttypes.h>
  125. #endif
  126. #include <stdlib.h>
  127. #include <string.h>
  128. #include <time.h>
  129. #ifdef HAVE_UTIME_H
  130. # include <utime.h>
  131. #endif
  132. #ifdef HAVE_UNISTD_H
  133. # include <unistd.h>
  134. #endif
  135. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  136. *
  137. * FIXUPS and CONVIENCE STUFF:
  138. */
  139. #ifdef __cplusplus
  140. # define EXTERN extern "C"
  141. #else
  142. # define EXTERN extern
  143. #endif
  144. /* some systems #def errno! and others do not declare it!! */
  145. #ifndef errno
  146. extern int errno;
  147. #endif
  148. /* Some machines forget this! */
  149. # ifndef EXIT_FAILURE
  150. # define EXIT_SUCCESS 0
  151. # define EXIT_FAILURE 1
  152. # endif
  153. #ifndef NUL
  154. # define NUL '\0'
  155. #endif
  156. #ifndef NULL
  157. # define NULL 0
  158. #endif
  159. #if !defined (MAXPATHLEN) && defined (HAVE_SYS_PARAM_H)
  160. # include <sys/param.h>
  161. #endif /* !MAXPATHLEN && HAVE_SYS_PARAM_H */
  162. #if !defined (MAXPATHLEN) && defined (PATH_MAX)
  163. # define MAXPATHLEN PATH_MAX
  164. #endif /* !MAXPATHLEN && PATH_MAX */
  165. #if !defined (MAXPATHLEN)
  166. # define MAXPATHLEN ((size_t)4096)
  167. #endif /* MAXPATHLEN */
  168. #define AG_PATH_MAX ((size_t)MAXPATHLEN)
  169. #ifndef LONG_MAX
  170. # define LONG_MAX ~(1L << (8*sizeof(long) -1))
  171. # define INT_MAX ~(1 << (8*sizeof(int) -1))
  172. #endif
  173. #ifndef ULONG_MAX
  174. # define ULONG_MAX ~(OUL)
  175. # define UINT_MAX ~(OU)
  176. #endif
  177. #ifndef SHORT_MAX
  178. # define SHORT_MAX ~(1 << (8*sizeof(short) -1))
  179. #else
  180. # define USHORT_MAX ~(OUS)
  181. #endif
  182. #ifndef HAVE_INT8_T
  183. typedef signed char int8_t;
  184. #endif
  185. #ifndef HAVE_UINT8_T
  186. typedef unsigned char uint8_t;
  187. #endif
  188. #ifndef HAVE_INT16_T
  189. typedef signed short int16_t;
  190. #endif
  191. #ifndef HAVE_UINT16_T
  192. typedef unsigned short uint16_t;
  193. #endif
  194. #ifndef HAVE_UINT_T
  195. typedef unsigned int uint_t;
  196. #endif
  197. #ifndef HAVE_INT32_T
  198. # if SIZEOF_INT == 4
  199. typedef signed int int32_t;
  200. # elif SIZEOF_LONG == 4
  201. typedef signed long int32_t;
  202. # endif
  203. #endif
  204. #ifndef HAVE_UINT32_T
  205. # if SIZEOF_INT == 4
  206. typedef unsigned int uint32_t;
  207. # elif SIZEOF_LONG == 4
  208. typedef unsigned long uint32_t;
  209. # else
  210. # error Cannot create a uint32_t type.
  211. Choke Me.
  212. # endif
  213. #endif
  214. #ifndef HAVE_INTPTR_T
  215. typedef signed long intptr_t;
  216. #endif
  217. #ifndef HAVE_UINTPTR_T
  218. typedef unsigned long uintptr_t;
  219. #endif
  220. /* redefine these for BSD style string libraries */
  221. #ifndef HAVE_STRCHR
  222. # define strchr index
  223. # define strrchr rindex
  224. #endif
  225. #ifdef USE_FOPEN_BINARY
  226. # ifndef FOPEN_BINARY_FLAG
  227. # define FOPEN_BINARY_FLAG "b"
  228. # endif
  229. # ifndef FOPEN_TEXT_FLAG
  230. # define FOPEN_TEXT_FLAG "t"
  231. # endif
  232. #else
  233. # ifndef FOPEN_BINARY_FLAG
  234. # define FOPEN_BINARY_FLAG
  235. # endif
  236. # ifndef FOPEN_TEXT_FLAG
  237. # define FOPEN_TEXT_FLAG
  238. # endif
  239. #endif
  240. #ifndef STR
  241. # define _STR(s) #s
  242. # define STR(s) _STR(s)
  243. #endif
  244. /* ##### Pointer sized word ##### */
  245. /* FIXME: the MAX stuff in here is broken! */
  246. #if SIZEOF_CHARP > SIZEOF_INT
  247. typedef long t_word;
  248. #define WORD_MAX LONG_MAX
  249. #define WORD_MIN LONG_MIN
  250. #else /* SIZEOF_CHARP <= SIZEOF_INT */
  251. typedef int t_word;
  252. #define WORD_MAX INT_MAX
  253. #define WORD_MIN INT_MIN
  254. #endif
  255. #endif /* COMPAT_H_GUARD */
  256. /*
  257. * Local Variables:
  258. * mode: C
  259. * c-file-style: "stroustrup"
  260. * indent-tabs-mode: nil
  261. * End:
  262. * end of compat/compat.h */