curlrules.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #ifndef __CURL_CURLRULES_H
  2. #define __CURL_CURLRULES_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, 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 https://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. * https://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_SIZEOF_CURL_OFF_T
  99. # error "CURL_SIZEOF_CURL_OFF_T definition is missing!"
  100. Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_is_missing
  101. #endif
  102. #ifndef CURL_SUFFIX_CURL_OFF_T
  103. # error "CURL_SUFFIX_CURL_OFF_T definition is missing!"
  104. Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_is_missing
  105. #endif
  106. #ifndef CURL_SUFFIX_CURL_OFF_TU
  107. # error "CURL_SUFFIX_CURL_OFF_TU definition is missing!"
  108. Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_is_missing
  109. #endif
  110. /*
  111. * Macros private to this header file.
  112. */
  113. #define CurlchkszEQ(t, s) sizeof(t) == s ? 1 : -1
  114. #define CurlchkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1
  115. /*
  116. * Verify that the size previously defined and expected for long
  117. * is the same as the one reported by sizeof() at compile time.
  118. */
  119. typedef char
  120. __curl_rule_01__
  121. [CurlchkszEQ(long, CURL_SIZEOF_LONG)];
  122. /*
  123. * Verify that the size previously defined and expected for
  124. * curl_off_t is actually the the same as the one reported
  125. * by sizeof() at compile time.
  126. */
  127. typedef char
  128. __curl_rule_02__
  129. [CurlchkszEQ(curl_off_t, CURL_SIZEOF_CURL_OFF_T)];
  130. /*
  131. * Verify at compile time that the size of curl_off_t as reported
  132. * by sizeof() is greater or equal than the one reported for long
  133. * for the current compilation.
  134. */
  135. typedef char
  136. __curl_rule_03__
  137. [CurlchkszGE(curl_off_t, long)];
  138. /*
  139. * Verify that the size previously defined and expected for
  140. * curl_socklen_t is actually the the same as the one reported
  141. * by sizeof() at compile time.
  142. */
  143. typedef char
  144. __curl_rule_04__
  145. [CurlchkszEQ(curl_socklen_t, CURL_SIZEOF_CURL_SOCKLEN_T)];
  146. /*
  147. * Verify at compile time that the size of curl_socklen_t as reported
  148. * by sizeof() is greater or equal than the one reported for int for
  149. * the current compilation.
  150. */
  151. typedef char
  152. __curl_rule_05__
  153. [CurlchkszGE(curl_socklen_t, int)];
  154. /* ================================================================ */
  155. /* EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS */
  156. /* ================================================================ */
  157. /*
  158. * CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow
  159. * these to be visible and exported by the external libcurl interface API,
  160. * while also making them visible to the library internals, simply including
  161. * curl_setup.h, without actually needing to include curl.h internally.
  162. * If some day this section would grow big enough, all this should be moved
  163. * to its own header file.
  164. */
  165. /*
  166. * Figure out if we can use the ## preprocessor operator, which is supported
  167. * by ISO/ANSI C and C++. Some compilers support it without setting __STDC__
  168. * or __cplusplus so we need to carefully check for them too.
  169. */
  170. #if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \
  171. defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \
  172. defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \
  173. defined(__ILEC400__)
  174. /* This compiler is believed to have an ISO compatible preprocessor */
  175. #define CURL_ISOCPP
  176. #else
  177. /* This compiler is believed NOT to have an ISO compatible preprocessor */
  178. #undef CURL_ISOCPP
  179. #endif
  180. /*
  181. * Macros for minimum-width signed and unsigned curl_off_t integer constants.
  182. */
  183. #if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551)
  184. # define __CURL_OFF_T_C_HLPR2(x) x
  185. # define __CURL_OFF_T_C_HLPR1(x) __CURL_OFF_T_C_HLPR2(x)
  186. # define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \
  187. __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T)
  188. # define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \
  189. __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU)
  190. #else
  191. # ifdef CURL_ISOCPP
  192. # define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix
  193. # else
  194. # define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix
  195. # endif
  196. # define __CURL_OFF_T_C_HLPR1(Val,Suffix) __CURL_OFF_T_C_HLPR2(Val,Suffix)
  197. # define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T)
  198. # define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU)
  199. #endif
  200. /*
  201. * Get rid of macros private to this header file.
  202. */
  203. #undef CurlchkszEQ
  204. #undef CurlchkszGE
  205. #endif /* __CURL_CURLRULES_H */