curlrules.h 8.2 KB

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