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