1 /*===---- stdarg.h - Variable argument handling ----------------------------===
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
7 *===-----------------------------------------------------------------------===
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.
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
28 * When clang modules are not enabled, the header guards can function in the
29 * normal simple fashion.
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)
36 #if !defined(__need___va_list) && !defined(__need_va_list) && \
37 !defined(__need_va_arg) && !defined(__need___va_copy) && \
38 !defined(__need_va_copy)
40 #define __need___va_list
41 #define __need_va_list
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.
47 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
48 (defined(__cplusplus) && __cplusplus >= 201103L) || \
49 !defined(__STRICT_ANSI__)
50 #define __need_va_copy
54 #ifdef __need___va_list
55 #include <__stdarg___gnuc_va_list.h>
56 #undef __need___va_list
57 #endif /* defined(__need___va_list) */
60 #include <__stdarg_va_list.h>
62 #endif /* defined(__need_va_list) */
65 #include <__stdarg_va_arg.h>
67 #endif /* defined(__need_va_arg) */
69 #ifdef __need___va_copy
70 #include <__stdarg___va_copy.h>
71 #undef __need___va_copy
72 #endif /* defined(__need___va_copy) */
75 #include <__stdarg_va_copy.h>
77 #endif /* defined(__need_va_copy) */