pam_cc_compat.h 2.0 KB

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