1 #ifndef __CARES_RULES_H
2 #define __CARES_RULES_H
3 
4 
5 /* Copyright (C) 2009 by Daniel Stenberg et al
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation for any purpose and without fee is hereby granted, provided
9  * that the above copyright notice appear in all copies and that both that
10  * copyright notice and this permission notice appear in supporting
11  * documentation, and that the name of M.I.T. not be used in advertising or
12  * publicity pertaining to distribution of the software without specific,
13  * written prior permission.  M.I.T. makes no representations about the
14  * suitability of this software for any purpose.  It is provided "as is"
15  * without express or implied warranty.
16  */
17 
18 /* ================================================================ */
19 /*                    COMPILE TIME SANITY CHECKS                    */
20 /* ================================================================ */
21 
22 /*
23  * NOTE 1:
24  * -------
25  *
26  * All checks done in this file are intentionally placed in a public
27  * header file which is pulled by ares.h when an application is
28  * being built using an already built c-ares library. Additionally
29  * this file is also included and used when building the library.
30  *
31  * If compilation fails on this file it is certainly sure that the
32  * problem is elsewhere. It could be a problem in the ares_build.h
33  * header file, or simply that you are using different compilation
34  * settings than those used to build the library.
35  *
36  * Nothing in this file is intended to be modified or adjusted by the
37  * c-ares library user nor by the c-ares library builder.
38  *
39  * Do not deactivate any check, these are done to make sure that the
40  * library is properly built and used.
41  *
42  * You can find further help on the c-ares development mailing list:
43  * http://cool.haxx.se/mailman/listinfo/c-ares/
44  *
45  * NOTE 2
46  * ------
47  *
48  * Some of the following compile time checks are based on the fact
49  * that the dimension of a constant array can not be a negative one.
50  * In this way if the compile time verification fails, the compilation
51  * will fail issuing an error. The error description wording is compiler
52  * dependent but it will be quite similar to one of the following:
53  *
54  *   "negative subscript or subscript is too large"
55  *   "array must have at least one element"
56  *   "-1 is an illegal array size"
57  *   "size of array is negative"
58  *
59  * If you are building an application which tries to use an already
60  * built c-ares library and you are getting this kind of errors on
61  * this file, it is a clear indication that there is a mismatch between
62  * how the library was built and how you are trying to use it for your
63  * application. Your already compiled or binary library provider is the
64  * only one who can give you the details you need to properly use it.
65  */
66 
67 /*
68  * Verify that some macros are actually defined.
69  */
70 
71 #ifndef CARES_SIZEOF_LONG
72 #  error "CARES_SIZEOF_LONG definition is missing!"
73    Error Compilation_aborted_CARES_SIZEOF_LONG_is_missing
74 #endif
75 
76 #ifndef CARES_TYPEOF_ARES_SOCKLEN_T
77 #  error "CARES_TYPEOF_ARES_SOCKLEN_T definition is missing!"
78    Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_is_missing
79 #endif
80 
81 #ifndef CARES_SIZEOF_ARES_SOCKLEN_T
82 #  error "CARES_SIZEOF_ARES_SOCKLEN_T definition is missing!"
83    Error Compilation_aborted_CARES_SIZEOF_ARES_SOCKLEN_T_is_missing
84 #endif
85 
86 /*
87  * Macros private to this header file.
88  */
89 
90 #define CareschkszEQ(t, s) sizeof(t) == s ? 1 : -1
91 
92 #define CareschkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1
93 
94 /*
95  * Verify that the size previously defined and expected for long
96  * is the same as the one reported by sizeof() at compile time.
97  */
98 
99 typedef char
100   __cares_rule_01__
101     [CareschkszEQ(long, CARES_SIZEOF_LONG)];
102 
103 /*
104  * Verify that the size previously defined and expected for
105  * ares_socklen_t is actually the the same as the one reported
106  * by sizeof() at compile time.
107  */
108 
109 typedef char
110   __cares_rule_02__
111     [CareschkszEQ(ares_socklen_t, CARES_SIZEOF_ARES_SOCKLEN_T)];
112 
113 /*
114  * Verify at compile time that the size of ares_socklen_t as reported
115  * by sizeof() is greater or equal than the one reported for int for
116  * the current compilation.
117  */
118 
119 typedef char
120   __cares_rule_03__
121     [CareschkszGE(ares_socklen_t, int)];
122 
123 /* ================================================================ */
124 /*          EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS           */
125 /* ================================================================ */
126 
127 /*
128  * Get rid of macros private to this header file.
129  */
130 
131 #undef CareschkszEQ
132 #undef CareschkszGE
133 
134 /*
135  * Get rid of macros not intended to exist beyond this point.
136  */
137 
138 #undef CARES_PULL_WS2TCPIP_H
139 #undef CARES_PULL_SYS_TYPES_H
140 #undef CARES_PULL_SYS_SOCKET_H
141 
142 #undef CARES_TYPEOF_ARES_SOCKLEN_T
143 
144 #endif /* __CARES_RULES_H */
145