]>
Commit | Line | Data |
---|---|---|
e039ca38 RL |
1 | /* |
2 | * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. | |
3 | * | |
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 | |
8 | */ | |
9 | ||
d6e9ddac RL |
10 | #include <openssl/opensslconf.h> |
11 | ||
e039ca38 RL |
12 | #ifndef OPENSSL_MACROS_H |
13 | # define OPENSSL_MACROS_H | |
14 | ||
15 | /* | |
16 | * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers | |
17 | * don't like that. This will hopefully silence them. | |
18 | */ | |
19 | # define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy; | |
20 | ||
21 | /* | |
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. | |
25 | * | |
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 | |
29 | * version 3.0.0). | |
30 | */ | |
31 | # ifndef DECLARE_DEPRECATED | |
32 | # define DECLARE_DEPRECATED(f) f; | |
33 | # ifdef __GNUC__ | |
34 | # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0) | |
35 | # undef DECLARE_DEPRECATED | |
36 | # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated)); | |
a42cb4ba VK |
37 | # endif |
38 | # elif defined(__SUNPRO_C) | |
39 | # if (__SUNPRO_C >= 0x5130) | |
40 | # undef DECLARE_DEPRECATED | |
41 | # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated)); | |
e039ca38 RL |
42 | # endif |
43 | # endif | |
44 | # endif | |
45 | ||
46 | /* | |
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: | |
50 | * | |
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) | |
54 | */ | |
55 | ||
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" | |
59 | # endif | |
60 | ||
61 | # ifndef OPENSSL_API_COMPAT | |
62 | # define OPENSSL_API_LEVEL OPENSSL_MIN_API | |
63 | # else | |
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 | |
72 | # else | |
73 | /* Major number 3 to 15 */ | |
74 | # define OPENSSL_API_LEVEL ((OPENSSL_API_COMPAT >> 28) & 0xF) | |
75 | # endif | |
76 | # endif | |
77 | ||
78 | /* | |
d6e9ddac RL |
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. | |
e039ca38 | 82 | */ |
d6e9ddac RL |
83 | |
84 | # if OPENSSL_API_LEVEL < 4 | |
e039ca38 RL |
85 | # define DEPRECATEDIN_4(f) DECLARE_DEPRECATED(f) |
86 | # define OPENSSL_API_4 0 | |
87 | # else | |
88 | # define DEPRECATEDIN_4(f) | |
89 | # define OPENSSL_API_4 1 | |
90 | # endif | |
91 | ||
92 | # if OPENSSL_API_LEVEL < 3 | |
93 | # define DEPRECATEDIN_3(f) DECLARE_DEPRECATED(f) | |
94 | # define OPENSSL_API_3 0 | |
95 | # else | |
96 | # define DEPRECATEDIN_3(f) | |
97 | # define OPENSSL_API_3 1 | |
98 | # endif | |
99 | ||
100 | # if OPENSSL_API_LEVEL < 2 | |
101 | # define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f) | |
102 | # define OPENSSL_API_1_1_0 0 | |
103 | # else | |
104 | # define DEPRECATEDIN_1_1_0(f) | |
105 | # define OPENSSL_API_1_1_0 1 | |
106 | # endif | |
107 | ||
108 | # if OPENSSL_API_LEVEL < 1 | |
109 | # define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f) | |
110 | # define OPENSSL_API_1_0_0 0 | |
111 | # else | |
112 | # define DEPRECATEDIN_1_0_0(f) | |
113 | # define OPENSSL_API_1_0_0 1 | |
114 | # endif | |
115 | ||
116 | # if OPENSSL_API_LEVEL < 0 | |
117 | # define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f) | |
118 | # define OPENSSL_API_0_9_8 0 | |
119 | # else | |
120 | # define DEPRECATEDIN_0_9_8(f) | |
121 | # define OPENSSL_API_0_9_8 1 | |
122 | # endif | |
123 | ||
124 | # ifndef OPENSSL_FILE | |
125 | # ifdef OPENSSL_NO_FILENAMES | |
126 | # define OPENSSL_FILE "" | |
127 | # define OPENSSL_LINE 0 | |
128 | # else | |
129 | # define OPENSSL_FILE __FILE__ | |
130 | # define OPENSSL_LINE __LINE__ | |
131 | # endif | |
132 | # endif | |
133 | ||
ec87a649 RL |
134 | /* |
135 | * __func__ was standardized in C99, so for any compiler that claims | |
136 | * to implement that language level or newer, we assume we can safely | |
137 | * use that symbol. | |
138 | * | |
139 | * GNU C also provides __FUNCTION__ since version 2, which predates | |
140 | * C99. We can, however, only use this if __STDC_VERSION__ exists, | |
141 | * as it's otherwise not allowed according to ISO C standards (C90). | |
142 | * (compiling with GNU C's -pedantic tells us so) | |
143 | * | |
144 | * If none of the above applies, we check if the compiler is MSVC, | |
145 | * and use __FUNCTION__ if that's the case. | |
146 | * | |
147 | * If all these possibilities are exhausted, we give up and use a | |
148 | * static string. | |
149 | */ | |
e039ca38 | 150 | # ifndef OPENSSL_FUNC |
ec87a649 RL |
151 | # if defined(__STDC_VERSION__) |
152 | # if __STDC_VERSION__ >= 199901L | |
153 | # define OPENSSL_FUNC __func__ | |
154 | # elif defined(__GNUC__) && __GNUC__ >= 2 | |
155 | # define OPENSSL_FUNC __FUNCTION__ | |
156 | # endif | |
157 | # elif defined(_MSC_VER) | |
158 | # define OPENSSL_FUNC __FUNCTION__ | |
e039ca38 RL |
159 | # else |
160 | # define OPENSSL_FUNC "(unknown function)" | |
161 | # endif | |
162 | # endif | |
163 | ||
164 | #endif /* OPENSSL_MACROS_H */ |