Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,13 @@ def StdC : StandardSpec<"stdc"> {
RetValSpec<IntType>,
[ArgSpec<IntType>, ArgSpec<FILEPtr>]
>,
FunctionSpec<
"vasprintf",
RetValSpec<IntType>,
[ArgSpec<CharRestrictedPtrPtr>,
ArgSpec<ConstCharPtr>,
ArgSpec<VaListType>]
>,
],
[
ObjectSpec<
Expand Down
10 changes: 10 additions & 0 deletions libc/src/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ add_entrypoint_object(
libc.src.stdio.printf_core.vfprintf_internal
)

add_entrypoint_object(
vasprintf
SRCS
vasprintf.cpp
HDRS
vasprintf.h
DEPENDS
libc.src.__support.arg_list
)

add_stdio_entrypoint_object(
fileno
SRCS
Expand Down
26 changes: 26 additions & 0 deletions libc/src/stdio/vasprintf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===-- Implementation of vasprintf -----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/stdio/vasprintf.h"

#include "src/__support/arg_list.h"

#include <stdarg.h>
#include <stdio.h>

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(int, vasprintf,
(char **__restrict, const char *, va_list vlist)) {
internal::ArgList args(vlist); // This holder class allows for easier copying
// and pointer semantics, as well as handling
// destruction automatically.
return -1;
}

} // namespace LIBC_NAMESPACE
21 changes: 21 additions & 0 deletions libc/src/stdio/vasprintf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header of vasprintf ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_STDIO_VASPRINTF_H
#define LLVM_LIBC_SRC_STDIO_VASPRINTF_H

#include <stdarg.h>
#include <stdio.h>

namespace LIBC_NAMESPACE {

int vasprintf(char **__restrict s, const char *format, va_list vlist);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_STDIO_VASPRINTF_H