From 8f9af4a58282ff8c66ac71137be4025e26dc8623 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Tue, 1 Jun 2021 23:37:09 +0200 Subject: [PATCH] LibC: Implement CODESET for langinfo --- Userland/Libraries/LibC/CMakeLists.txt | 1 + Userland/Libraries/LibC/langinfo.cpp | 27 ++++++++++++++++++++++++++ Userland/Libraries/LibC/langinfo.h | 20 +++++++++++++++++++ Userland/Libraries/LibC/nl_types.h | 15 ++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 Userland/Libraries/LibC/langinfo.cpp create mode 100644 Userland/Libraries/LibC/langinfo.h create mode 100644 Userland/Libraries/LibC/nl_types.h diff --git a/Userland/Libraries/LibC/CMakeLists.txt b/Userland/Libraries/LibC/CMakeLists.txt index 48a627d85e..98b31ba227 100644 --- a/Userland/Libraries/LibC/CMakeLists.txt +++ b/Userland/Libraries/LibC/CMakeLists.txt @@ -12,6 +12,7 @@ set(LIBC_SOURCES grp.cpp inttypes.cpp ioctl.cpp + langinfo.cpp libcinit.cpp libgen.cpp link.cpp diff --git a/Userland/Libraries/LibC/langinfo.cpp b/Userland/Libraries/LibC/langinfo.cpp new file mode 100644 index 0000000000..9d5d9d2eee --- /dev/null +++ b/Userland/Libraries/LibC/langinfo.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021, the SerenityOS developers + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +static const char* __nl_langinfo(nl_item item) +{ + switch (item) { + case CODESET: + return "UTF-8"; + default: + return ""; + } +} + +extern "C" { + +char* nl_langinfo(nl_item item) +{ + // POSIX states that returned strings should not be modified, + // so this cast is probably fine. + return const_cast(__nl_langinfo(item)); +} +} diff --git a/Userland/Libraries/LibC/langinfo.h b/Userland/Libraries/LibC/langinfo.h new file mode 100644 index 0000000000..3470f18f93 --- /dev/null +++ b/Userland/Libraries/LibC/langinfo.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2021, the SerenityOS developers + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +__BEGIN_DECLS + +enum { + CODESET, +}; + +char* nl_langinfo(nl_item); + +__END_DECLS diff --git a/Userland/Libraries/LibC/nl_types.h b/Userland/Libraries/LibC/nl_types.h new file mode 100644 index 0000000000..31fcbc0e75 --- /dev/null +++ b/Userland/Libraries/LibC/nl_types.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021, the SerenityOS developers + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +__BEGIN_DECLS + +typedef int nl_item; + +__END_DECLS