compat.h 5.2 KB

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