Home | History | Annotate | Download | only in curl
      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 (at) 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 /* ================================================================ */
     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  * https://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_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 
     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 
     88 #ifndef CURL_TYPEOF_CURL_OFF_T
     89 #  error "CURL_TYPEOF_CURL_OFF_T definition is missing!"
     90    Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_is_missing
     91 #endif
     92 
     93 #ifndef CURL_FORMAT_CURL_OFF_T
     94 #  error "CURL_FORMAT_CURL_OFF_T definition is missing!"
     95    Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_is_missing
     96 #endif
     97 
     98 #ifndef CURL_FORMAT_CURL_OFF_TU
     99 #  error "CURL_FORMAT_CURL_OFF_TU definition is missing!"
    100    Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_is_missing
    101 #endif
    102 
    103 #ifndef CURL_FORMAT_OFF_T
    104 #  error "CURL_FORMAT_OFF_T definition is missing!"
    105    Error Compilation_aborted_CURL_FORMAT_OFF_T_is_missing
    106 #endif
    107 
    108 #ifndef CURL_SIZEOF_CURL_OFF_T
    109 #  error "CURL_SIZEOF_CURL_OFF_T definition is missing!"
    110    Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_is_missing
    111 #endif
    112 
    113 #ifndef CURL_SUFFIX_CURL_OFF_T
    114 #  error "CURL_SUFFIX_CURL_OFF_T definition is missing!"
    115    Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_is_missing
    116 #endif
    117 
    118 #ifndef CURL_SUFFIX_CURL_OFF_TU
    119 #  error "CURL_SUFFIX_CURL_OFF_TU definition is missing!"
    120    Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_is_missing
    121 #endif
    122 
    123 /*
    124  * Macros private to this header file.
    125  */
    126 
    127 #define CurlchkszEQ(t, s) sizeof(t) == s ? 1 : -1
    128 
    129 #define CurlchkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1
    130 
    131 /*
    132  * Verify that the size previously defined and expected for
    133  * curl_off_t is actually the the same as the one reported
    134  * by sizeof() at compile time.
    135  */
    136 
    137 typedef char
    138   __curl_rule_02__
    139     [CurlchkszEQ(curl_off_t, CURL_SIZEOF_CURL_OFF_T)];
    140 
    141 /*
    142  * Verify at compile time that the size of curl_off_t as reported
    143  * by sizeof() is greater or equal than the one reported for long
    144  * for the current compilation.
    145  */
    146 
    147 typedef char
    148   __curl_rule_03__
    149     [CurlchkszGE(curl_off_t, long)];
    150 
    151 /*
    152  * Verify that the size previously defined and expected for
    153  * curl_socklen_t is actually the the same as the one reported
    154  * by sizeof() at compile time.
    155  */
    156 
    157 typedef char
    158   __curl_rule_04__
    159     [CurlchkszEQ(curl_socklen_t, CURL_SIZEOF_CURL_SOCKLEN_T)];
    160 
    161 /*
    162  * Verify at compile time that the size of curl_socklen_t as reported
    163  * by sizeof() is greater or equal than the one reported for int for
    164  * the current compilation.
    165  */
    166 
    167 typedef char
    168   __curl_rule_05__
    169     [CurlchkszGE(curl_socklen_t, int)];
    170 
    171 /* ================================================================ */
    172 /*          EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS           */
    173 /* ================================================================ */
    174 
    175 /*
    176  * CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow
    177  * these to be visible and exported by the external libcurl interface API,
    178  * while also making them visible to the library internals, simply including
    179  * curl_setup.h, without actually needing to include curl.h internally.
    180  * If some day this section would grow big enough, all this should be moved
    181  * to its own header file.
    182  */
    183 
    184 /*
    185  * Figure out if we can use the ## preprocessor operator, which is supported
    186  * by ISO/ANSI C and C++. Some compilers support it without setting __STDC__
    187  * or  __cplusplus so we need to carefully check for them too.
    188  */
    189 
    190 #if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \
    191   defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \
    192   defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \
    193   defined(__ILEC400__)
    194   /* This compiler is believed to have an ISO compatible preprocessor */
    195 #define CURL_ISOCPP
    196 #else
    197   /* This compiler is believed NOT to have an ISO compatible preprocessor */
    198 #undef CURL_ISOCPP
    199 #endif
    200 
    201 /*
    202  * Macros for minimum-width signed and unsigned curl_off_t integer constants.
    203  */
    204 
    205 #if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551)
    206 #  define __CURL_OFF_T_C_HLPR2(x) x
    207 #  define __CURL_OFF_T_C_HLPR1(x) __CURL_OFF_T_C_HLPR2(x)
    208 #  define CURL_OFF_T_C(Val)  __CURL_OFF_T_C_HLPR1(Val) ## \
    209                              __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T)
    210 #  define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \
    211                              __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU)
    212 #else
    213 #  ifdef CURL_ISOCPP
    214 #    define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix
    215 #  else
    216 #    define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix
    217 #  endif
    218 #  define __CURL_OFF_T_C_HLPR1(Val,Suffix) __CURL_OFF_T_C_HLPR2(Val,Suffix)
    219 #  define CURL_OFF_T_C(Val)  __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T)
    220 #  define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU)
    221 #endif
    222 
    223 /*
    224  * Get rid of macros private to this header file.
    225  */
    226 
    227 #undef CurlchkszEQ
    228 #undef CurlchkszGE
    229 
    230 /*
    231  * Get rid of macros not intended to exist beyond this point.
    232  */
    233 
    234 #undef CURL_PULL_WS2TCPIP_H
    235 #undef CURL_PULL_SYS_TYPES_H
    236 #undef CURL_PULL_SYS_SOCKET_H
    237 #undef CURL_PULL_SYS_POLL_H
    238 #undef CURL_PULL_STDINT_H
    239 #undef CURL_PULL_INTTYPES_H
    240 
    241 #undef CURL_TYPEOF_CURL_SOCKLEN_T
    242 #undef CURL_TYPEOF_CURL_OFF_T
    243 
    244 #ifdef CURL_NO_OLDIES
    245 #undef CURL_FORMAT_OFF_T /* not required since 7.19.0 - obsoleted in 7.20.0 */
    246 #endif
    247 
    248 #endif /* __CURL_CURLRULES_H */
    249