xref: /llvm-project/libc/src/stdio/generic/vprintf.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
111d643f0SMichael Jones //===-- Implementation of vprintf -------------------------------*- C++ -*-===//
211d643f0SMichael Jones //
311d643f0SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
411d643f0SMichael Jones // See https://llvm.org/LICENSE.txt for license information.
511d643f0SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
611d643f0SMichael Jones //
711d643f0SMichael Jones //===----------------------------------------------------------------------===//
811d643f0SMichael Jones 
911d643f0SMichael Jones #include "src/stdio/vprintf.h"
1011d643f0SMichael Jones 
1111d643f0SMichael Jones #include "src/__support/File/file.h"
1211d643f0SMichael Jones #include "src/__support/arg_list.h"
13*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
1411d643f0SMichael Jones #include "src/stdio/printf_core/vfprintf_internal.h"
1511d643f0SMichael Jones 
165aed6d67SMichael Jones #include "hdr/types/FILE.h"
1711d643f0SMichael Jones #include <stdarg.h>
1811d643f0SMichael Jones 
1911d643f0SMichael Jones #ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE
2011d643f0SMichael Jones #define PRINTF_STDOUT LIBC_NAMESPACE::stdout
2111d643f0SMichael Jones #else // LIBC_COPT_STDIO_USE_SYSTEM_FILE
2211d643f0SMichael Jones #define PRINTF_STDOUT ::stdout
2311d643f0SMichael Jones #endif // LIBC_COPT_STDIO_USE_SYSTEM_FILE
2411d643f0SMichael Jones 
25*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
2611d643f0SMichael Jones 
2711d643f0SMichael Jones LLVM_LIBC_FUNCTION(int, vprintf,
2811d643f0SMichael Jones                    (const char *__restrict format, va_list vlist)) {
2911d643f0SMichael Jones   internal::ArgList args(vlist); // This holder class allows for easier copying
3011d643f0SMichael Jones                                  // and pointer semantics, as well as handling
3111d643f0SMichael Jones                                  // destruction automatically.
3211d643f0SMichael Jones   int ret_val = printf_core::vfprintf_internal(
3311d643f0SMichael Jones       reinterpret_cast<::FILE *>(PRINTF_STDOUT), format, args);
3411d643f0SMichael Jones   return ret_val;
3511d643f0SMichael Jones }
3611d643f0SMichael Jones 
37*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
38