Skip to content

Commit

Permalink
[libc]: add vsscanf and vaprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
izaakschroeder committed Jul 2, 2024
1 parent 47aa763 commit 09af310
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdlib.strtoll_l
libc.src.ctype.isdigit_l
libc.src.ctype.isxdigit_l
libc.src.stdio.vsscanf
libc.src.stdio.vaprintf

)

Expand Down
2 changes: 2 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdlib.strtoll_l
libc.src.ctype.isdigit_l
libc.src.ctype.isxdigit_l
libc.src.stdio.vsscanf
libc.src.stdio.vaprintf
)

set(TARGET_LIBM_ENTRYPOINTS
Expand Down
14 changes: 14 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,20 @@ def StdC : StandardSpec<"stdc"> {
RetValSpec<IntType>,
[ArgSpec<IntType>, ArgSpec<FILEPtr>]
>,
FunctionSpec<
"vaprintf",
RetValSpec<IntType>,
[ArgSpec<CharPtr>,
ArgSpec<ConstCharPtr>,
ArgSpec<VaListType>]
>,
FunctionSpec<
"vsscanf",
RetValSpec<IntType>,
[ArgSpec<ConstCharPtr>,
ArgSpec<ConstCharPtr>,
ArgSpec<VaListType>]
>,
],
[
ObjectSpec<
Expand Down
20 changes: 20 additions & 0 deletions libc/src/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,26 @@ add_entrypoint_object(
libc.src.stdio.printf_core.vfprintf_internal
)

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

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

add_stdio_entrypoint_object(
fileno
SRCS
Expand Down
27 changes: 27 additions & 0 deletions libc/src/stdio/vaprintf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===-- Implementation of vaprintf ------------------------------*- 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/vaprintf.h"

#include "src/__support/arg_list.h"

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

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(int, vaprintf,
(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
22 changes: 22 additions & 0 deletions libc/src/stdio/vaprintf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Implementation header of vaprintf -----------------------*- 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_VAPRINTF_H
#define LLVM_LIBC_SRC_STDIO_VAPRINTF_H

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

namespace LIBC_NAMESPACE {

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

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_STDIO_VAPRINTF_H
28 changes: 28 additions & 0 deletions libc/src/stdio/vsscanf.cpp
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions libc/src/stdio/vsscanf.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 09af310

Please sign in to comment.