-
Notifications
You must be signed in to change notification settings - Fork 15k
[libc] Stub out message catalog functions from <nl_types.h> #164360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0eeb97f
[libc] Add <nl_types.h> header.
vonosmas af673d3
add catopen impl
vonosmas 2b96596
add implementation for catclose and catgets
vonosmas aab915d
add implementation for catclose and catgets - 2
vonosmas 86e6afb
Add unit tests for nl_types.
vonosmas 859fc63
fix formatting
vonosmas f8e8c8c
add TODOs in function implementations.
vonosmas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| //===-- Definition of nl_catd type ----------------------------------------===// | ||
| // | ||
| // 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_TYPES_NL_CATD_H | ||
| #define LLVM_LIBC_TYPES_NL_CATD_H | ||
|
|
||
| typedef void *nl_catd; | ||
|
|
||
| #endif // LLVM_LIBC_TYPES_NL_CATD_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| header: nl_types.h | ||
| standards: | ||
| - posix | ||
| macros: [] | ||
| types: | ||
| - type_name: nl_catd | ||
| enums: [] | ||
| objects: [] | ||
| functions: | ||
| - name: catopen | ||
| standards: | ||
| - posix | ||
| return_type: nl_catd | ||
| arguments: | ||
| - type: const char * | ||
| - type: int | ||
| - name: catclose | ||
| standards: | ||
| - posix | ||
| return_type: int | ||
| arguments: | ||
| - type: nl_catd | ||
| - name: catgets | ||
| standards: | ||
| - posix | ||
| return_type: char * | ||
| arguments: | ||
| - type: nl_catd | ||
| - type: int | ||
| - type: int | ||
| - type: const char* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| add_entrypoint_object( | ||
| catopen | ||
| SRCS | ||
| catopen.cpp | ||
| HDRS | ||
| catopen.h | ||
| DEPENDS | ||
| libc.include.llvm-libc-types.nl_catd | ||
| libc.src.errno.errno | ||
| ) | ||
|
|
||
| add_entrypoint_object( | ||
| catclose | ||
| SRCS | ||
| catclose.cpp | ||
| HDRS | ||
| catclose.h | ||
| DEPENDS | ||
| libc.include.llvm-libc-types.nl_catd | ||
| ) | ||
|
|
||
| add_entrypoint_object( | ||
| catgets | ||
| SRCS | ||
| catgets.cpp | ||
| HDRS | ||
| catgets.h | ||
| DEPENDS | ||
| libc.include.llvm-libc-types.nl_catd | ||
| ) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //===-- Implementation of catclose ----------------------------------------===// | ||
| // | ||
| // 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/nl_types/catclose.h" | ||
| #include "include/llvm-libc-types/nl_catd.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, catclose, ([[maybe_unused]] nl_catd catalog)) { | ||
| // TODO: Add implementation for message catalogs. For now, return error | ||
| // regardless of input. | ||
| return -1; | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //===-- Implementation header for catclose ----------------------*- 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_NL_TYPES_CATCLOSE_H | ||
| #define LLVM_LIBC_SRC_NL_TYPES_CATCLOSE_H | ||
|
|
||
| #include "include/llvm-libc-types/nl_catd.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| int catclose(nl_catd catalog); | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC_NL_TYPES_CATCLOSE_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //===-- Implementation of catgets -----------------------------------------===// | ||
| // | ||
| // 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/nl_types/catgets.h" | ||
| #include "include/llvm-libc-types/nl_catd.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(char *, catgets, | ||
| ([[maybe_unused]] nl_catd catalog, | ||
| [[maybe_unused]] int set_number, | ||
| [[maybe_unused]] int message_number, const char *message)) { | ||
| // TODO: Add implementation for message catalogs. For now, return backup | ||
| // message regardless of input. | ||
| return const_cast<char *>(message); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //===-- Implementation header for catgets -----------------------*- 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_NL_TYPES_CATGETS_H | ||
| #define LLVM_LIBC_SRC_NL_TYPES_CATGETS_H | ||
|
|
||
| #include "include/llvm-libc-types/nl_catd.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| char *catgets(nl_catd catalog, int set_number, int message_number, | ||
| const char *message); | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC_NL_TYPES_CATGETS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //===-- Implementation of catopen -----------------------------------------===// | ||
| // | ||
| // 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/nl_types/catopen.h" | ||
| #include "include/llvm-libc-types/nl_catd.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/libc_errno.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(nl_catd, catopen, | ||
| ([[maybe_unused]] const char *name, | ||
| [[maybe_unused]] int flag)) { | ||
| // TODO: Add implementation for message catalogs. For now, return error | ||
| // regardless of input. | ||
| libc_errno = EINVAL; | ||
| return reinterpret_cast<nl_catd>(-1); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //===-- Implementation header for catopen -----------------------*- 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_NL_TYPES_CATOPEN_H | ||
| #define LLVM_LIBC_SRC_NL_TYPES_CATOPEN_H | ||
|
|
||
| #include "include/llvm-libc-types/nl_catd.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| nl_catd catopen(const char *name, int flag); | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC_NL_TYPES_CATOPEN_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| add_custom_target(libc-nl-types-tests) | ||
|
|
||
| add_libc_test( | ||
| nl_types_test | ||
| SUITE | ||
| libc-nl-types-tests | ||
| SRCS | ||
| nl_types_test.cpp | ||
| DEPENDS | ||
| libc.include.llvm-libc-types.nl_catd | ||
| libc.src.nl_types.catopen | ||
| libc.src.nl_types.catclose | ||
| libc.src.nl_types.catgets | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //===-- Unittests for nl_types --------------------------------------------===// | ||
| // | ||
| // 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 "include/llvm-libc-types/nl_catd.h" | ||
| #include "src/nl_types/catclose.h" | ||
| #include "src/nl_types/catgets.h" | ||
| #include "src/nl_types/catopen.h" | ||
| #include "test/UnitTest/ErrnoCheckingTest.h" | ||
|
|
||
| using LlvmLibcNlTypesTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest; | ||
|
|
||
| TEST_F(LlvmLibcNlTypesTest, CatopenFails) { | ||
| ASSERT_EQ(LIBC_NAMESPACE::catopen("/somepath", 0), | ||
| reinterpret_cast<nl_catd>(-1)); | ||
| ASSERT_ERRNO_EQ(EINVAL); | ||
| } | ||
|
|
||
| TEST_F(LlvmLibcNlTypesTest, CatcloseFails) { | ||
| ASSERT_EQ(LIBC_NAMESPACE::catclose(nullptr), -1); | ||
| } | ||
|
|
||
| TEST_F(LlvmLibcNlTypesTest, CatgetsFails) { | ||
| const char *message = "message"; | ||
| // Note that we test for pointer equality here, since catgets | ||
| // is expected to return the input argument as-is. | ||
| ASSERT_EQ(LIBC_NAMESPACE::catgets(nullptr, 0, 0, message), | ||
| const_cast<char *>(message)); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.