Skip to content

[libc] Add stubs for 'langinfo.h' #106620

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions libc/config/gpu/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.uchar
libc.include.features
libc.include.locale
libc.include.langinfo

# Header for RPC extensions
libc.include.gpu_rpc
Expand Down
11 changes: 11 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,17 @@ add_header_macro(
.llvm-libc-types.struct_lconv
)

add_header_macro(
langinfo
../libc/newhdrgen/yaml/langinfo.yaml
langinfo.h.def
langinfo.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-macros.langinfo_macros
.llvm-libc-types.nl_item
)

if(LIBC_TARGET_OS_IS_GPU)
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/gpu)

Expand Down
20 changes: 20 additions & 0 deletions libc/include/langinfo.h.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- C standard library header langinfo.h --------------------------------===//
//
// 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_LANGINFO_H
#define LLVM_LIBC_LANGINFO_H

#include "__llvm-libc-common.h"

#include "llvm-libc-types/locale_t.h"
#include "llvm-libc-macros/langinfo-macros.h"

%%public_api()

#endif // LLVM_LIBC_LANGINFO_H

6 changes: 6 additions & 0 deletions libc/include/llvm-libc-macros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,9 @@ add_macro_header(
HDR
locale-macros.h
)

add_macro_header(
langinfo_macros
HDR
langinfo-macros.h
)
81 changes: 81 additions & 0 deletions libc/include/llvm-libc-macros/langinfo-macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//===-- Definition of macros from langinfo.h ------------------------------===//
//
// 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_MACROS_LANGINFO_MACROS_H
#define LLVM_LIBC_MACROS_LANGINFO_MACROS_H

// TODO: Define these for the C locale.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are going to be hardcoded to the default locale, is it worthwhile to just set the obvious ones now? Like AM_STR is going to be "AM", etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, the C locale is most likely going to be the only one we're going to support in LLVM libc so we might as well make it usable right away.

#define CODESET 0

#define D_T_FMT 0
#define D_FMT 0
#define T_FMT 0
#define T_FMT_AMPM 0

#define AM_STR 0
#define PM_STR 0

#define DAY_1 0
#define DAY_2 0
#define DAY_3 0
#define DAY_4 0
#define DAY_5 0
#define DAY_6 0
#define DAY_7 0

#define ABDAY_1 0
#define ABDAY_2 0
#define ABDAY_3 0
#define ABDAY_4 0
#define ABDAY_5 0
#define ABDAY_6 0
#define ABDAY_7 0

#define MON_1 0
#define MON_2 0
#define MON_3 0
#define MON_4 0
#define MON_5 0
#define MON_6 0
#define MON_7 0
#define MON_8 0
#define MON_9 0
#define MON_10 0
#define MON_11 0
#define MON_12 0

#define ABMON_1 0
#define ABMON_2 0
#define ABMON_3 0
#define ABMON_4 0
#define ABMON_5 0
#define ABMON_6 0
#define ABMON_7 0
#define ABMON_8 0
#define ABMON_9 0
#define ABMON_10 0
#define ABMON_11 0
#define ABMON_12 0

#define ERA 0
#define ERA_D_FMT 0
#define ERA_D_T_FMT 0
#define ERA_T_FMT 0

#define ALT_DIGITS 0

#define RADIXCHAR 0

#define THOUSEP 0

#define YESEXPR 0
#define NOEXPR 0

#define CRNCYSTR 0

#endif // LLVM_LIBC_MACROS_LANGINFO_MACROS_H
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 @@ -144,3 +144,4 @@ DEPENDS
)
add_header(locale_t HDR locale_t.h)
add_header(struct_lconv HDR struct_lconv.h)
add_header(nl_item HDR nl_item.h)
14 changes: 14 additions & 0 deletions libc/include/llvm-libc-types/nl_item.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//===-- Definition of type nl_item ----------------------------------------===//
//
// 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_ITEM_H
#define LLVM_LIBC_TYPES_NL_ITEM_H

typedef int nl_item;

