2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/opensslconf.h>
12 #ifndef OPENSSL_MACROS_H
13 # define OPENSSL_MACROS_H
16 * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers
17 * don't like that. This will hopefully silence them.
19 # define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy;
22 * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the
23 * declarations of functions deprecated in or before <version>. If this is
24 * undefined, the value of the macro OPENSSL_API_MIN above is the default.
26 * For any version number up until version 1.1.x, <version> is expected to be
27 * the calculated version number 0xMNNFFPPSL. For version numbers 3.0.0 and
28 * on, <version> is expected to be only the major version number (i.e. 3 for
31 # ifndef DECLARE_DEPRECATED
32 # define DECLARE_DEPRECATED(f) f;
34 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
35 # undef DECLARE_DEPRECATED
36 # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated));
38 # elif defined(__SUNPRO_C)
39 # if (__SUNPRO_C >= 0x5130)
40 # undef DECLARE_DEPRECATED
41 # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated));
47 * We convert the OPENSSL_API_COMPAT value to an API level. The API level
48 * is the major version number for 3.0.0 and on. For earlier versions, it
49 * uses this scheme, which is close enough for our purposes:
51 * 0.x.y 0 (0.9.8 was the last release in this series)
52 * 1.0.x 1 (1.0.2 was the last release in this series)
53 * 1.1.x 2 (1.1.1 was the last release in this series)
56 /* In case someone defined both */
57 # if defined(OPENSSL_API_COMPAT) && defined(OPENSSL_API_LEVEL)
58 # error "Disallowed to define both OPENSSL_API_COMPAT and OPENSSL_API_LEVEL"
61 # ifndef OPENSSL_API_COMPAT
62 # define OPENSSL_API_LEVEL OPENSSL_MIN_API
64 # if (OPENSSL_API_COMPAT < 0x1000L) /* Major version numbers up to 16777215 */
65 # define OPENSSL_API_LEVEL OPENSSL_API_COMPAT
66 # elif (OPENSSL_API_COMPAT & 0xF0000000L) == 0x00000000L
67 # define OPENSSL_API_LEVEL 0
68 # elif (OPENSSL_API_COMPAT & 0xFFF00000L) == 0x10000000L
69 # define OPENSSL_API_LEVEL 1
70 # elif (OPENSSL_API_COMPAT & 0xFFF00000L) == 0x10100000L
71 # define OPENSSL_API_LEVEL 2
73 /* Major number 3 to 15 */
74 # define OPENSSL_API_LEVEL ((OPENSSL_API_COMPAT >> 28) & 0xF)
79 * Define API level check macros up to what makes sense. Since we
80 * do future deprecations, we define one API level beyond the current
81 * major version number.
84 # if OPENSSL_API_LEVEL < 4
85 # define DEPRECATEDIN_4(f) DECLARE_DEPRECATED(f)
86 # define OPENSSL_API_4 0
88 # define DEPRECATEDIN_4(f)
89 # define OPENSSL_API_4 1
92 # if OPENSSL_API_LEVEL < 3
93 # define DEPRECATEDIN_3(f) DECLARE_DEPRECATED(f)
94 # define OPENSSL_API_3 0
96 # define DEPRECATEDIN_3(f)
97 # define OPENSSL_API_3 1
100 # if OPENSSL_API_LEVEL < 2
101 # define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f)
102 # define OPENSSL_API_1_1_0 0
104 # define DEPRECATEDIN_1_1_0(f)
105 # define OPENSSL_API_1_1_0 1
108 # if OPENSSL_API_LEVEL < 1
109 # define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f)
110 # define OPENSSL_API_1_0_0 0
112 # define DEPRECATEDIN_1_0_0(f)
113 # define OPENSSL_API_1_0_0 1
116 # if OPENSSL_API_LEVEL < 0
117 # define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f)
118 # define OPENSSL_API_0_9_8 0
120 # define DEPRECATEDIN_0_9_8(f)
121 # define OPENSSL_API_0_9_8 1
124 # ifndef OPENSSL_FILE
125 # ifdef OPENSSL_NO_FILENAMES
126 # define OPENSSL_FILE ""
127 # define OPENSSL_LINE 0
129 # define OPENSSL_FILE __FILE__
130 # define OPENSSL_LINE __LINE__
134 # ifndef OPENSSL_FUNC
135 # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
136 # define OPENSSL_FUNC __func__
137 # elif defined(__STDC__) && defined(PEDANTIC)
138 # define OPENSSL_FUNC "(PEDANTIC disallows function name)"
139 # elif defined(_MSC_VER) || (defined(__GNUC__) && __GNUC__ >= 2)
140 # define OPENSSL_FUNC __FUNCTION__
141 # elif defined(__FUNCSIG__)
142 # define OPENSSL_FUNC __FUNCSIG__
144 # define OPENSSL_FUNC "(unknown function)"
148 #endif /* OPENSSL_MACROS_H */