1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* C++ compatible function declaration macros.
4 Copyright (C) 2010 Free Software Foundation, Inc.
6 This program is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* The three most frequent use cases of these macros are:
24 * For providing a substitute for a function that is missing on some
25 platforms, but is declared and works fine on the platforms on which
30 _GL_FUNCDECL_SYS (foo, ...);
32 _GL_CXXALIAS_SYS (foo, ...);
33 _GL_CXXALIASWARN (foo);
34 #elif defined GNULIB_POSIXCHECK
38 * For providing a replacement for a function that exists on all platforms,
39 but is broken/insufficient and needs to be replaced on some platforms:
43 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
47 _GL_FUNCDECL_RPL (foo, ...);
48 _GL_CXXALIAS_RPL (foo, ...);
50 _GL_CXXALIAS_SYS (foo, ...);
52 _GL_CXXALIASWARN (foo);
53 #elif defined GNULIB_POSIXCHECK
57 * For providing a replacement for a function that exists on some platforms
58 but is broken/insufficient and needs to be replaced on some of them and
59 is additionally either missing or undeclared on some other platforms:
63 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
67 _GL_FUNCDECL_RPL (foo, ...);
68 _GL_CXXALIAS_RPL (foo, ...);
70 # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
71 _GL_FUNCDECL_SYS (foo, ...);
73 _GL_CXXALIAS_SYS (foo, ...);
75 _GL_CXXALIASWARN (foo);
76 #elif defined GNULIB_POSIXCHECK
81 /* _GL_EXTERN_C declaration;
82 performs the declaration with C linkage. */
83 #if defined __cplusplus
84 # define _GL_EXTERN_C extern "C"
86 # define _GL_EXTERN_C extern
89 /* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
90 declares a replacement function, named rpl_func, with the given prototype,
91 consisting of return type, parameters, and attributes.
93 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
94 _GL_ARG_NONNULL ((1)));
96 #define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
97 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
98 #define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
99 _GL_EXTERN_C rettype rpl_func parameters_and_attributes
101 /* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
102 declares the system function, named func, with the given prototype,
103 consisting of return type, parameters, and attributes.
105 _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
106 _GL_ARG_NONNULL ((1)));
108 #define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
109 _GL_EXTERN_C rettype func parameters_and_attributes
111 /* _GL_CXXALIAS_RPL (func, rettype, parameters);
112 declares a C++ alias called GNULIB_NAMESPACE::func
113 that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
115 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
117 #define _GL_CXXALIAS_RPL(func,rettype,parameters) \
118 _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
119 #if defined __cplusplus && defined GNULIB_NAMESPACE
120 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
121 namespace GNULIB_NAMESPACE \
123 rettype (*const func) parameters = ::rpl_func; \
125 _GL_EXTERN_C int _gl_cxxalias_dummy
127 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
128 _GL_EXTERN_C int _gl_cxxalias_dummy
131 /* _GL_CXXALIAS_SYS (func, rettype, parameters);
132 declares a C++ alias called GNULIB_NAMESPACE::func
133 that redirects to the system provided function func, if GNULIB_NAMESPACE
136 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
138 #if defined __cplusplus && defined GNULIB_NAMESPACE
139 /* If we were to write
140 rettype (*const func) parameters = ::func;
141 like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
142 better (remove an indirection through a 'static' pointer variable),
143 but then the _GL_CXXALIASWARN macro below would cause a warning not only
144 for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
145 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
146 namespace GNULIB_NAMESPACE \
148 static rettype (*func) parameters = ::func; \
150 _GL_EXTERN_C int _gl_cxxalias_dummy
152 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
153 _GL_EXTERN_C int _gl_cxxalias_dummy
156 /* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
157 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
158 except that the C function func may have a slightly different declaration.
159 A cast is used to silence the "invalid conversion" error that would
161 #if defined __cplusplus && defined GNULIB_NAMESPACE
162 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
163 namespace GNULIB_NAMESPACE \
165 static rettype (*func) parameters = \
166 reinterpret_cast<rettype(*)parameters>(::func); \
168 _GL_EXTERN_C int _gl_cxxalias_dummy
170 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
171 _GL_EXTERN_C int _gl_cxxalias_dummy
174 /* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
175 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
176 except that the C function is picked among a set of overloaded functions,
177 namely the one with rettype2 and parameters2. Two consecutive casts
178 are used to silence the "cannot find a match" and "invalid conversion"
179 errors that would otherwise occur. */
180 #if defined __cplusplus && defined GNULIB_NAMESPACE
181 # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
182 namespace GNULIB_NAMESPACE \
184 static rettype (*func) parameters = \
185 reinterpret_cast<rettype(*)parameters>( \
186 reinterpret_cast<rettype2(*)parameters2>(::func)); \
188 _GL_EXTERN_C int _gl_cxxalias_dummy
190 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
191 _GL_EXTERN_C int _gl_cxxalias_dummy
194 /* _GL_CXXALIASWARN (func);
195 causes a warning to be emitted when ::func is used but not when
196 GNULIB_NAMESPACE::func is used. */
197 #if defined __cplusplus && defined GNULIB_NAMESPACE
198 # define _GL_CXXALIASWARN(func) \
199 _GL_CXXALIASWARN1 (func, GNULIB_NAMESPACE)
200 # define _GL_CXXALIASWARN1(func,namespace) \
201 _GL_CXXALIASWARN2 (func, namespace)
202 # define _GL_CXXALIASWARN2(func,namespace) \
203 _GL_WARN_ON_USE (func, \
204 "The symbol ::" #func " refers to the system function. " \
205 "Use " #namespace "::" #func " instead.")
207 # define _GL_CXXALIASWARN(func) \
208 _GL_EXTERN_C int _gl_cxxalias_dummy
211 #endif /* _GL_CXXDEFS_H */