xref: /freebsd/contrib/pam-krb5/portable/macros.h (revision bf6873c5786e333d679a7838d28812febf479a8a)
1*bf6873c5SCy Schubert /*
2*bf6873c5SCy Schubert  * Portability macros used in include files.
3*bf6873c5SCy Schubert  *
4*bf6873c5SCy Schubert  * The canonical version of this file is maintained in the rra-c-util package,
5*bf6873c5SCy Schubert  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
6*bf6873c5SCy Schubert  *
7*bf6873c5SCy Schubert  * Written by Russ Allbery <eagle@eyrie.org>
8*bf6873c5SCy Schubert  * Copyright 2015 Russ Allbery <eagle@eyrie.org>
9*bf6873c5SCy Schubert  * Copyright 2008, 2011-2012
10*bf6873c5SCy Schubert  *     The Board of Trustees of the Leland Stanford Junior University
11*bf6873c5SCy Schubert  *
12*bf6873c5SCy Schubert  * Copying and distribution of this file, with or without modification, are
13*bf6873c5SCy Schubert  * permitted in any medium without royalty provided the copyright notice and
14*bf6873c5SCy Schubert  * this notice are preserved.  This file is offered as-is, without any
15*bf6873c5SCy Schubert  * warranty.
16*bf6873c5SCy Schubert  *
17*bf6873c5SCy Schubert  * SPDX-License-Identifier: FSFAP
18*bf6873c5SCy Schubert  */
19*bf6873c5SCy Schubert 
20*bf6873c5SCy Schubert #ifndef PORTABLE_MACROS_H
21*bf6873c5SCy Schubert #define PORTABLE_MACROS_H 1
22*bf6873c5SCy Schubert 
23*bf6873c5SCy Schubert /*
24*bf6873c5SCy Schubert  * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7
25*bf6873c5SCy Schubert  * could you use the __format__ form of the attributes, which is what we use
26*bf6873c5SCy Schubert  * (to avoid confusion with other macros).
27*bf6873c5SCy Schubert  */
28*bf6873c5SCy Schubert #ifndef __attribute__
29*bf6873c5SCy Schubert #    if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
30*bf6873c5SCy Schubert #        define __attribute__(spec) /* empty */
31*bf6873c5SCy Schubert #    endif
32*bf6873c5SCy Schubert #endif
33*bf6873c5SCy Schubert 
34*bf6873c5SCy Schubert /*
35*bf6873c5SCy Schubert  * We use __alloc_size__, but it was only available in fairly recent versions
36*bf6873c5SCy Schubert  * of GCC.  Suppress warnings about the unknown attribute if GCC is too old.
37*bf6873c5SCy Schubert  * We know that we're GCC at this point, so we can use the GCC variadic macro
38*bf6873c5SCy Schubert  * extension, which will still work with versions of GCC too old to have C99
39*bf6873c5SCy Schubert  * variadic macro support.
40*bf6873c5SCy Schubert  */
41*bf6873c5SCy Schubert #if !defined(__attribute__) && !defined(__alloc_size__)
42*bf6873c5SCy Schubert #    if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)) \
43*bf6873c5SCy Schubert         && !defined(__clang__)
44*bf6873c5SCy Schubert #        define __alloc_size__(spec, args...) /* empty */
45*bf6873c5SCy Schubert #    endif
46*bf6873c5SCy Schubert #endif
47*bf6873c5SCy Schubert 
48*bf6873c5SCy Schubert /*
49*bf6873c5SCy Schubert  * LLVM and Clang pretend to be GCC but don't support all of the __attribute__
50*bf6873c5SCy Schubert  * settings that GCC does.  For them, suppress warnings about unknown
51*bf6873c5SCy Schubert  * attributes on declarations.  This unfortunately will affect the entire
52*bf6873c5SCy Schubert  * compilation context, but there's no push and pop available.
53*bf6873c5SCy Schubert  */
54*bf6873c5SCy Schubert #if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__))
55*bf6873c5SCy Schubert #    pragma GCC diagnostic ignored "-Wattributes"
56*bf6873c5SCy Schubert #endif
57*bf6873c5SCy Schubert 
58*bf6873c5SCy Schubert /*
59*bf6873c5SCy Schubert  * BEGIN_DECLS is used at the beginning of declarations so that C++
60*bf6873c5SCy Schubert  * compilers don't mangle their names.  END_DECLS is used at the end.
61*bf6873c5SCy Schubert  */
62*bf6873c5SCy Schubert #undef BEGIN_DECLS
63*bf6873c5SCy Schubert #undef END_DECLS
64*bf6873c5SCy Schubert #ifdef __cplusplus
65*bf6873c5SCy Schubert #    define BEGIN_DECLS extern "C" {
66*bf6873c5SCy Schubert #    define END_DECLS   }
67*bf6873c5SCy Schubert #else
68*bf6873c5SCy Schubert #    define BEGIN_DECLS /* empty */
69*bf6873c5SCy Schubert #    define END_DECLS   /* empty */
70*bf6873c5SCy Schubert #endif
71*bf6873c5SCy Schubert 
72*bf6873c5SCy Schubert #endif /* !PORTABLE_MACROS_H */
73