#endif // LLVM_LIBC_TYPES_NL_ITEM_H
19 changes: 19 additions & 0 deletions libc/newhdrgen/yaml/langinfo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
header: langinfo.h
macros: []
types: []
enums: []
objects: []
functions:
- name: nl_langinfo
standards:
- POSIX
return_type: char *
arguments:
- type: nl_item
- name: nl_langinfo_l
standards:
- POSIX
return_type: char *
arguments:
- type: nl_item
- type: locale_t
26 changes: 26 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def StdC : StandardSpec<"stdc"> {
PtrType TimeTTypePtr = PtrType<TimeTType>;
NamedType ClockT = NamedType<"clock_t">;
NamedType LocaleT = NamedType<"locale_t">;
NamedType NLItem = NamedType<"nl_item">;

NamedType DivTType = NamedType<"div_t">;
NamedType LDivTType = NamedType<"ldiv_t">;
Expand Down Expand Up @@ -1754,6 +1755,30 @@ def StdC : StandardSpec<"stdc"> {
] // Functions
>;

HeaderSpec LangInfo = HeaderSpec<
"langinfo.h",
[],
[], // Types
[], // Enumerations
[
FunctionSpec<
"nl_langinfo",
RetValSpec<CharPtr>,
[
ArgSpec<NLItem>
]
>,
FunctionSpec<
"nl_langinfo",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be nl_langinfo_l

RetValSpec<CharPtr>,
[
ArgSpec<NLItem>,
ArgSpec<LocaleT>
]
>
] // Functions
>;

let Headers = [
Assert,
CType,
Expand All @@ -1776,5 +1801,6 @@ def StdC : StandardSpec<"stdc"> {
UChar,
WChar,
Locale,
LangInfo,
];
}
20 changes: 20 additions & 0 deletions libc/src/langinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
add_object_library(
nl_langinfo
SRCS
nl_langinfo.cpp
HDRS
nl_langinfo.h
DEPENDS
libc.include.langinfo
libc.include.locale
)

add_object_library(
nl_langinfo_l
SRCS
nl_langinfo_l.cpp
HDRS
nl_langinfo_l.h
DEPENDS
libc.include.locale
)
20 changes: 20 additions & 0 deletions libc/src/langinfo/nl_langinfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of nl_langinfo -------------------------------------===//
//
// 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/langinfo/nl_langinfo.h"

#include "src/__support/common.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(char *, nl_langinfo, (nl_item)) {
static char EMPTY[] = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if these aren't implemented we should provide an error to the user. I'd recommend setting errno to ENOSYS.

return EMPTY;
}

} // namespace LIBC_NAMESPACE_DECL
21 changes: 21 additions & 0 deletions libc/src/langinfo/nl_langinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header for nl_langinfo -------------------*- 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_LANGINFO_NL_LANGINFO_H
#define LLVM_LIBC_SRC_LANGINFO_NL_LANGINFO_H

#include "include/llvm-libc-types/nl_item.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

char *nl_langinfo(nl_item);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_LANGINFO_NL_LANGINFO_H
20 changes: 20 additions & 0 deletions libc/src/langinfo/nl_langinfo_l.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of nl_langinfo_l -----------------------------------===//
//
// 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/langinfo/nl_langinfo_l.h"

#include "src/__support/common.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(char *, nl_langinfo_l, (nl_item, locale_t locale)) {
static char EMPTY[] = "";
return EMPTY;
}

} // namespace LIBC_NAMESPACE_DECL
22 changes: 22 additions & 0 deletions libc/src/langinfo/nl_langinfo_l.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Implementation header for nl_langinfo_l -----------------*- 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_LANGINFO_NL_LANGINFO_L_H
#define LLVM_LIBC_SRC_LANGINFO_NL_LANGINFO_L_H

#include "include/llvm-libc-types/locale_t.h"
#include "include/llvm-libc-types/nl_item.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

char *nl_langinfo_l(nl_item, locale_t locale);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_LANGINFO_NL_LANGINFO_L_H
Loading