compat.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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.16 2007/04/27 01:10:47 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) && defined(_MAX_PATH)
  166. # define PATH_MAX _MAX_PATH
  167. # define MAXPATHLEN _MAX_PATH
  168. #endif
  169. #if !defined (MAXPATHLEN)
  170. # define MAXPATHLEN ((size_t)4096)
  171. #endif /* MAXPATHLEN */
  172. #define AG_PATH_MAX ((size_t)MAXPATHLEN)
  173. #ifndef LONG_MAX
  174. # define LONG_MAX ~(1L << (8*sizeof(long) -1))
  175. # define INT_MAX ~(1 << (8*sizeof(int) -1))
  176. #endif
  177. #ifndef ULONG_MAX
  178. # define ULONG_MAX ~(OUL)
  179. # define UINT_MAX ~(OU)
  180. #endif
  181. #ifndef SHORT_MAX
  182. # define SHORT_MAX ~(1 << (8*sizeof(short) -1))
  183. #else
  184. # define USHORT_MAX ~(OUS)
  185. #endif
  186. #ifndef HAVE_INT8_T
  187. typedef signed char int8_t;
  188. #endif
  189. #ifndef HAVE_UINT8_T
  190. typedef unsigned char uint8_t;
  191. #endif
  192. #ifndef HAVE_INT16_T
  193. typedef signed short int16_t;
  194. #endif
  195. #ifndef HAVE_UINT16_T
  196. typedef unsigned short uint16_t;
  197. #endif
  198. #ifndef HAVE_UINT_T
  199. typedef unsigned int uint_t;
  200. #endif
  201. #ifndef HAVE_INT32_T
  202. # if SIZEOF_INT == 4
  203. typedef signed int int32_t;
  204. # elif SIZEOF_LONG == 4
  205. typedef signed long int32_t;
  206. # endif
  207. #endif
  208. #ifndef HAVE_UINT32_T
  209. # if SIZEOF_INT == 4
  210. typedef unsigned int uint32_t;
  211. # elif SIZEOF_LONG == 4
  212. typedef unsigned long uint32_t;
  213. # else
  214. # error Cannot create a uint32_t type.
  215. Choke Me.
  216. # endif
  217. #endif
  218. #ifndef HAVE_INTPTR_T
  219. typedef signed long intptr_t;
  220. #endif
  221. #ifndef HAVE_UINTPTR_T
  222. typedef unsigned long uintptr_t;
  223. #endif
  224. /* redefine these for BSD style string libraries */
  225. #ifndef HAVE_STRCHR
  226. # define strchr index
  227. # define strrchr rindex
  228. #endif
  229. #ifdef USE_FOPEN_BINARY
  230. # ifndef FOPEN_BINARY_FLAG
  231. # define FOPEN_BINARY_FLAG "b"
  232. # endif
  233. # ifndef FOPEN_TEXT_FLAG
  234. # define FOPEN_TEXT_FLAG "t"
  235. # endif
  236. #else
  237. # ifndef FOPEN_BINARY_FLAG
  238. # define FOPEN_BINARY_FLAG
  239. # endif
  240. # ifndef FOPEN_TEXT_FLAG
  241. # define FOPEN_TEXT_FLAG
  242. # endif
  243. #endif
  244. #ifndef STR
  245. # define _STR(s) #s
  246. # define STR(s) _STR(s)
  247. #endif
  248. /* ##### Pointer sized word ##### */
  249. /* FIXME: the MAX stuff in here is broken! */
  250. #if SIZEOF_CHARP > SIZEOF_INT
  251. typedef long t_word;
  252. #define WORD_MAX LONG_MAX
  253. #define WORD_MIN LONG_MIN
  254. #else /* SIZEOF_CHARP <= SIZEOF_INT */
  255. typedef int t_word;
  256. #define WORD_MAX INT_MAX
  257. #define WORD_MIN INT_MIN
  258. #endif
  259. #endif /* COMPAT_H_GUARD */
  260. /*
  261. * Local Variables:
  262. * mode: C
  263. * c-file-style: "stroustrup"
  264. * indent-tabs-mode: nil
  265. * End:
  266. * end of compat/compat.h */