ares_rules.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* MIT License
  2. *
  3. * Copyright (c) 2009 Daniel Stenberg
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. * SPDX-License-Identifier: MIT
  25. */
  26. #ifndef __CARES_RULES_H
  27. #define __CARES_RULES_H
  28. /* ================================================================ */
  29. /* COMPILE TIME SANITY CHECKS */
  30. /* ================================================================ */
  31. /*
  32. * NOTE 1:
  33. * -------
  34. *
  35. * All checks done in this file are intentionally placed in a public
  36. * header file which is pulled by ares.h when an application is
  37. * being built using an already built c-ares library. Additionally
  38. * this file is also included and used when building the library.
  39. *
  40. * If compilation fails on this file it is certainly sure that the
  41. * problem is elsewhere. It could be a problem in the ares_build.h
  42. * header file, or simply that you are using different compilation
  43. * settings than those used to build the library.
  44. *
  45. * Nothing in this file is intended to be modified or adjusted by the
  46. * c-ares library user nor by the c-ares library builder.
  47. *
  48. * Do not deactivate any check, these are done to make sure that the
  49. * library is properly built and used.
  50. *
  51. * You can find further help on the c-ares development mailing list:
  52. * http://lists.haxx.se/listinfo/c-ares/
  53. *
  54. * NOTE 2
  55. * ------
  56. *
  57. * Some of the following compile time checks are based on the fact
  58. * that the dimension of a constant array can not be a negative one.
  59. * In this way if the compile time verification fails, the compilation
  60. * will fail issuing an error. The error description wording is compiler
  61. * dependent but it will be quite similar to one of the following:
  62. *
  63. * "negative subscript or subscript is too large"
  64. * "array must have at least one element"
  65. * "-1 is an illegal array size"
  66. * "size of array is negative"
  67. *
  68. * If you are building an application which tries to use an already
  69. * built c-ares library and you are getting this kind of errors on
  70. * this file, it is a clear indication that there is a mismatch between
  71. * how the library was built and how you are trying to use it for your
  72. * application. Your already compiled or binary library provider is the
  73. * only one who can give you the details you need to properly use it.
  74. */
  75. /*
  76. * Verify that some macros are actually defined.
  77. */
  78. #ifndef CARES_TYPEOF_ARES_SOCKLEN_T
  79. # error "CARES_TYPEOF_ARES_SOCKLEN_T definition is missing!"
  80. Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_is_missing
  81. #endif
  82. /*
  83. * Macros private to this header file.
  84. */
  85. #define CareschkszEQ(t, s) sizeof(t) == s ? 1 : -1
  86. #define CareschkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1
  87. /*
  88. * Verify that the size previously defined and expected for
  89. * ares_socklen_t is actually the same as the one reported
  90. * by sizeof() at compile time.
  91. */
  92. typedef char
  93. __cares_rule_02__
  94. [CareschkszEQ(ares_socklen_t, sizeof(CARES_TYPEOF_ARES_SOCKLEN_T))];
  95. /*
  96. * Verify at compile time that the size of ares_socklen_t as reported
  97. * by sizeof() is greater or equal than the one reported for int for
  98. * the current compilation.
  99. */
  100. typedef char
  101. __cares_rule_03__
  102. [CareschkszGE(ares_socklen_t, int)];
  103. /* ================================================================ */
  104. /* EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS */
  105. /* ================================================================ */
  106. /*
  107. * Get rid of macros private to this header file.
  108. */
  109. #undef CareschkszEQ
  110. #undef CareschkszGE
  111. /*
  112. * Get rid of macros not intended to exist beyond this point.
  113. */
  114. #undef CARES_PULL_WS2TCPIP_H
  115. #undef CARES_PULL_SYS_TYPES_H
  116. #undef CARES_PULL_SYS_SOCKET_H
  117. #undef CARES_TYPEOF_ARES_SOCKLEN_T
  118. #endif /* __CARES_RULES_H */