xref: /freebsd/contrib/llvm-project/clang/lib/Headers/stdarg.h (revision 725a9f47324d42037db93c27ceb40d4956872f3e)
1 /*===---- stdarg.h - Variable argument handling ----------------------------===
2  *
3  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4  * See https://llvm.org/LICENSE.txt for license information.
5  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6  *
7  *===-----------------------------------------------------------------------===
8  */
9 
10 /*
11  * This header is designed to be included multiple times. If any of the __need_
12  * macros are defined, then only that subset of interfaces are provided. This
13  * can be useful for POSIX headers that need to not expose all of stdarg.h, but
14  * need to use some of its interfaces. Otherwise this header provides all of
15  * the expected interfaces.
16  *
17  * When clang modules are enabled, this header is a textual header. It ignores
18  * its header guard so that multiple submodules can export its interfaces.
19  * Take module SM with submodules A and B, whose headers both include stdarg.h
20  * When SM.A builds, __STDARG_H will be defined. When SM.B builds, the
21  * definition from SM.A will leak when building without local submodule
22  * visibility. stdarg.h wouldn't include any of its implementation headers, and
23  * SM.B wouldn't import any of the stdarg modules, and SM.B's `export *`
24  * wouldn't export any stdarg interfaces as expected. However, since stdarg.h
25  * ignores its header guard when building with modules, it all works as
26  * expected.
27  *
28  * When clang modules are not enabled, the header guards can function in the
29  * normal simple fashion.
30  */
31 #if !defined(__STDARG_H) || __has_feature(modules) ||                          \
32     defined(__need___va_list) || defined(__need_va_list) ||                    \
33     defined(__need_va_arg) || defined(__need___va_copy) ||                     \
34     defined(__need_va_copy)
35 
36 #if !defined(__need___va_list) && !defined(__need_va_list) &&                  \
37     !defined(__need_va_arg) && !defined(__need___va_copy) &&                   \
38     !defined(__need_va_copy)
39 #define __STDARG_H
40 #define __need___va_list
41 #define __need_va_list
42 #define __need_va_arg
43 #define __need___va_copy
44 /* GCC always defines __va_copy, but does not define va_copy unless in c99 mode
45  * or -ansi is not specified, since it was not part of C90.
46  */
47 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) ||              \
48     (defined(__cplusplus) && __cplusplus >= 201103L) ||                        \
49     !defined(__STRICT_ANSI__)
50 #define __need_va_copy
51 #endif
52 #endif
53 
54 #ifdef __need___va_list
55 #include <__stdarg___gnuc_va_list.h>
56 #undef __need___va_list
57 #endif /* defined(__need___va_list) */
58 
59 #ifdef __need_va_list
60 #include <__stdarg_va_list.h>
61 #undef __need_va_list
62 #endif /* defined(__need_va_list) */
63 
64 #ifdef __need_va_arg
65 #include <__stdarg_va_arg.h>
66 #undef __need_va_arg
67 #endif /* defined(__need_va_arg) */
68 
69 #ifdef __need___va_copy
70 #include <__stdarg___va_copy.h>
71 #undef __need___va_copy
72 #endif /* defined(__need___va_copy) */
73 
74 #ifdef __need_va_copy
75 #include <__stdarg_va_copy.h>
76 #undef __need_va_copy
77 #endif /* defined(__need_va_copy) */
78 
79 #endif
80