From 5c68d50070c2dfffad4bef377a053097fe63cec7 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 31 May 2023 22:12:50 +0200 Subject: [PATCH] libc: Add a very bare-bones locale.h --- libc/CMakeLists.txt | 1 + libc/include/bits/locale-cat.h | 18 ++++++++++++++++++ libc/include/locale.h | 20 ++++++++++++++++++++ libc/src/locale.cpp | 12 ++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 libc/include/bits/locale-cat.h create mode 100644 libc/include/locale.h create mode 100644 libc/src/locale.cpp diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 75033f6a..46834ba4 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -19,6 +19,7 @@ set(SOURCES src/env.cpp src/pwd.cpp src/grp.cpp + src/locale.cpp src/sys/stat.cpp src/sys/mman.cpp src/sys/wait.cpp diff --git a/libc/include/bits/locale-cat.h b/libc/include/bits/locale-cat.h new file mode 100644 index 00000000..ceef5821 --- /dev/null +++ b/libc/include/bits/locale-cat.h @@ -0,0 +1,18 @@ +/* bits/locale-cat.h: Locale categories. */ + +#ifndef _BITS_LOCALE_CAT_H +#define _BITS_LOCALE_CAT_H + +enum __libc_locale_category +{ + LC_ALL, // Controls all locales. + LC_CTYPE, // Character classification and case conversion. + LC_COLLATE, // Collation order. + LC_MONETARY, // Monetary formatting. + LC_NUMERIC, // Numeric, non-monetary formatting. + LC_TIME, // Date and time formats. + LC_MESSAGES, // Formats of informative and diagnostic messages and interactive responses. + __num_locale_categories, +}; + +#endif diff --git a/libc/include/locale.h b/libc/include/locale.h new file mode 100644 index 00000000..e0740303 --- /dev/null +++ b/libc/include/locale.h @@ -0,0 +1,20 @@ +/* locale.h: Locale category macros. */ + +#ifndef _LOCALE_H +#define _LOCALE_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + // Query or set the current locale. + char* setlocale(int category, const char* locale); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libc/src/locale.cpp b/libc/src/locale.cpp new file mode 100644 index 00000000..19c508ab --- /dev/null +++ b/libc/src/locale.cpp @@ -0,0 +1,12 @@ +#include + +static char s_default_locale[] = "C"; + +extern "C" +{ + char* setlocale(int, const char*) + { + // FIXME: Set the current locale if is not NULL. + return s_default_locale; + } +}