[libc-commits] [libc] [libc] Add `vasprintf` function (PR #97528)
via libc-commits
libc-commits at lists.llvm.org
Tue Jul 2 23:54:38 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Izaak Schroeder (izaakschroeder)
<details>
<summary>Changes</summary>
Needs proper implementation, but the stubs are here.
---
Full diff: https://github.com/llvm/llvm-project/pull/97528.diff
4 Files Affected:
- (modified) libc/spec/stdc.td (+7)
- (modified) libc/src/stdio/CMakeLists.txt (+10)
- (added) libc/src/stdio/vasprintf.cpp (+27)
- (added) libc/src/stdio/vasprintf.h (+22)
``````````diff
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 9ff40bf76700c..6902bbfe14417 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -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<
diff --git a/libc/src/stdio/CMakeLists.txt b/libc/src/stdio/CMakeLists.txt
index a659d9e847a9e..300a97ca4377a 100644
--- a/libc/src/stdio/CMakeLists.txt
+++ b/libc/src/stdio/CMakeLists.txt
@@ -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
diff --git a/libc/src/stdio/vasprintf.cpp b/libc/src/stdio/vasprintf.cpp
new file mode 100644
index 0000000000000..d625d98e83706
--- /dev/null
+++ b/libc/src/stdio/vasprintf.cpp
@@ -0,0 +1,27 @@
+//===-- 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
diff --git a/libc/src/stdio/vasprintf.h b/libc/src/stdio/vasprintf.h
new file mode 100644
index 0000000000000..f9b1d85ef81fb
--- /dev/null
+++ b/libc/src/stdio/vasprintf.h
@@ -0,0 +1,22 @@
+//===-- 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
``````````
</details>
https://github.com/llvm/llvm-project/pull/97528
More information about the libc-commits
mailing list