diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt index 83717616e313..e55407d340bb 100644 --- a/libc/config/baremetal/arm/entrypoints.txt +++ b/libc/config/baremetal/arm/entrypoints.txt @@ -312,6 +312,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.wctype.iswblank libc.src.wctype.iswxdigit libc.src.wctype.iswpunct + libc.src.wctype.iswprint # internal entrypoints libc.startup.baremetal.init libc.startup.baremetal.fini diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt index 3c922062d2f8..654786b919c2 100644 --- a/libc/config/baremetal/riscv/entrypoints.txt +++ b/libc/config/baremetal/riscv/entrypoints.txt @@ -309,6 +309,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.wctype.iswblank libc.src.wctype.iswxdigit libc.src.wctype.iswpunct + libc.src.wctype.iswprint # internal entrypoints libc.startup.baremetal.init diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt index 11f142266d9a..d365708b950a 100644 --- a/libc/config/darwin/aarch64/entrypoints.txt +++ b/libc/config/darwin/aarch64/entrypoints.txt @@ -112,6 +112,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.wctype.iswblank libc.src.wctype.iswxdigit libc.src.wctype.iswpunct + libc.src.wctype.iswprint ) if(LLVM_LIBC_FULL_BUILD) diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index 92cf42a29626..e6c903089884 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -383,6 +383,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.wctype.iswblank libc.src.wctype.iswxdigit libc.src.wctype.iswpunct + libc.src.wctype.iswprint # sys/uio.h entrypoints libc.src.sys.uio.writev diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt index 737d6fcc6016..91fa524cc0d6 100644 --- a/libc/config/linux/arm/entrypoints.txt +++ b/libc/config/linux/arm/entrypoints.txt @@ -204,6 +204,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.wctype.iswblank libc.src.wctype.iswxdigit libc.src.wctype.iswpunct + libc.src.wctype.iswprint ) if(LLVM_LIBC_FULL_BUILD) diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt index 312329895e08..ba97e5c2035b 100644 --- a/libc/config/linux/riscv/entrypoints.txt +++ b/libc/config/linux/riscv/entrypoints.txt @@ -387,6 +387,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.wctype.iswblank libc.src.wctype.iswxdigit libc.src.wctype.iswpunct + libc.src.wctype.iswprint # sys/uio.h entrypoints libc.src.sys.uio.writev diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index e76f2f2ee523..a58e68d47c1e 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -437,6 +437,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.wctype.iswblank libc.src.wctype.iswxdigit libc.src.wctype.iswpunct + libc.src.wctype.iswprint # sys/uio.h entrypoints libc.src.sys.uio.writev diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt index 089cd1c8ede8..a1803d65d1b4 100644 --- a/libc/config/windows/entrypoints.txt +++ b/libc/config/windows/entrypoints.txt @@ -118,6 +118,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.wctype.iswblank libc.src.wctype.iswxdigit libc.src.wctype.iswpunct + libc.src.wctype.iswprint ) set(TARGET_LIBM_ENTRYPOINTS diff --git a/libc/include/wctype.yaml b/libc/include/wctype.yaml index 170eac48e734..932ff6ac1b13 100644 --- a/libc/include/wctype.yaml +++ b/libc/include/wctype.yaml @@ -68,3 +68,9 @@ functions: return_type: int arguments: - type: wint_t + - name: iswprint + standards: + - stdc + return_type: int + arguments: + - type: wint_t diff --git a/libc/src/wctype/CMakeLists.txt b/libc/src/wctype/CMakeLists.txt index d22d21eb487f..07bfed39980c 100644 --- a/libc/src/wctype/CMakeLists.txt +++ b/libc/src/wctype/CMakeLists.txt @@ -5,7 +5,7 @@ add_entrypoint_object( HDRS iswalpha.h DEPENDS - libc.src.__support.wctype_utils + libc.src.__support.wctype_utils ) add_entrypoint_object( @@ -119,3 +119,14 @@ add_entrypoint_object( libc.src.__support.wctype_utils libc.hdr.types.wint_t ) + +add_entrypoint_object( + iswprint + SRCS + iswprint.cpp + HDRS + iswprint.h + DEPENDS + libc.src.__support.wctype_utils + libc.hdr.types.wint_t +) diff --git a/libc/src/wctype/iswprint.cpp b/libc/src/wctype/iswprint.cpp new file mode 100644 index 000000000000..b291a52054e1 --- /dev/null +++ b/libc/src/wctype/iswprint.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of iswprint ----------------------------------------===// +// +// 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/wctype/iswprint.h" +#include "src/__support/common.h" +#include "src/__support/wctype_utils.h" + +#include "hdr/types/wint_t.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(int, iswprint, (wint_t c)) { + return internal::isprint(static_cast(c)); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/wctype/iswprint.h b/libc/src/wctype/iswprint.h new file mode 100644 index 000000000000..e848bcca2acc --- /dev/null +++ b/libc/src/wctype/iswprint.h @@ -0,0 +1,21 @@ +//===-- Implementation header for iswprint ----------------------*- 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_WCTYPE_ISWPRINT_H +#define LLVM_LIBC_SRC_WCTYPE_ISWPRINT_H + +#include "hdr/types/wint_t.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE_DECL { + +int iswprint(wint_t c); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_WCTYPE_ISWPRINT_H diff --git a/libc/test/src/wctype/CMakeLists.txt b/libc/test/src/wctype/CMakeLists.txt index 132d74daaac7..a5f85856dfb3 100644 --- a/libc/test/src/wctype/CMakeLists.txt +++ b/libc/test/src/wctype/CMakeLists.txt @@ -111,3 +111,13 @@ add_libc_test( DEPENDS libc.src.wctype.iswpunct ) + +add_libc_test( + iswprint_test + SUITE + libc_wctype_unittests + SRCS + iswprint_test.cpp + DEPENDS + libc.src.wctype.iswprint +) diff --git a/libc/test/src/wctype/iswprint_test.cpp b/libc/test/src/wctype/iswprint_test.cpp new file mode 100644 index 000000000000..6f5dfc4e0a60 --- /dev/null +++ b/libc/test/src/wctype/iswprint_test.cpp @@ -0,0 +1,21 @@ +//===-- Unittests for iswprint --------------------------------------------===// +// +// 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/wctype/iswprint.h" + +#include "test/UnitTest/Test.h" + +TEST(LlvmLibciswprint, SimpleTest) { + for (int ch = -255; ch < 255; ++ch) { + if (' ' <= ch && ch <= '~') { + EXPECT_NE(LIBC_NAMESPACE::iswprint(ch), 0); + } else { + EXPECT_EQ(LIBC_NAMESPACE::iswprint(ch), 0); + } + } +}