Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,11 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.wchar.wcstombs
libc.src.wchar.wcsrtombs
libc.src.wchar.wcsnrtombs

# nl_types.h entrypoints
libc.src.nl_types.catopen
libc.src.nl_types.catclose
libc.src.nl_types.catgets
)
endif()

Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.malloc
libc.include.math
libc.include.netinet_in
libc.include.nl_types
libc.include.poll
libc.include.pthread
libc.include.sched
Expand Down
8 changes: 8 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,14 @@ add_header_macro(
.llvm-libc-macros.poll-macros
)

add_header_macro(
nl_types
../libc/include/nl_types.yaml
nl_types.h
DEPENDS
.llvm-libc-types.nl_catd
)

# UEFI spec references "Uefi.h" so we use that name for compatibility
add_header_macro(
uefi
Expand Down
1 change: 1 addition & 0 deletions libc/include/llvm-libc-types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ add_header(mbstate_t HDR mbstate_t.h)
add_header(mode_t HDR mode_t.h)
add_header(mtx_t HDR mtx_t.h DEPENDS .__futex_word .__mutex_type)
add_header(nfds_t HDR nfds_t.h)
add_header(nl_catd HDR nl_catd.h)
add_header(nlink_t HDR nlink_t.h)
add_header(off_t HDR off_t.h)
add_header(once_flag HDR once_flag.h DEPENDS .__futex_word)
Expand Down
14 changes: 14 additions & 0 deletions libc/include/llvm-libc-types/nl_catd.h
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
31 changes: 31 additions & 0 deletions libc/include/nl_types.yaml
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*
1 change: 1 addition & 0 deletions libc/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ add_subdirectory(arpa)
add_subdirectory(assert)
add_subdirectory(compiler)
add_subdirectory(locale)
add_subdirectory(nl_types)
add_subdirectory(search)
add_subdirectory(setjmp)
add_subdirectory(signal)
Expand Down
31 changes: 31 additions & 0 deletions libc/src/nl_types/CMakeLists.txt
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
)

21 changes: 21 additions & 0 deletions libc/src/nl_types/catclose.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- 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)) {
// Message catalogs are not implemented. Return error regardless of input.
return -1;
}

} // namespace LIBC_NAMESPACE_DECL
21 changes: 21 additions & 0 deletions libc/src/nl_types/catclose.h
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
25 changes: 25 additions & 0 deletions libc/src/nl_types/catgets.cpp
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)) {
// Message catalogs are not implemented.
// Return backup message regardless of input.
return const_cast<char *>(message);
}

} // namespace LIBC_NAMESPACE_DECL
22 changes: 22 additions & 0 deletions libc/src/nl_types/catgets.h
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
25 changes: 25 additions & 0 deletions libc/src/nl_types/catopen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===-- 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)) {
// Message catalogs are not implemented. Return error regardless of input.
libc_errno = EINVAL;
return reinterpret_cast<nl_catd>(-1);
}

} // namespace LIBC_NAMESPACE_DECL
21 changes: 21 additions & 0 deletions libc/src/nl_types/catopen.h
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
1 change: 1 addition & 0 deletions libc/test/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ add_subdirectory(assert)
add_subdirectory(compiler)
add_subdirectory(dirent)
add_subdirectory(locale)
add_subdirectory(nl_types)
add_subdirectory(signal)
add_subdirectory(spawn)

Expand Down
14 changes: 14 additions & 0 deletions libc/test/src/nl_types/CMakeLists.txt
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
)
33 changes: 33 additions & 0 deletions libc/test/src/nl_types/nl_types_test.cpp
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));
}
Loading