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 #ifndef OPENSSL_MACROS_H
11 # define OPENSSL_MACROS_H
14 * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers
15 * don't like that. This will hopefully silence them.
17 # define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy;
20 * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the
21 * declarations of functions deprecated in or before <version>. If this is
22 * undefined, the value of the macro OPENSSL_API_MIN above is the default.
24 * For any version number up until version 1.1.x, <version> is expected to be
25 * the calculated version number 0xMNNFFPPSL. For version numbers 3.0.0 and
26 * on, <version> is expected to be only the major version number (i.e. 3 for
29 # ifndef DECLARE_DEPRECATED
30 # define DECLARE_DEPRECATED(f) f;
32 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
33 # undef DECLARE_DEPRECATED
34 # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated));
36 # elif defined(__SUNPRO_C)
37 # if (__SUNPRO_C >= 0x5130)
38 # undef DECLARE_DEPRECATED
39 # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated));
45 * We convert the OPENSSL_API_COMPAT value to an API level. The API level
46 * is the major version number for 3.0.0 and on. For earlier versions, it
47 * uses this scheme, which is close enough for our purposes:
49 * 0.x.y 0 (0.9.8 was the last release in this series)
50 * 1.0.x 1 (1.0.2 was the last release in this series)
51 * 1.1.x 2 (1.1.1 was the last release in this series)
54 /* In case someone defined both */
55 # if defined(OPENSSL_API_COMPAT) && defined(OPENSSL_API_LEVEL)
56 # error "Disallowed to define both OPENSSL_API_COMPAT and OPENSSL_API_LEVEL"
59 # ifndef OPENSSL_API_COMPAT
60 # define OPENSSL_API_LEVEL OPENSSL_MIN_API
62 # if (OPENSSL_API_COMPAT < 0x1000L) /* Major version numbers up to 16777215 */
63 # define OPENSSL_API_LEVEL OPENSSL_API_COMPAT
64 # elif (OPENSSL_API_COMPAT & 0xF0000000L) == 0x00000000L
65 # define OPENSSL_API_LEVEL 0
66 # elif (OPENSSL_API_COMPAT & 0xFFF00000L) == 0x10000000L
67 # define OPENSSL_API_LEVEL 1
68 # elif (OPENSSL_API_COMPAT & 0xFFF00000L) == 0x10100000L
69 # define OPENSSL_API_LEVEL 2
71 /* Major number 3 to 15 */
72 # define OPENSSL_API_LEVEL ((OPENSSL_API_COMPAT >> 28) & 0xF)
77 * Do not deprecate things to be deprecated in version 4.0 before the
78 * OpenSSL version number matches.
80 # if OPENSSL_VERSION_MAJOR < 4
81 # define DEPRECATEDIN_4(f) f;
82 # define OPENSSL_API_4 0
83 # elif OPENSSL_API_LEVEL < 4
84 # define DEPRECATEDIN_4(f) DECLARE_DEPRECATED(f)
85 # define OPENSSL_API_4 0
87 # define DEPRECATEDIN_4(f)
88 # define OPENSSL_API_4 1
91 # if OPENSSL_API_LEVEL < 3
92 # define DEPRECATEDIN_3(f) DECLARE_DEPRECATED(f)
93 # define OPENSSL_API_3 0
95 # define DEPRECATEDIN_3(f)
96 # define OPENSSL_API_3 1
99 # if OPENSSL_API_LEVEL < 2
100 # define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f)
101 # define OPENSSL_API_1_1_0 0
103 # define DEPRECATEDIN_1_1_0(f)
104 # define OPENSSL_API_1_1_0 1
107 # if OPENSSL_API_LEVEL < 1
108 # define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f)
109 # define OPENSSL_API_1_0_0 0
111 # define DEPRECATEDIN_1_0_0(f)
112 # define OPENSSL_API_1_0_0 1
115 # if OPENSSL_API_LEVEL < 0
116 # define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f)
117 # define OPENSSL_API_0_9_8 0
119 # define DEPRECATEDIN_0_9_8(f)
120 # define OPENSSL_API_0_9_8 1
123 # ifndef OPENSSL_FILE
124 # ifdef OPENSSL_NO_FILENAMES
125 # define OPENSSL_FILE ""
126 # define OPENSSL_LINE 0
128 # define OPENSSL_FILE __FILE__
129 # define OPENSSL_LINE __LINE__
133 # ifndef OPENSSL_FUNC
134 # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
135 # define OPENSSL_FUNC __func__
136 # elif defined(__STDC__) && defined(PEDANTIC)
137 # define OPENSSL_FUNC "(PEDANTIC disallows function name)"
138 # elif defined(_MSC_VER) || (defined(__GNUC__) && __GNUC__ >= 2)
139 # define OPENSSL_FUNC __FUNCTION__
140 # elif defined(__FUNCSIG__)
141 # define OPENSSL_FUNC __FUNCSIG__
143 # define OPENSSL_FUNC "(unknown function)"
147 #endif /* OPENSSL_MACROS_H */