Skip to content

Commit b2b62c1

Browse files
vonosmasaokblast
authored andcommitted
[libc] Add macros definitions for <nl_types.h> (llvm#164474)
This PR adds required macro definitions to `<nl_types.h>` header, so that they're available to the code including it. The header itself was added in 12abe8a, together with stub definitions of the three required functions.
1 parent b953d2a commit b2b62c1

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed

libc/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ add_header_macro(
776776
../libc/include/nl_types.yaml
777777
nl_types.h
778778
DEPENDS
779+
.llvm-libc-macros.nl_types_macros
779780
.llvm-libc-types.nl_catd
780781
)
781782

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ add_macro_header(
345345
locale-macros.h
346346
)
347347

348+
add_macro_header(
349+
nl_types_macros
350+
HDR
351+
nl-types-macros.h
352+
)
353+
348354
add_macro_header(
349355
pthread_macros
350356
HDR
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===-- Definition of macros from nl_types.h ------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_MACROS_NL_TYPES_MACROS_H
10+
#define LLVM_LIBC_MACROS_NL_TYPES_MACROS_H
11+
12+
#define NL_SETD 1
13+
#define NL_CAT_LOCALE 1
14+
15+
#endif // LLVM_LIBC_MACROS_NL_TYPES_MACROS_H

libc/include/nl_types.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
header: nl_types.h
22
standards:
33
- posix
4-
macros: []
4+
macros:
5+
- macro_name: NL_SETD
6+
macro_header: nl-types-macros.h
7+
- macro_name: NL_CAT_LOCALE
8+
macro_header: nl-types-macros.h
59
types:
610
- type_name: nl_catd
711
enums: []

libc/test/src/nl_types/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_libc_test(
77
SRCS
88
nl_types_test.cpp
99
DEPENDS
10+
libc.include.llvm-libc-macros.nl_types_macros
1011
libc.include.llvm-libc-types.nl_catd
1112
libc.src.nl_types.catopen
1213
libc.src.nl_types.catclose

libc/test/src/nl_types/nl_types_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "include/llvm-libc-macros/nl-types-macros.h"
910
#include "include/llvm-libc-types/nl_catd.h"
1011
#include "src/nl_types/catclose.h"
1112
#include "src/nl_types/catgets.h"
@@ -15,7 +16,7 @@
1516
using LlvmLibcNlTypesTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
1617

1718
TEST_F(LlvmLibcNlTypesTest, CatopenFails) {
18-
ASSERT_EQ(LIBC_NAMESPACE::catopen("/somepath", 0),
19+
ASSERT_EQ(LIBC_NAMESPACE::catopen("/somepath", NL_CAT_LOCALE),
1920
reinterpret_cast<nl_catd>(-1));
2021
ASSERT_ERRNO_EQ(EINVAL);
2122
}
@@ -28,6 +29,6 @@ TEST_F(LlvmLibcNlTypesTest, CatgetsFails) {
2829
const char *message = "message";
2930
// Note that we test for pointer equality here, since catgets
3031
// is expected to return the input argument as-is.
31-
ASSERT_EQ(LIBC_NAMESPACE::catgets(nullptr, 0, 0, message),
32+
ASSERT_EQ(LIBC_NAMESPACE::catgets(nullptr, NL_SETD, 1, message),
3233
const_cast<char *>(message));
3334
}

0 commit comments

Comments
 (0)