curlrules.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #ifndef __CURL_CURLRULES_H
  2. #define __CURL_CURLRULES_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2012, Daniel Stenberg, <[email protected]>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at http://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. ***************************************************************************/
  24. /* ================================================================ */
  25. /* COMPILE TIME SANITY CHECKS */
  26. /* ================================================================ */
  27. /*
  28. * NOTE 1:
  29. * -------
  30. *
  31. * All checks done in this file are intentionally placed in a public
  32. * header file which is pulled by curl/curl.h when an application is
  33. * being built using an already built libcurl library. Additionally
  34. * this file is also included and used when building the library.
  35. *
  36. * If compilation fails on this file it is certainly sure that the
  37. * problem is elsewhere. It could be a problem in the curlbuild.h
  38. * header file, or simply that you are using different compilation
  39. * settings than those used to build the library.
  40. *
  41. * Nothing in this file is intended to be modified or adjusted by the
  42. * curl library user nor by the curl library builder.
  43. *
  44. * Do not deactivate any check, these are done to make sure that the
  45. * library is properly built and used.
  46. *
  47. * You can find further help on the libcurl development mailing list:
  48. * http://cool.haxx.se/mailman/listinfo/curl-library/
  49. *
  50. * NOTE 2
  51. * ------
  52. *
  53. * Some of the following compile time checks are based on the fact
  54. * that the dimension of a constant array can not be a negative one.
  55. * In this way if the compile time verification fails, the compilation
  56. * will fail issuing an error. The error description wording is compiler
  57. * dependent but it will be quite similar to one of the following:
  58. *
  59. * "negative subscript or subscript is too large"
  60. * "array must have at least one element"
  61. * "-1 is an illegal array size"
  62. * "size of array is negative"
  63. *
  64. * If you are building an application which tries to use an already
  65. * built libcurl library and you are getting this kind of errors on
  66. * this file, it is a clear indication that there is a mismatch between
  67. * how the library was built and how you are trying to use it for your
  68. * application. Your already compiled or binary library provider is the
  69. * only one who can give you the details you need to properly use it.
  70. */
  71. /*
  72. * Verify that some macros are actually defined.
  73. */
  74. #ifndef CURL_SIZEOF_LONG
  75. # error "CURL_SIZEOF_LONG definition is missing!"
  76. Error Compilation_aborted_CURL_SIZEOF_LONG_is_missing
  77. #endif
  78. #ifndef CURL_TYPEOF_CURL_SOCKLEN_T
  79. # error "CURL_TYPEOF_CURL_SOCKLEN_T definition is missing!"
  80. Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_is_missing
  81. #endif
  82. #ifndef CURL_SIZEOF_CURL_SOCKLEN_T
  83. # error "CURL_SIZEOF_CURL_SOCKLEN_T definition is missing!"
  84. Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_is_missing
  85. #endif
  86. #ifndef CURL_TYPEOF_CURL_OFF_T
  87. # error "CURL_TYPEOF_CURL_OFF_T definition is missing!"
  88. Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_is_missing
  89. #endif
  90. #ifndef CURL_FORMAT_CURL_OFF_T
  91. # error "CURL_FORMAT_CURL_OFF_T definition is missing!"
  92. Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_is_missing
  93. #endif
  94. #ifndef CURL_FORMAT_CURL_OFF_TU
  95. # error "CURL_FORMAT_CURL_OFF_TU definition is missing!"
  96. Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_is_missing
  97. #endif
  98. #ifndef CURL_FORMAT_OFF_T
  99. # error "CURL_FORMAT_OFF_T definition is missing!"
  100. Error Compilation_aborted_CURL_FORMAT_OFF_T_is_missing
  101. #endif
  102. #ifndef CURL_SIZEOF_CURL_OFF_T
  103. # error "CURL_SIZEOF_CURL_OFF_T definition is missing!"
  104. Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_is_missing
  105. #endif
  106. #ifndef CURL_SUFFIX_CURL_OFF_T
  107. # error "CURL_SUFFIX_CURL_OFF_T definition is missing!"
  108. Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_is_missing
  109. #endif
  110. #ifndef CURL_SUFFIX_CURL_OFF_TU
  111. # error "CURL_SUFFIX_CURL_OFF_TU definition is missing!"
  112. Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_is_missing
  113. #endif
  114. /*
  115. * Macros private to this header file.
  116. */
  117. #define CurlchkszEQ(t, s) sizeof(t) == s ? 1 : -1
  118. #define CurlchkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1
  119. /*
  120. * Verify that the size previously defined and expected for long
  121. * is the same as the one reported by sizeof() at compile time.
  122. */
  123. typedef char
  124. __curl_rule_01__
  125. [CurlchkszEQ(long, CURL_SIZEOF_LONG)];
  126. /*
  127. * Verify that the size previously defined and expected for
  128. * curl_off_t is actually the the same as the one reported
  129. * by sizeof() at compile time.
  130. */
  131. typedef char
  132. __curl_rule_02__
  133. [CurlchkszEQ(curl_off_t, CURL_SIZEOF_CURL_OFF_T)];
  134. /*
  135. * Verify at compile time that the size of curl_off_t as reported
  136. * by sizeof() is greater or equal than the one reported for long
  137. * for the current compilation.
  138. */
  139. typedef char
  140. __curl_rule_03__
  141. [CurlchkszGE(curl_off_t, long)];
  142. /*
  143. * Verify that the size previously defined and expected for
  144. * curl_socklen_t is actually the the same as the one reported
  145. * by sizeof() at compile time.
  146. */
  147. typedef char
  148. __curl_rule_04__
  149. [CurlchkszEQ(curl_socklen_t, CURL_SIZEOF_CURL_SOCKLEN_T)];
  150. /*
  151. * Verify at compile time that the size of curl_socklen_t as reported
  152. * by sizeof() is greater or equal than the one reported for int for
  153. * the current compilation.
  154. */
  155. typedef char
  156. __curl_rule_05__
  157. [CurlchkszGE(curl_socklen_t, int)];
  158. /* ================================================================ */
  159. /* EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS */
  160. /* ================================================================ */
  161. /*
  162. * CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow
  163. * these to be visible and exported by the external libcurl interface API,
  164. * while also making them visible to the library internals, simply including
  165. * curl_setup.h, without actually needing to include curl.h internally.
  166. * If some day this section would grow big enough, all this should be moved
  167. * to its own header file.
  168. */
  169. /*
  170. * Figure out if we can use the ## preprocessor operator, which is supported
  171. * by ISO/ANSI C and C++. Some compilers support it without setting __STDC__
  172. * or __cplusplus so we need to carefully check for them too.
  173. */
  174. #if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \
  175. defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \
  176. defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \
  177. defined(__ILEC400__)
  178. /* This compiler is believed to have an ISO compatible preprocessor */
  179. #define CURL_ISOCPP
  180. #else
  181. /* This compiler is believed NOT to have an ISO compatible preprocessor */
  182. #undef CURL_ISOCPP
  183. #endif
  184. /*
  185. * Macros for minimum-width signed and unsigned curl_off_t integer constants.
  186. */
  187. #if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551)
  188. # define __CURL_OFF_T_C_HLPR2(x) x
  189. # define __CURL_OFF_T_C_HLPR1(x) __CURL_OFF_T_C_HLPR2(x)
  190. # define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \
  191. __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T)
  192. # define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \
  193. __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU)
  194. #else
  195. # ifdef CURL_ISOCPP
  196. # define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix
  197. # else
  198. # define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix
  199. # endif
  200. # define __CURL_OFF_T_C_HLPR1(Val,Suffix) __CURL_OFF_T_C_HLPR2(Val,Suffix)
  201. # define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T)
  202. # define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU)
  203. #endif
  204. /*
  205. * Get rid of macros private to this header file.
  206. */
  207. #undef CurlchkszEQ
  208. #undef CurlchkszGE
  209. /*
  210. * Get rid of macros not intended to exist beyond this point.
  211. */
  212. #undef CURL_PULL_WS2TCPIP_H
  213. #undef CURL_PULL_SYS_TYPES_H
  214. #undef CURL_PULL_SYS_SOCKET_H
  215. #undef CURL_PULL_SYS_POLL_H
  216. #undef CURL_PULL_STDINT_H
  217. #undef CURL_PULL_INTTYPES_H
  218. #undef CURL_TYPEOF_CURL_SOCKLEN_T
  219. #undef CURL_TYPEOF_CURL_OFF_T
  220. #ifdef CURL_NO_OLDIES
  221. #undef CURL_FORMAT_OFF_T /* not required since 7.19.0 - obsoleted in 7.20.0 */
  222. #endif
  223. #endif /* __CURL_CURLRULES_H */