[libc-commits] [libc] [libc] Initial support for 'locale.h' in the LLVM libc (PR #102689)

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Sat Aug 10 22:26:55 PDT 2024


================
@@ -0,0 +1,36 @@
+//===-- Implementation header for the locale --------------------*- 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_LOCALE_LOCALECONV_H
+#define LLVM_LIBC_SRC_LOCALE_LOCALECONV_H
+
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+
+#include "include/llvm-libc-types/locale_t.h"
+
+#include <stddef.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+// We only support the "C" locale right now.
+static constexpr size_t MAX_LOCALE_NAME_SIZE = 2;
+
+struct __locale_data {
+  char name[MAX_LOCALE_NAME_SIZE];
+};
+
+// The pointer to the default "C" locale.
+extern __locale_t c_locale;
+
+// The global locale instance.
+LIBC_THREAD_LOCAL extern locale_t locale;
----------------
petrhosek wrote:

This isn't going to work on baremetal where thread local variables generally aren't available. According to the documentation the locale functions aren't expected to be thread-safe so this shouldn't be required. Can we make it a global variable?

https://github.com/llvm/llvm-project/pull/102689


More information about the libc-commits mailing list