compat.h 5.8 KB

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