[libcxx-commits] [libcxx] [libc++][z/OS] Move z/OS to new locale API and resolve all name collisions (PR #165428)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 28 16:42:33 PDT 2025
================
@@ -0,0 +1,318 @@
+//===-----------------------------------------------------------------------===//
+//
+// 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 _LIBCPP___LOCALE_DIR_SUPPORT_IBM_H
+#define _LIBCPP___LOCALE_DIR_SUPPORT_IBM_H
+
+#include <__support/ibm/locale_mgmt_zos.h>
+#include <__support/ibm/vasprintf.h>
+
+#include "cstdlib"
+#include <clocale> // std::lconv
+#include <locale.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <wctype.h>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// These functions are exported within std namespace
+// for compatibility with previous versions.
+_LIBCPP_EXPORTED_FROM_ABI int isdigit_l(int, locale_t);
+_LIBCPP_EXPORTED_FROM_ABI int isxdigit_l(int, locale_t);
+
+namespace __locale {
+struct __locale_guard {
+ _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(std::uselocale(__loc)) {}
+
+ _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
+ // if (__old_loc_)
+ if (__old_loc_ != (locale_t)0)
+ std::uselocale(__old_loc_);
+ }
+
+ locale_t __old_loc_;
+
+ __locale_guard(__locale_guard const&) = delete;
+ __locale_guard& operator=(__locale_guard const&) = delete;
+};
+
+//
+// Locale management
+//
+#define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
+#define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
+#define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
+#define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
+#define _LIBCPP_TIME_MASK LC_TIME_MASK
+#define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
+#define _LIBCPP_ALL_MASK LC_ALL_MASK
+#define _LIBCPP_LC_ALL LC_ALL
+
+#define _LIBCPP_CLOC std::__c_locale()
+#ifndef _LIBCPP_LC_GLOBAL_LOCALE
+# define _LIBCPP_LC_GLOBAL_LOCALE ((locale_t) - 1)
+#endif
+
+using __locale_t _LIBCPP_NODEBUG = locale_t;
+
+#if defined(_LIBCPP_BUILDING_LIBRARY)
+using __lconv_t _LIBCPP_NODEBUG = std::lconv;
+
+inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __locale, __locale_t __base) {
+ return newlocale(__category_mask, __locale, __base);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { freelocale(__loc); }
+
+inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) {
+ return ::setlocale(__category, __locale);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
+ __locale_guard __current(__loc);
+ return std::localeconv();
+}
+#endif // _LIBCPP_BUILDING_LIBRARY
+
+// The following are not POSIX routines. These are quick-and-dirty hacks
+// to make things pretend to work
+
+//
+// Strtonum functions
+//
+inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
+ __locale_guard __newloc(__loc);
+ return ::strtof(__nptr, __endptr);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
+ __locale_guard __newloc(__loc);
+ return ::strtod(__nptr, __endptr);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
+ __locale_guard __newloc(__loc);
+ return ::strtold(__nptr, __endptr);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
+ __locale_guard __newloc(__loc);
+ return ::strtoll(__nptr, __endptr, __base);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI unsigned long long
+__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
+ __locale_guard __newloc(__loc);
+ return ::strtoull(__nptr, __endptr, __base);
+}
+
+//
+// Character manipulation functions
+//
+namespace __ibm {
+_LIBCPP_HIDE_FROM_ABI int islower_l(int, __locale_t);
----------------
ldionne wrote:
Why do we need these non-reserved functions? Can't we use functions like `__islower` directly?
https://github.com/llvm/llvm-project/pull/165428
More information about the libcxx-commits
mailing list