diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 5036c9438a503..910bdc53cbbc5 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -1254,7 +1254,11 @@ if(LLVM_LIBC_FULL_BUILD) libc.src.stdlib.atexit libc.src.stdlib.exit libc.src.stdlib.getenv + libc.src.stdlib.mbstowcs + libc.src.stdlib.mbtowc libc.src.stdlib.quick_exit + libc.src.stdlib.wcstombs + libc.src.stdlib.wctomb # signal.h entrypoints libc.src.signal.kill @@ -1372,13 +1376,9 @@ if(LLVM_LIBC_FULL_BUILD) libc.src.wchar.mbrlen libc.src.wchar.mbsinit libc.src.wchar.mbrtowc - libc.src.wchar.mbtowc - libc.src.wchar.mbstowcs libc.src.wchar.mbsrtowcs libc.src.wchar.mbsnrtowcs libc.src.wchar.wcrtomb - libc.src.wchar.wctomb - libc.src.wchar.wcstombs libc.src.wchar.wcsrtombs libc.src.wchar.wcsnrtombs diff --git a/libc/include/stdlib.yaml b/libc/include/stdlib.yaml index 495eb7e1317b6..4752244279243 100644 --- a/libc/include/stdlib.yaml +++ b/libc/include/stdlib.yaml @@ -17,6 +17,7 @@ types: - type_name: lldiv_t - type_name: locale_t - type_name: size_t + - type_name: wchar_t enums: [] objects: [] functions: @@ -135,6 +136,22 @@ functions: arguments: - type: long long - type: long long + - name: mbstowcs + standards: + - stdc + return_type: size_t + arguments: + - type: wchar_t *__restrict + - type: const char *__restrict + - type: size_t + - name: mbtowc + standards: + - stdc + return_type: int + arguments: + - type: wchar_t *__restrict + - type: const char *__restrict + - type: size_t - name: memalignment standards: - stdc @@ -332,3 +349,18 @@ functions: return_type: int arguments: - type: const char * + - name: wctomb + standards: + - stdc + return_type: int + arguments: + - type: char * + - type: wchar_t + - name: wcstombs + standards: + - stdc + return_type: size_t + arguments: + - type: char *__restrict + - type: const wchar_t *__restrict + - type: size_t diff --git a/libc/include/wchar.yaml b/libc/include/wchar.yaml index a524c7f56bed0..7a94f9b542b7f 100644 --- a/libc/include/wchar.yaml +++ b/libc/include/wchar.yaml @@ -50,14 +50,6 @@ functions: - type: const char *__restrict - type: size_t - type: mbstate_t *__restrict - - name: mbtowc - standards: - - stdc - return_type: int - arguments: - - type: wchar_t *__restrict - - type: const char *__restrict - - type: size_t - name: mbsnrtowcs standards: - stdc @@ -77,14 +69,6 @@ functions: - type: const char **__restrict - type: size_t - type: mbstate_t *__restrict - - name: mbstowcs - standards: - - stdc - return_type: size_t - arguments: - - type: wchar_t *__restrict - - type: const char *__restrict - - type: size_t - name: mbsinit standards: - stdc @@ -269,13 +253,6 @@ functions: - type: char *__restrict - type: wchar_t - type: mbstate_t *__restrict - - name: wctomb - standards: - - stdc - return_type: int - arguments: - - type: char * - - type: wchar_t - name: wcscpy standards: - stdc @@ -336,14 +313,6 @@ functions: - type: const wchar_t *__restrict - type: wchar_t **__restrict - type: int - - name: wcstombs - standards: - - stdc - return_type: size_t - arguments: - - type: char *__restrict - - type: const wchar_t *__restrict - - type: size_t - name: wcstoul standards: - stdc diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt index 1ccdcc8bec148..62da469f0eb9e 100644 --- a/libc/src/stdlib/CMakeLists.txt +++ b/libc/src/stdlib/CMakeLists.txt @@ -368,6 +368,65 @@ add_entrypoint_object( libc.hdr.types.size_t ) +add_entrypoint_object( + mbtowc + SRCS + mbtowc.cpp + HDRS + mbtowc.h + DEPENDS + libc.hdr.types.size_t + libc.hdr.types.wchar_t + libc.src.__support.common + libc.src.__support.macros.config + libc.src.__support.libc_errno + libc.src.__support.wchar.mbrtowc + libc.src.__support.wchar.mbstate +) + +add_entrypoint_object( + mbstowcs + SRCS + mbstowcs.cpp + HDRS + mbstowcs.h + DEPENDS + libc.hdr.types.size_t + libc.hdr.types.wchar_t + libc.src.__support.common + libc.src.__support.macros.config + libc.src.__support.macros.null_check + libc.src.__support.libc_errno + libc.src.__support.wchar.mbstate + libc.src.__support.wchar.mbsnrtowcs +) + +add_entrypoint_object( + wctomb + SRCS + wctomb.cpp + HDRS + wctomb.h + DEPENDS + libc.hdr.types.wchar_t + libc.src.__support.wchar.wcrtomb + libc.src.__support.wchar.mbstate + libc.src.__support.libc_errno +) + +add_entrypoint_object( + wcstombs + SRCS + wcstombs.cpp + HDRS + wcstombs.h + DEPENDS + libc.hdr.types.wchar_t + libc.src.__support.wchar.mbstate + libc.src.__support.wchar.wcsnrtombs + libc.src.__support.libc_errno +) + if(NOT LIBC_TARGET_OS_IS_BAREMETAL AND NOT LIBC_TARGET_OS_IS_GPU) if(LLVM_LIBC_INCLUDE_SCUDO) set(SCUDO_DEPS "") diff --git a/libc/src/wchar/mbstowcs.cpp b/libc/src/stdlib/mbstowcs.cpp similarity index 97% rename from libc/src/wchar/mbstowcs.cpp rename to libc/src/stdlib/mbstowcs.cpp index 43e953cdf2ac2..6d283ea46e3b9 100644 --- a/libc/src/wchar/mbstowcs.cpp +++ b/libc/src/stdlib/mbstowcs.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/wchar/mbstowcs.h" +#include "src/stdlib/mbstowcs.h" #include "hdr/types/size_t.h" #include "hdr/types/wchar_t.h" diff --git a/libc/src/wchar/mbstowcs.h b/libc/src/stdlib/mbstowcs.h similarity index 83% rename from libc/src/wchar/mbstowcs.h rename to libc/src/stdlib/mbstowcs.h index 7d08a838b2324..90f8195a39ec5 100644 --- a/libc/src/wchar/mbstowcs.h +++ b/libc/src/stdlib/mbstowcs.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SRC_WCHAR_MBSTOWCS_H -#define LLVM_LIBC_SRC_WCHAR_MBSTOWCS_H +#ifndef LLVM_LIBC_SRC_STDLIB_MBSTOWCS_H +#define LLVM_LIBC_SRC_STDLIB_MBSTOWCS_H #include "hdr/types/size_t.h" #include "hdr/types/wchar_t.h" @@ -19,4 +19,4 @@ size_t mbstowcs(wchar_t *__restrict pwcs, const char *__restrict s, size_t n); } // namespace LIBC_NAMESPACE_DECL -#endif // LLVM_LIBC_SRC_WCHAR_MBSTOWCS_H +#endif // LLVM_LIBC_SRC_STDLIB_MBSTOWCS_H diff --git a/libc/src/wchar/mbtowc.cpp b/libc/src/stdlib/mbtowc.cpp similarity index 97% rename from libc/src/wchar/mbtowc.cpp rename to libc/src/stdlib/mbtowc.cpp index 6d099d43da5fa..5f482463f4711 100644 --- a/libc/src/wchar/mbtowc.cpp +++ b/libc/src/stdlib/mbtowc.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/wchar/mbtowc.h" +#include "src/stdlib/mbtowc.h" #include "hdr/types/size_t.h" #include "hdr/types/wchar_t.h" diff --git a/libc/src/wchar/mbtowc.h b/libc/src/stdlib/mbtowc.h similarity index 84% rename from libc/src/wchar/mbtowc.h rename to libc/src/stdlib/mbtowc.h index f974197f81b58..acd85cb77ba76 100644 --- a/libc/src/wchar/mbtowc.h +++ b/libc/src/stdlib/mbtowc.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SRC_WCHAR_MBTOWC_H -#define LLVM_LIBC_SRC_WCHAR_MBTOWC_H +#ifndef LLVM_LIBC_SRC_STDLIB_MBTOWC_H +#define LLVM_LIBC_SRC_STDLIB_MBTOWC_H #include "hdr/types/size_t.h" #include "hdr/types/wchar_t.h" @@ -19,4 +19,4 @@ int mbtowc(wchar_t *__restrict pwc, const char *__restrict s, size_t n); } // namespace LIBC_NAMESPACE_DECL -#endif // LLVM_LIBC_SRC_WCHAR_MBTOWC_H +#endif // LLVM_LIBC_SRC_STDLIB_MBTOWC_H diff --git a/libc/src/wchar/wcstombs.cpp b/libc/src/stdlib/wcstombs.cpp similarity index 97% rename from libc/src/wchar/wcstombs.cpp rename to libc/src/stdlib/wcstombs.cpp index c3793cbe912cd..712af958456de 100644 --- a/libc/src/wchar/wcstombs.cpp +++ b/libc/src/stdlib/wcstombs.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/wchar/wcstombs.h" +#include "src/stdlib/wcstombs.h" #include "hdr/types/char32_t.h" #include "hdr/types/size_t.h" diff --git a/libc/src/wchar/wcstombs.h b/libc/src/stdlib/wcstombs.h similarity index 83% rename from libc/src/wchar/wcstombs.h rename to libc/src/stdlib/wcstombs.h index cd0008a168d90..39515431098cb 100644 --- a/libc/src/wchar/wcstombs.h +++ b/libc/src/stdlib/wcstombs.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SRC_WCHAR_WCSTOMBS_H -#define LLVM_LIBC_SRC_WCHAR_WCSTOMBS_H +#ifndef LLVM_LIBC_SRC_STDLIB_WCSTOMBS_H +#define LLVM_LIBC_SRC_STDLIB_WCSTOMBS_H #include "hdr/types/size_t.h" #include "hdr/types/wchar_t.h" @@ -19,4 +19,4 @@ size_t wcstombs(char *__restrict s, const wchar_t *__restrict pwcs, size_t n); } // namespace LIBC_NAMESPACE_DECL -#endif // LLVM_LIBC_SRC_WCHAR_WCSTOMBS_H +#endif // LLVM_LIBC_SRC_STDLIB_WCSTOMBS_H diff --git a/libc/src/wchar/wctomb.cpp b/libc/src/stdlib/wctomb.cpp similarity index 97% rename from libc/src/wchar/wctomb.cpp rename to libc/src/stdlib/wctomb.cpp index 142302e6ae09b..0ca1a84cd923e 100644 --- a/libc/src/wchar/wctomb.cpp +++ b/libc/src/stdlib/wctomb.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/wchar/wctomb.h" +#include "src/stdlib/wctomb.h" #include "hdr/types/wchar_t.h" #include "src/__support/common.h" diff --git a/libc/src/wchar/wctomb.h b/libc/src/stdlib/wctomb.h similarity index 83% rename from libc/src/wchar/wctomb.h rename to libc/src/stdlib/wctomb.h index 02a34e5ad229f..90afa31d9e707 100644 --- a/libc/src/wchar/wctomb.h +++ b/libc/src/stdlib/wctomb.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SRC_WCHAR_WCTOMB_H -#define LLVM_LIBC_SRC_WCHAR_WCTOMB_H +#ifndef LLVM_LIBC_SRC_STDLIB_WCTOMB_H +#define LLVM_LIBC_SRC_STDLIB_WCTOMB_H #include "hdr/types/mbstate_t.h" #include "hdr/types/wchar_t.h" @@ -19,4 +19,4 @@ int wctomb(char *s, wchar_t wc); } // namespace LIBC_NAMESPACE_DECL -#endif // LLVM_LIBC_SRC_WCHAR_WCTOMB_H +#endif // LLVM_LIBC_SRC_STDLIB_WCTOMB_H diff --git a/libc/src/wchar/CMakeLists.txt b/libc/src/wchar/CMakeLists.txt index e6d9af9eacf73..9ca7295118a11 100644 --- a/libc/src/wchar/CMakeLists.txt +++ b/libc/src/wchar/CMakeLists.txt @@ -156,19 +156,6 @@ add_entrypoint_object( libc.src.__support.wchar.mbstate ) -add_entrypoint_object( - wctomb - SRCS - wctomb.cpp - HDRS - wctomb.h - DEPENDS - libc.hdr.types.wchar_t - libc.src.__support.wchar.wcrtomb - libc.src.__support.wchar.mbstate - libc.src.__support.libc_errno -) - add_entrypoint_object( mbsinit SRCS @@ -201,39 +188,6 @@ add_entrypoint_object( libc.src.__support.wchar.mbstate ) -add_entrypoint_object( - mbtowc - SRCS - mbtowc.cpp - HDRS - mbtowc.h - DEPENDS - libc.hdr.types.size_t - libc.hdr.types.wchar_t - libc.src.__support.common - libc.src.__support.macros.config - libc.src.__support.libc_errno - libc.src.__support.wchar.mbrtowc - libc.src.__support.wchar.mbstate -) - -add_entrypoint_object( - mbstowcs - SRCS - mbstowcs.cpp - HDRS - mbstowcs.h - DEPENDS - libc.hdr.types.size_t - libc.hdr.types.wchar_t - libc.src.__support.common - libc.src.__support.macros.config - libc.src.__support.macros.null_check - libc.src.__support.libc_errno - libc.src.__support.wchar.mbstate - libc.src.__support.wchar.mbsnrtowcs -) - add_entrypoint_object( mbsrtowcs SRCS @@ -266,19 +220,6 @@ add_entrypoint_object( libc.src.__support.wchar.mbsnrtowcs ) -add_entrypoint_object( - wcstombs - SRCS - wcstombs.cpp - HDRS - wcstombs.h - DEPENDS - libc.hdr.types.wchar_t - libc.src.__support.wchar.mbstate - libc.src.__support.wchar.wcsnrtombs - libc.src.__support.libc_errno -) - add_entrypoint_object( wcsrtombs SRCS diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt index 42e8faa3fd69f..bcd3d139aa46c 100644 --- a/libc/test/src/stdlib/CMakeLists.txt +++ b/libc/test/src/stdlib/CMakeLists.txt @@ -388,6 +388,56 @@ add_libc_test( libc.src.stdlib.memalignment ) +add_libc_test( + mbtowc_test + SUITE + libc-stdlib-tests + SRCS + mbtowc_test.cpp + DEPENDS + libc.hdr.errno_macros + libc.src.stdlib.mbtowc + libc.hdr.types.wchar_t + libc.test.UnitTest.ErrnoCheckingTest +) + +add_libc_test( + mbstowcs_test + SUITE + libc-stdlib-tests + SRCS + mbstowcs_test.cpp + DEPENDS + libc.hdr.errno_macros + libc.src.stdlib.mbstowcs + libc.hdr.types.wchar_t + libc.test.UnitTest.ErrnoCheckingTest +) + +add_libc_test( + wctomb_test + SUITE + libc-stdlib-tests + SRCS + wctomb_test.cpp + DEPENDS + libc.hdr.errno_macros + libc.src.stdlib.wctomb + libc.hdr.types.wchar_t +) + +add_libc_test( + wcstombs_test + SUITE + libc-stdlib-tests + SRCS + wcstombs_test.cpp + DEPENDS + libc.src.stdlib.wcstombs + libc.test.UnitTest.ErrnoCheckingTest + libc.hdr.types.wchar_t +) + if(LLVM_LIBC_FULL_BUILD) add_libc_test( diff --git a/libc/test/src/wchar/mbstowcs_test.cpp b/libc/test/src/stdlib/mbstowcs_test.cpp similarity index 99% rename from libc/test/src/wchar/mbstowcs_test.cpp rename to libc/test/src/stdlib/mbstowcs_test.cpp index 742f47819c84b..125683a3eca97 100644 --- a/libc/test/src/wchar/mbstowcs_test.cpp +++ b/libc/test/src/stdlib/mbstowcs_test.cpp @@ -9,7 +9,7 @@ #include "hdr/errno_macros.h" #include "hdr/types/wchar_t.h" #include "src/__support/macros/null_check.h" -#include "src/wchar/mbstowcs.h" +#include "src/stdlib/mbstowcs.h" #include "test/UnitTest/ErrnoCheckingTest.h" #include "test/UnitTest/Test.h" diff --git a/libc/test/src/wchar/mbtowc_test.cpp b/libc/test/src/stdlib/mbtowc_test.cpp similarity index 99% rename from libc/test/src/wchar/mbtowc_test.cpp rename to libc/test/src/stdlib/mbtowc_test.cpp index 7c86d5583aaed..7946e077b647e 100644 --- a/libc/test/src/wchar/mbtowc_test.cpp +++ b/libc/test/src/stdlib/mbtowc_test.cpp @@ -8,7 +8,7 @@ #include "hdr/errno_macros.h" #include "hdr/types/wchar_t.h" -#include "src/wchar/mbtowc.h" +#include "src/stdlib/mbtowc.h" #include "test/UnitTest/ErrnoCheckingTest.h" #include "test/UnitTest/Test.h" diff --git a/libc/test/src/wchar/wcstombs_test.cpp b/libc/test/src/stdlib/wcstombs_test.cpp similarity index 98% rename from libc/test/src/wchar/wcstombs_test.cpp rename to libc/test/src/stdlib/wcstombs_test.cpp index 61e0873dc9711..792a4edb51b38 100644 --- a/libc/test/src/wchar/wcstombs_test.cpp +++ b/libc/test/src/stdlib/wcstombs_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/wchar/wcstombs.h" +#include "src/stdlib/wcstombs.h" #include "test/UnitTest/ErrnoCheckingTest.h" #include "test/UnitTest/Test.h" diff --git a/libc/test/src/wchar/wctomb_test.cpp b/libc/test/src/stdlib/wctomb_test.cpp similarity index 98% rename from libc/test/src/wchar/wctomb_test.cpp rename to libc/test/src/stdlib/wctomb_test.cpp index 357f36267b689..56bebf87a2796 100644 --- a/libc/test/src/wchar/wctomb_test.cpp +++ b/libc/test/src/stdlib/wctomb_test.cpp @@ -8,7 +8,7 @@ #include "hdr/errno_macros.h" #include "hdr/types/wchar_t.h" -#include "src/wchar/wctomb.h" +#include "src/stdlib/wctomb.h" #include "test/UnitTest/ErrnoCheckingTest.h" #include "test/UnitTest/Test.h" diff --git a/libc/test/src/wchar/CMakeLists.txt b/libc/test/src/wchar/CMakeLists.txt index a62a30fe00124..7a7cfaee7f367 100644 --- a/libc/test/src/wchar/CMakeLists.txt +++ b/libc/test/src/wchar/CMakeLists.txt @@ -62,32 +62,6 @@ add_libc_test( libc.test.UnitTest.ErrnoCheckingTest ) -add_libc_test( - mbtowc_test - SUITE - libc_wchar_unittests - SRCS - mbtowc_test.cpp - DEPENDS - libc.hdr.errno_macros - libc.src.wchar.mbtowc - libc.hdr.types.wchar_t - libc.test.UnitTest.ErrnoCheckingTest -) - -add_libc_test( - mbstowcs_test - SUITE - libc_wchar_unittests - SRCS - mbstowcs_test.cpp - DEPENDS - libc.hdr.errno_macros - libc.src.wchar.mbstowcs - libc.hdr.types.wchar_t - libc.test.UnitTest.ErrnoCheckingTest -) - add_libc_test( mblen_test SUITE @@ -188,30 +162,6 @@ add_libc_test( libc.test.UnitTest.ErrnoCheckingTest ) -add_libc_test( - wctomb_test - SUITE - libc_wchar_unittests - SRCS - wctomb_test.cpp - DEPENDS - libc.hdr.errno_macros - libc.src.wchar.wctomb - libc.hdr.types.wchar_t -) - -add_libc_test( - wcstombs_test - SUITE - libc_wchar_unittests - SRCS - wcstombs_test.cpp - DEPENDS - libc.src.wchar.wcstombs - libc.test.UnitTest.ErrnoCheckingTest - libc.hdr.types.wchar_t -) - add_libc_test( wcsrtombs_test SUITE