1 /*
2 * Copyright (c) 2020 Dmitry V. Levin <ldv@altlinux.org>
3 */
4
5 #ifndef PAM_CC_COMPAT_H
6 #define PAM_CC_COMPAT_H
7
8 #include "config.h"
9 #include <security/_pam_types.h>
10
11 #if defined __clang__ && defined __clang_major__ && defined __clang_minor__
12 # define PAM_CLANG_PREREQ(maj, min) \
13 ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
14 #else
15 # define PAM_CLANG_PREREQ(maj, min) 0
16 #endif
17
18 #if PAM_GNUC_PREREQ(2, 7)
19 # define PAM_ATTRIBUTE_ALIGNED(arg) __attribute__((__aligned__(arg)))
20 #else
21 # define PAM_ATTRIBUTE_ALIGNED(arg) /* empty */
22 #endif
23
24 #if PAM_GNUC_PREREQ(4, 6)
25 # define DIAG_PUSH_IGNORE_CAST_QUAL \
26 _Pragma("GCC diagnostic push"); \
27 _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
28 # define DIAG_POP_IGNORE_CAST_QUAL \
29 _Pragma("GCC diagnostic pop")
30 # define DIAG_PUSH_IGNORE_CAST_ALIGN \
31 _Pragma("GCC diagnostic push"); \
32 _Pragma("GCC diagnostic ignored \"-Wcast-align\"")
33 # define DIAG_POP_IGNORE_CAST_ALIGN \
34 _Pragma("GCC diagnostic pop")
35 # define DIAG_PUSH_IGNORE_FORMAT_NONLITERAL \
36 _Pragma("GCC diagnostic push"); \
37 _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"")
38 # define DIAG_POP_IGNORE_FORMAT_NONLITERAL \
39 _Pragma("GCC diagnostic pop")
40 #elif PAM_CLANG_PREREQ(2, 6)
41 # define DIAG_PUSH_IGNORE_CAST_QUAL \
42 _Pragma("clang diagnostic push"); \
43 _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
44 # define DIAG_POP_IGNORE_CAST_QUAL \
45 _Pragma("clang diagnostic pop")
46 # define DIAG_PUSH_IGNORE_CAST_ALIGN \
47 _Pragma("clang diagnostic push"); \
48 _Pragma("clang diagnostic ignored \"-Wcast-align\"")
49 # define DIAG_POP_IGNORE_CAST_ALIGN \
50 _Pragma("clang diagnostic pop")
51 # define DIAG_PUSH_IGNORE_FORMAT_NONLITERAL \
52 _Pragma("clang diagnostic push"); \
53 _Pragma("clang diagnostic ignored \"-Wformat-nonliteral\"")
54 # define DIAG_POP_IGNORE_FORMAT_NONLITERAL \
55 _Pragma("clang diagnostic pop")
56 #else
57 # define DIAG_PUSH_IGNORE_CAST_QUAL /* empty */
58 # define DIAG_POP_IGNORE_CAST_QUAL /* empty */
59 # define DIAG_PUSH_IGNORE_CAST_ALIGN /* empty */
60 # define DIAG_POP_IGNORE_CAST_ALIGN /* empty */
61 # define DIAG_PUSH_IGNORE_FORMAT_NONLITERAL /* empty */
62 # define DIAG_POP_IGNORE_FORMAT_NONLITERAL /* empty */
63 #endif
64
65 /*
66 * Evaluates to
67 * 1, if the given two types are known to be the same
68 * 0, otherwise.
69 */
70 #if PAM_GNUC_PREREQ(3, 0)
71 # define PAM_IS_SAME_TYPE(x_, y_) \
72 __builtin_types_compatible_p(__typeof__(x_), __typeof__(y_))
73 #else
74 /* Cannot tell whether these types are the same. */
75 # define PAM_IS_SAME_TYPE(x_, y_) 0
76 #endif
77
78 #endif /* PAM_CC_COMPAT_H */