mountlist: Add support for Minix.
[gnulib.git] / lib / cdefs.h
blobb1645312487cf0b66e007eb22f9d9092150040ff
1 /* Copyright (C) 1992-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #ifndef _SYS_CDEFS_H
19 #define _SYS_CDEFS_H 1
21 /* We are almost always included from features.h. */
22 #ifndef _FEATURES_H
23 # include <features.h>
24 #endif
26 /* The GNU libc does not support any K&R compilers or the traditional mode
27 of ISO C compilers anymore. Check for some of the combinations not
28 anymore supported. */
29 #if defined __GNUC__ && !defined __STDC__
30 # error "You need a ISO C conforming compiler to use the glibc headers"
31 #endif
33 /* Some user header file might have defined this before. */
34 #undef __P
35 #undef __PMT
37 #ifdef __GNUC__
39 /* All functions, except those with callbacks or those that
40 synchronize memory, are leaf functions. */
41 # if __GNUC_PREREQ (4, 6) && !defined _LIBC
42 # define __LEAF , __leaf__
43 # define __LEAF_ATTR __attribute__ ((__leaf__))
44 # else
45 # define __LEAF
46 # define __LEAF_ATTR
47 # endif
49 /* GCC can always grok prototypes. For C++ programs we add throw()
50 to help it optimize the function calls. But this works only with
51 gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
52 as non-throwing using a function attribute since programs can use
53 the -fexceptions options for C code as well. */
54 # if !defined __cplusplus && __GNUC_PREREQ (3, 3)
55 # define __THROW __attribute__ ((__nothrow__ __LEAF))
56 # define __THROWNL __attribute__ ((__nothrow__))
57 # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
58 # define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
59 # else
60 # if defined __cplusplus && __GNUC_PREREQ (2,8)
61 # define __THROW throw ()
62 # define __THROWNL throw ()
63 # define __NTH(fct) __LEAF_ATTR fct throw ()
64 # define __NTHNL(fct) fct throw ()
65 # else
66 # define __THROW
67 # define __THROWNL
68 # define __NTH(fct) fct
69 # define __NTHNL(fct) fct
70 # endif
71 # endif
73 #else /* Not GCC. */
75 # if (defined __cplusplus \
76 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
77 # define __inline inline
78 # else
79 # define __inline /* No inline functions. */
80 # endif
82 # define __THROW
83 # define __THROWNL
84 # define __NTH(fct) fct
86 #endif /* GCC. */
88 /* Compilers that are not clang may object to
89 #if defined __clang__ && __has_extension(...)
90 even though they do not need to evaluate the right-hand side of the &&. */
91 #if defined __clang__ && defined __has_extension
92 # define __glibc_clang_has_extension(ext) __has_extension (ext)
93 #else
94 # define __glibc_clang_has_extension(ext) 0
95 #endif
97 /* These two macros are not used in glibc anymore. They are kept here
98 only because some other projects expect the macros to be defined. */
99 #define __P(args) args
100 #define __PMT(args) args
102 /* For these things, GCC behaves the ANSI way normally,
103 and the non-ANSI way under -traditional. */
105 #define __CONCAT(x,y) x ## y
106 #define __STRING(x) #x
108 /* This is not a typedef so `const __ptr_t' does the right thing. */
109 #define __ptr_t void *
112 /* C++ needs to know that types and declarations are C, not C++. */
113 #ifdef __cplusplus
114 # define __BEGIN_DECLS extern "C" {
115 # define __END_DECLS }
116 #else
117 # define __BEGIN_DECLS
118 # define __END_DECLS
119 #endif
122 /* Fortify support. */
123 #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
124 #define __bos0(ptr) __builtin_object_size (ptr, 0)
126 #if __GNUC_PREREQ (4,3)
127 # define __warndecl(name, msg) \
128 extern void name (void) __attribute__((__warning__ (msg)))
129 # define __warnattr(msg) __attribute__((__warning__ (msg)))
130 # define __errordecl(name, msg) \
131 extern void name (void) __attribute__((__error__ (msg)))
132 #else
133 # define __warndecl(name, msg) extern void name (void)
134 # define __warnattr(msg)
135 # define __errordecl(name, msg) extern void name (void)
136 #endif
138 /* Support for flexible arrays.
139 Headers that should use flexible arrays only if they're "real"
140 (e.g. only if they won't affect sizeof()) should test
141 #if __glibc_c99_flexarr_available. */
142 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
143 # define __flexarr []
144 # define __glibc_c99_flexarr_available 1
145 #elif __GNUC_PREREQ (2,97)
146 /* GCC 2.97 supports C99 flexible array members as an extension,
147 even when in C89 mode or compiling C++ (any version). */
148 # define __flexarr []
149 # define __glibc_c99_flexarr_available 1
150 #elif defined __GNUC__
151 /* Pre-2.97 GCC did not support C99 flexible arrays but did have
152 an equivalent extension with slightly different notation. */
153 # define __flexarr [0]
154 # define __glibc_c99_flexarr_available 1
155 #else
156 /* Some other non-C99 compiler. Approximate with [1]. */
157 # define __flexarr [1]
158 # define __glibc_c99_flexarr_available 0
159 #endif
162 /* __asm__ ("xyz") is used throughout the headers to rename functions
163 at the assembly language level. This is wrapped by the __REDIRECT
164 macro, in order to support compilers that can do this some other
165 way. When compilers don't support asm-names at all, we have to do
166 preprocessor tricks instead (which don't have exactly the right
167 semantics, but it's the best we can do).
169 Example:
170 int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
172 #if defined __GNUC__ && __GNUC__ >= 2
174 # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
175 # ifdef __cplusplus
176 # define __REDIRECT_NTH(name, proto, alias) \
177 name proto __THROW __asm__ (__ASMNAME (#alias))
178 # define __REDIRECT_NTHNL(name, proto, alias) \
179 name proto __THROWNL __asm__ (__ASMNAME (#alias))
180 # else
181 # define __REDIRECT_NTH(name, proto, alias) \
182 name proto __asm__ (__ASMNAME (#alias)) __THROW
183 # define __REDIRECT_NTHNL(name, proto, alias) \
184 name proto __asm__ (__ASMNAME (#alias)) __THROWNL
185 # endif
186 # define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
187 # define __ASMNAME2(prefix, cname) __STRING (prefix) cname
190 #elif __SOME_OTHER_COMPILER__
192 # define __REDIRECT(name, proto, alias) name proto; \
193 _Pragma("let " #name " = " #alias)
195 #endif
197 /* GCC has various useful declarations that can be made with the
198 `__attribute__' syntax. All of the ways we use this do fine if
199 they are omitted for compilers that don't understand it. */
200 #if !defined __GNUC__ || __GNUC__ < 2
201 # define __attribute__(xyz) /* Ignore */
202 #endif
204 /* At some point during the gcc 2.96 development the `malloc' attribute
205 for functions was introduced. We don't want to use it unconditionally
206 (although this would be possible) since it generates warnings. */
207 #if __GNUC_PREREQ (2,96)
208 # define __attribute_malloc__ __attribute__ ((__malloc__))
209 #else
210 # define __attribute_malloc__ /* Ignore */
211 #endif
213 /* Tell the compiler which arguments to an allocation function
214 indicate the size of the allocation. */
215 #if __GNUC_PREREQ (4, 3)
216 # define __attribute_alloc_size__(params) \
217 __attribute__ ((__alloc_size__ params))
218 #else
219 # define __attribute_alloc_size__(params) /* Ignore. */
220 #endif
222 /* At some point during the gcc 2.96 development the `pure' attribute
223 for functions was introduced. We don't want to use it unconditionally
224 (although this would be possible) since it generates warnings. */
225 #if __GNUC_PREREQ (2,96)
226 # define __attribute_pure__ __attribute__ ((__pure__))
227 #else
228 # define __attribute_pure__ /* Ignore */
229 #endif
231 /* This declaration tells the compiler that the value is constant. */
232 #if __GNUC_PREREQ (2,5)
233 # define __attribute_const__ __attribute__ ((__const__))
234 #else
235 # define __attribute_const__ /* Ignore */
236 #endif
238 /* At some point during the gcc 3.1 development the `used' attribute
239 for functions was introduced. We don't want to use it unconditionally
240 (although this would be possible) since it generates warnings. */
241 #if __GNUC_PREREQ (3,1)
242 # define __attribute_used__ __attribute__ ((__used__))
243 # define __attribute_noinline__ __attribute__ ((__noinline__))
244 #else
245 # define __attribute_used__ __attribute__ ((__unused__))
246 # define __attribute_noinline__ /* Ignore */
247 #endif
249 /* Since version 3.2, gcc allows marking deprecated functions. */
250 #if __GNUC_PREREQ (3,2)
251 # define __attribute_deprecated__ __attribute__ ((__deprecated__))
252 #else
253 # define __attribute_deprecated__ /* Ignore */
254 #endif
256 /* Since version 4.5, gcc also allows one to specify the message printed
257 when a deprecated function is used. clang claims to be gcc 4.2, but
258 may also support this feature. */
259 #if __GNUC_PREREQ (4,5) || \
260 __glibc_clang_has_extension (__attribute_deprecated_with_message__)
261 # define __attribute_deprecated_msg__(msg) \
262 __attribute__ ((__deprecated__ (msg)))
263 #else
264 # define __attribute_deprecated_msg__(msg) __attribute_deprecated__
265 #endif
267 /* At some point during the gcc 2.8 development the `format_arg' attribute
268 for functions was introduced. We don't want to use it unconditionally
269 (although this would be possible) since it generates warnings.
270 If several `format_arg' attributes are given for the same function, in
271 gcc-3.0 and older, all but the last one are ignored. In newer gccs,
272 all designated arguments are considered. */
273 #if __GNUC_PREREQ (2,8)
274 # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
275 #else
276 # define __attribute_format_arg__(x) /* Ignore */
277 #endif
279 /* At some point during the gcc 2.97 development the `strfmon' format
280 attribute for functions was introduced. We don't want to use it
281 unconditionally (although this would be possible) since it
282 generates warnings. */
283 #if __GNUC_PREREQ (2,97)
284 # define __attribute_format_strfmon__(a,b) \
285 __attribute__ ((__format__ (__strfmon__, a, b)))
286 #else
287 # define __attribute_format_strfmon__(a,b) /* Ignore */
288 #endif
290 /* The nonnull function attribute marks pointer parameters that
291 must not be NULL. Do not define __nonnull if it is already defined,
292 for portability when this file is used in Gnulib. */
293 #ifndef __nonnull
294 # if __GNUC_PREREQ (3,3)
295 # define __nonnull(params) __attribute__ ((__nonnull__ params))
296 # else
297 # define __nonnull(params)
298 # endif
299 #endif
301 /* If fortification mode, we warn about unused results of certain
302 function calls which can lead to problems. */
303 #if __GNUC_PREREQ (3,4)
304 # define __attribute_warn_unused_result__ \
305 __attribute__ ((__warn_unused_result__))
306 # if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
307 # define __wur __attribute_warn_unused_result__
308 # endif
309 #else
310 # define __attribute_warn_unused_result__ /* empty */
311 #endif
312 #ifndef __wur
313 # define __wur /* Ignore */
314 #endif
316 /* Forces a function to be always inlined. */
317 #if __GNUC_PREREQ (3,2)
318 /* The Linux kernel defines __always_inline in stddef.h (283d7573), and
319 it conflicts with this definition. Therefore undefine it first to
320 allow either header to be included first. */
321 # undef __always_inline
322 # define __always_inline __inline __attribute__ ((__always_inline__))
323 #else
324 # undef __always_inline
325 # define __always_inline __inline
326 #endif
328 /* Associate error messages with the source location of the call site rather
329 than with the source location inside the function. */
330 #if __GNUC_PREREQ (4,3)
331 # define __attribute_artificial__ __attribute__ ((__artificial__))
332 #else
333 # define __attribute_artificial__ /* Ignore */
334 #endif
336 /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
337 inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__
338 or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions
339 older than 4.3 may define these macros and still not guarantee GNU inlining
340 semantics.
342 clang++ identifies itself as gcc-4.2, but has support for GNU inlining
343 semantics, that can be checked fot by using the __GNUC_STDC_INLINE_ and
344 __GNUC_GNU_INLINE__ macro definitions. */
345 #if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
346 || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
347 || defined __GNUC_GNU_INLINE__)))
348 # if defined __GNUC_STDC_INLINE__ || defined __cplusplus
349 # define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
350 # define __extern_always_inline \
351 extern __always_inline __attribute__ ((__gnu_inline__))
352 # else
353 # define __extern_inline extern __inline
354 # define __extern_always_inline extern __always_inline
355 # endif
356 #endif
358 #ifdef __extern_always_inline
359 # define __fortify_function __extern_always_inline __attribute_artificial__
360 #endif
362 /* GCC 4.3 and above allow passing all anonymous arguments of an
363 __extern_always_inline function to some other vararg function. */
364 #if __GNUC_PREREQ (4,3)
365 # define __va_arg_pack() __builtin_va_arg_pack ()
366 # define __va_arg_pack_len() __builtin_va_arg_pack_len ()
367 #endif
369 /* It is possible to compile containing GCC extensions even if GCC is
370 run in pedantic mode if the uses are carefully marked using the
371 `__extension__' keyword. But this is not generally available before
372 version 2.8. */
373 #if !__GNUC_PREREQ (2,8)
374 # define __extension__ /* Ignore */
375 #endif
377 /* __restrict is known in EGCS 1.2 and above. */
378 #if !__GNUC_PREREQ (2,92)
379 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
380 # define __restrict restrict
381 # else
382 # define __restrict /* Ignore */
383 # endif
384 #endif
386 /* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
387 array_name[restrict]
388 GCC 3.1 supports this. */
389 #if __GNUC_PREREQ (3,1) && !defined __GNUG__
390 # define __restrict_arr __restrict
391 #else
392 # ifdef __GNUC__
393 # define __restrict_arr /* Not supported in old GCC. */
394 # else
395 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
396 # define __restrict_arr restrict
397 # else
398 /* Some other non-C99 compiler. */
399 # define __restrict_arr /* Not supported. */
400 # endif
401 # endif
402 #endif
404 #if __GNUC__ >= 3
405 # define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
406 # define __glibc_likely(cond) __builtin_expect ((cond), 1)
407 #else
408 # define __glibc_unlikely(cond) (cond)
409 # define __glibc_likely(cond) (cond)
410 #endif
412 #if (!defined _Noreturn \
413 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
414 && !__GNUC_PREREQ (4,7))
415 # if __GNUC_PREREQ (2,8)
416 # define _Noreturn __attribute__ ((__noreturn__))
417 # else
418 # define _Noreturn
419 # endif
420 #endif
422 #if __GNUC_PREREQ (8, 0)
423 /* Describes a char array whose address can safely be passed as the first
424 argument to strncpy and strncat, as the char array is not necessarily
425 a NUL-terminated string. */
426 # define __attribute_nonstring__ __attribute__ ((__nonstring__))
427 #else
428 # define __attribute_nonstring__
429 #endif
431 #if (!defined _Static_assert && !defined __cplusplus \
432 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
433 && (!__GNUC_PREREQ (4, 6) || defined __STRICT_ANSI__))
434 # define _Static_assert(expr, diagnostic) \
435 extern int (*__Static_assert_function (void)) \
436 [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
437 #endif
439 /* The #ifndef lets Gnulib avoid including these on non-glibc
440 platforms, where the includes typically do not exist. */
441 #ifndef __WORDSIZE
442 # include <bits/wordsize.h>
443 # include <bits/long-double.h>
444 #endif
446 #if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
447 # define __LDBL_COMPAT 1
448 # ifdef __REDIRECT
449 # define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
450 # define __LDBL_REDIR(name, proto) \
451 __LDBL_REDIR1 (name, proto, __nldbl_##name)
452 # define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
453 # define __LDBL_REDIR_NTH(name, proto) \
454 __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
455 # define __LDBL_REDIR1_DECL(name, alias) \
456 extern __typeof (name) name __asm (__ASMNAME (#alias));
457 # define __LDBL_REDIR_DECL(name) \
458 extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
459 # define __REDIRECT_LDBL(name, proto, alias) \
460 __LDBL_REDIR1 (name, proto, __nldbl_##alias)
461 # define __REDIRECT_NTH_LDBL(name, proto, alias) \
462 __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
463 # endif
464 #endif
465 #if !defined __LDBL_COMPAT || !defined __REDIRECT
466 # define __LDBL_REDIR1(name, proto, alias) name proto
467 # define __LDBL_REDIR(name, proto) name proto
468 # define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
469 # define __LDBL_REDIR_NTH(name, proto) name proto __THROW
470 # define __LDBL_REDIR_DECL(name)
471 # ifdef __REDIRECT
472 # define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
473 # define __REDIRECT_NTH_LDBL(name, proto, alias) \
474 __REDIRECT_NTH (name, proto, alias)
475 # endif
476 #endif
478 /* __glibc_macro_warning (MESSAGE) issues warning MESSAGE. This is
479 intended for use in preprocessor macros.
481 Note: MESSAGE must be a _single_ string; concatenation of string
482 literals is not supported. */
483 #if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
484 # define __glibc_macro_warning1(message) _Pragma (#message)
485 # define __glibc_macro_warning(message) \
486 __glibc_macro_warning1 (GCC warning message)
487 #else
488 # define __glibc_macro_warning(msg)
489 #endif
491 /* Generic selection (ISO C11) is a C-only feature, available in GCC
492 since version 4.9. Previous versions do not provide generic
493 selection, even though they might set __STDC_VERSION__ to 201112L,
494 when in -std=c11 mode. Thus, we must check for !defined __GNUC__
495 when testing __STDC_VERSION__ for generic selection support.
496 On the other hand, Clang also defines __GNUC__, so a clang-specific
497 check is required to enable the use of generic selection. */
498 #if !defined __cplusplus \
499 && (__GNUC_PREREQ (4, 9) \
500 || __glibc_clang_has_extension (c_generic_selections) \
501 || (!defined __GNUC__ && defined __STDC_VERSION__ \
502 && __STDC_VERSION__ >= 201112L))
503 # define __HAVE_GENERIC_SELECTION 1
504 #else
505 # define __HAVE_GENERIC_SELECTION 0
506 #endif
508 #endif /* sys/cdefs.h */