compat.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999-2006, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * This program is free software, distributed under the terms of
  9. * the GNU General Public License
  10. */
  11. /*! \file
  12. * \brief General Definitions for Asterisk top level program
  13. * Included by asterisk.h to handle platform-specific issues
  14. * especially those related to header files.
  15. */
  16. #include "asterisk/compiler.h"
  17. #ifndef _COMPAT_H
  18. #define _COMPAT_H
  19. #ifndef __STDC_VERSION__
  20. /* flex output wants to find this defined. */
  21. #define __STDC_VERSION__ 0
  22. #endif
  23. #ifdef HAVE_INTTYPES_H
  24. #include <inttypes.h>
  25. #endif
  26. #ifdef HAVE_LIMITS_H
  27. #include <limits.h>
  28. #endif
  29. #ifdef HAVE_UNISTD_H
  30. #include <unistd.h>
  31. #endif
  32. #ifdef HAVE_STDDEF_H
  33. #include <stddef.h>
  34. #endif
  35. #ifdef HAVE_STDINT_H
  36. #include <stdint.h>
  37. #endif
  38. #ifdef HAVE_SYS_TYPES_H
  39. #include <sys/types.h>
  40. #endif
  41. #include <stdarg.h>
  42. #ifdef HAVE_STDLIB_H
  43. #include <stdlib.h>
  44. #endif
  45. #ifdef HAVE_ALLOCA_H
  46. #include <alloca.h> /* not necessarily present - could be in stdlib */
  47. #elif defined(HAVE_ALLOCA) && defined(__MINGW32__)
  48. #include <malloc.h> /* see if it is here... */
  49. #endif
  50. #include <stdio.h> /* this is always present */
  51. #ifdef HAVE_STRING_H
  52. #include <string.h>
  53. #endif
  54. #ifndef AST_POLL_COMPAT
  55. #include <poll.h>
  56. #else
  57. #include "asterisk/poll-compat.h"
  58. #endif
  59. #ifndef HAVE_LLONG_MAX
  60. #define LLONG_MAX 9223372036854775807LL
  61. #endif
  62. #ifndef HAVE_CLOSEFROM
  63. void closefrom(int lowfd);
  64. #endif
  65. #if !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC)
  66. int __attribute__((format(printf, 2, 3))) asprintf(char **str, const char *fmt, ...);
  67. #endif
  68. #ifndef HAVE_FFSLL
  69. int ffsll(long long n);
  70. #endif
  71. #ifndef HAVE_GETLOADAVG
  72. int getloadavg(double *list, int nelem);
  73. #endif
  74. #ifndef HAVE_HTONLL
  75. uint64_t htonll(uint64_t host64);
  76. #endif
  77. #ifndef HAVE_MKDTEMP
  78. char *mkdtemp(char *template_s);
  79. #endif
  80. #ifndef HAVE_NTOHLL
  81. uint64_t ntohll(uint64_t net64);
  82. #endif
  83. #ifndef HAVE_SETENV
  84. int setenv(const char *name, const char *value, int overwrite);
  85. #endif
  86. #ifndef HAVE_STRCASESTR
  87. char *strcasestr(const char *, const char *);
  88. #endif
  89. #if !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC)
  90. char *strndup(const char *, size_t);
  91. #endif
  92. #ifndef HAVE_STRNLEN
  93. size_t strnlen(const char *, size_t);
  94. #endif
  95. #ifndef HAVE_STRSEP
  96. char* strsep(char** str, const char* delims);
  97. #endif
  98. #ifndef HAVE_STRTOQ
  99. uint64_t strtoq(const char *nptr, char **endptr, int base);
  100. #endif
  101. #ifndef HAVE_UNSETENV
  102. int unsetenv(const char *name);
  103. #endif
  104. #if !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC)
  105. int __attribute__((format(printf, 2, 0))) vasprintf(char **strp, const char *fmt, va_list ap);
  106. #endif
  107. #ifndef HAVE_TIMERSUB
  108. void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff);
  109. #endif
  110. #define strlcat __use__ast_str__functions_not__strlcat__
  111. #define strlcpy __use__ast_copy_string__not__strlcpy__
  112. #include <errno.h>
  113. #ifdef SOLARIS
  114. #define __BEGIN_DECLS
  115. #define __END_DECLS
  116. #ifndef __P
  117. #define __P(p) p
  118. #endif
  119. #include <alloca.h>
  120. #include <strings.h>
  121. #include <string.h>
  122. #include <pthread.h>
  123. #include <sys/stat.h>
  124. #include <signal.h>
  125. #include <netinet/in.h>
  126. #include <sys/loadavg.h>
  127. #include <dat/dat_platform_specific.h>
  128. #ifndef BYTE_ORDER
  129. #define LITTLE_ENDIAN 1234
  130. #define BIG_ENDIAN 4321
  131. #ifdef __sparc__
  132. #define BYTE_ORDER BIG_ENDIAN
  133. #else
  134. #define BYTE_ORDER LITTLE_ENDIAN
  135. #endif
  136. #endif
  137. #ifndef __BYTE_ORDER
  138. #define __LITTLE_ENDIAN LITTLE_ENDIAN
  139. #define __BIG_ENDIAN BIG_ENDIAN
  140. #define __BYTE_ORDER BYTE_ORDER
  141. #endif
  142. #ifndef __BIT_TYPES_DEFINED__
  143. #define __BIT_TYPES_DEFINED__
  144. typedef unsigned char u_int8_t;
  145. typedef unsigned short u_int16_t;
  146. typedef unsigned int u_int32_t;
  147. typedef unsigned int uint;
  148. #endif
  149. #endif /* SOLARIS */
  150. #ifdef __CYGWIN__
  151. #define _WIN32_WINNT 0x0500
  152. #ifndef INET_ADDRSTRLEN
  153. #define INET_ADDRSTRLEN 16
  154. #endif
  155. #ifndef INET6_ADDRSTRLEN
  156. #define INET6_ADDRSTRLEN 46
  157. #endif
  158. #endif /* __CYGWIN__ */
  159. #ifdef __CYGWIN__
  160. typedef unsigned long long uint64_t;
  161. #endif
  162. /* glob compat stuff */
  163. #if defined(__Darwin__) || defined(__CYGWIN__)
  164. #define GLOB_ABORTED GLOB_ABEND
  165. #endif
  166. #include <glob.h>
  167. #if !defined(HAVE_GLOB_NOMAGIC) || !defined(HAVE_GLOB_BRACE)
  168. #define MY_GLOB_FLAGS GLOB_NOCHECK
  169. #else
  170. #define MY_GLOB_FLAGS (GLOB_NOMAGIC | GLOB_BRACE)
  171. #endif
  172. #ifndef HAVE_ROUNDF
  173. #ifdef HAVE_ROUND
  174. #define roundf(x) ((float)round(x))
  175. #else
  176. float roundf(float x);
  177. #endif
  178. #endif
  179. #ifndef INFINITY
  180. #define INFINITY (1.0/0.0)
  181. #endif
  182. #ifndef NAN
  183. #define NAN (0.0/0.0)
  184. #endif
  185. #endif