1/*
2 * Copyright 2022, Trung Nguyen, trungnt282910@gmail.com
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5
6
7#ifndef _THREAD_LOCALE_H
8#define _THREAD_LOCALE_H
9
10
11#include "LocaleBackend.h"
12
13
14namespace BPrivate {
15namespace Libroot {
16
17
18// This struct is taken from glibc's __locale_struct
19// from xlocale.h.
20// It will also be used by glibc so it should have the same
21// layout.
22struct GlibcLocaleStruct {
23    void *__locales[7]; /* 7 = __LC_LAST. */
24
25    const unsigned short int *__ctype_b;
26    const int *__ctype_tolower;
27    const int *__ctype_toupper;
28};
29
30
31// Taken from glibc's bits/locale.h
32// glibc uses different codes from our the native locale.h.
33// This should be the values used for the indexes
34// in GlibcLocaleStruct.
35enum {
36    GLIBC_LC_CTYPE = 0,
37    GLIBC_LC_NUMERIC = 1,
38    GLIBC_LC_TIME = 2,
39    GLIBC_LC_COLLATE = 3,
40    GLIBC_LC_MONETARY = 4,
41    GLIBC_LC_MESSAGES = 5,
42    GLIBC_LC_ALL = 6,
43};
44
45
46// The pointer in the TLS will point to this struct.
47struct ThreadLocale {
48    GlibcLocaleStruct   glibcLocaleStruct;
49    LocaleBackendData*  threadLocaleInfo;
50};
51
52
53ThreadLocale* GetCurrentThreadLocale();
54
55
56}	// namespace Libroot
57}	// namespace BPrivate
58
59
60#endif	// _THREAD_LOCALE_H
61