[libc-commits] [libc] [libc]: Add `vsscanf` function (PR #97529)

Izaak Schroeder via libc-commits libc-commits at lists.llvm.org
Tue Jul 2 23:56:35 PDT 2024


https://github.com/izaakschroeder created https://github.com/llvm/llvm-project/pull/97529

Still needs proper implementation, but stubs are here.

>From 48432beccb619caa3fe6c2fc9a0d6142262554b4 Mon Sep 17 00:00:00 2001
From: Izaak Schroeder <izaak.schroeder at gmail.com>
Date: Tue, 2 Jul 2024 23:55:25 -0700
Subject: [PATCH] [libc]: Add `vsscanf` function

---
 libc/spec/stdc.td             |  7 +++++++
 libc/src/stdio/CMakeLists.txt | 10 ++++++++++
 libc/src/stdio/vsscanf.cpp    | 28 ++++++++++++++++++++++++++++
 libc/src/stdio/vsscanf.h      | 21 +++++++++++++++++++++
 4 files changed, 66 insertions(+)
 create mode 100644 libc/src/stdio/vsscanf.cpp
 create mode 100644 libc/src/stdio/vsscanf.h

diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 9ff40bf76700c..0d35a1e3e6203 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<
+              "vsscanf",
+              RetValSpec<IntType>,
+              [ArgSpec<ConstCharPtr>,
+               ArgSpec<ConstCharPtr>,
+               ArgSpec<VaListType>]
+          >,
       ],
       [
           ObjectSpec<
diff --git a/libc/src/stdio/CMakeLists.txt b/libc/src/stdio/CMakeLists.txt
index a659d9e847a9e..3f1d97cad6afd 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(
+  vsscanf
+  SRCS
+    vsscanf.cpp
+  HDRS
+    vsscanf.h
+  DEPENDS
+    libc.src.__support.arg_list
+)
+
 add_stdio_entrypoint_object(
   fileno
   SRCS
diff --git a/libc/src/stdio/vsscanf.cpp b/libc/src/stdio/vsscanf.cpp
new file mode 100644
index 0000000000000..b5c9173387ea0
--- /dev/null
+++ b/libc/src/stdio/vsscanf.cpp
@@ -0,0 +1,28 @@
+//===-- Implementation of vsscanf -------------------------------*- 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/vsscanf.h"
+
+#include "src/__support/arg_list.h"
+
+#include <stdarg.h>
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(int, vsscanf,
+                   (const char *, 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/vsscanf.h b/libc/src/stdio/vsscanf.h
new file mode 100644
index 0000000000000..5f32f7ed351b1
--- /dev/null
+++ b/libc/src/stdio/vsscanf.h
@@ -0,0 +1,21 @@
+//===-- Implementation header of vsscanf ------------------------*- 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_VSSCANF_H
+#define LLVM_LIBC_SRC_STDIO_VSSCANF_H
+
+#include <stdarg.h>
+
+namespace LIBC_NAMESPACE {
+
+int vsscanf(const char * s, const char * format,
+             va_list vlist);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDIO_VSSCANF_H



More information about the libc-commits mailing list