From d77b84be585e9ceaed1501579df5a4aec6a24a63 Mon Sep 17 00:00:00 2001 From: Owen Shepherd Date: Mon, 31 Dec 2012 19:20:06 +0000 Subject: [PATCH] PDCLIB-1 PDCLIB-2 PDCLIB-9 PDCLIB-12: Add thread specific locale support; migrate existing codebase to utilise it --- functions/ctype/isalnum.c | 5 +- functions/ctype/isalpha.c | 5 +- functions/ctype/isblank.c | 5 +- functions/ctype/iscntrl.c | 5 +- functions/ctype/isdigit.c | 5 +- functions/ctype/isgraph.c | 5 +- functions/ctype/islower.c | 5 +- functions/ctype/isprint.c | 5 +- functions/ctype/ispunct.c | 5 +- functions/ctype/isspace.c | 5 +- functions/ctype/isupper.c | 5 +- functions/ctype/isxdigit.c | 5 +- functions/ctype/tolower.c | 5 +- functions/ctype/toupper.c | 5 +- functions/locale/localeconv.c | 6 +- functions/stdio/perror.c | 4 +- functions/string/strcoll.c | 8 +- functions/string/strerror.c | 4 +- functions/string/strxfrm.c | 5 +- includes/locale.h | 11 +-- internals/_PDCLIB_int.h | 25 +------ internals/_PDCLIB_locale.h | 73 ++++++++++++++++++- opt/basecodecs/_PDCLIB_ascii.c | 2 +- opt/basecodecs/_PDCLIB_latin1.c | 2 +- opt/basecodecs/_PDCLIB_utf8.c | 2 +- .../posix/functions/_PDCLIB/_PDCLIB_stdinit.c | 30 +++++--- platform/posix/internals/_PDCLIB_config.h | 5 ++ platform/win32/internals/_PDCLIB_config.h | 5 ++ 28 files changed, 153 insertions(+), 99 deletions(-) diff --git a/functions/ctype/isalnum.c b/functions/ctype/isalnum.c index f4969fa..bbb01d5 100644 --- a/functions/ctype/isalnum.c +++ b/functions/ctype/isalnum.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int isalnum( int c ) { - return ( _PDCLIB_lconv.ctype[c].flags & ( _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_DIGIT ) ); + return ( _PDCLIB_threadlocale()->_CType[c].flags & ( _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_DIGIT ) ); } #endif diff --git a/functions/ctype/isalpha.c b/functions/ctype/isalpha.c index 9dad397..147fd5e 100644 --- a/functions/ctype/isalpha.c +++ b/functions/ctype/isalpha.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int isalpha( int c ) { - return ( _PDCLIB_lconv.ctype[c].flags & _PDCLIB_CTYPE_ALPHA ); + return ( _PDCLIB_threadlocale()->_CType[c].flags & _PDCLIB_CTYPE_ALPHA ); } #endif diff --git a/functions/ctype/isblank.c b/functions/ctype/isblank.c index cc29fa8..fe2a51b 100644 --- a/functions/ctype/isblank.c +++ b/functions/ctype/isblank.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int isblank( int c ) { - return ( _PDCLIB_lconv.ctype[c].flags & _PDCLIB_CTYPE_BLANK ); + return ( _PDCLIB_threadlocale()->_CType[c].flags & _PDCLIB_CTYPE_BLANK ); } #endif diff --git a/functions/ctype/iscntrl.c b/functions/ctype/iscntrl.c index 8c0a4f3..ebb1f47 100644 --- a/functions/ctype/iscntrl.c +++ b/functions/ctype/iscntrl.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int iscntrl( int c ) { - return ( _PDCLIB_lconv.ctype[c].flags & _PDCLIB_CTYPE_CNTRL ); + return ( _PDCLIB_threadlocale()->_CType[c].flags & _PDCLIB_CTYPE_CNTRL ); } #endif diff --git a/functions/ctype/isdigit.c b/functions/ctype/isdigit.c index b122f7e..36be037 100644 --- a/functions/ctype/isdigit.c +++ b/functions/ctype/isdigit.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int isdigit( int c ) { - return ( _PDCLIB_lconv.ctype[c].flags & _PDCLIB_CTYPE_DIGIT ); + return ( _PDCLIB_threadlocale()->_CType[c].flags & _PDCLIB_CTYPE_DIGIT ); } #endif diff --git a/functions/ctype/isgraph.c b/functions/ctype/isgraph.c index d623485..133a39c 100644 --- a/functions/ctype/isgraph.c +++ b/functions/ctype/isgraph.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int isgraph( int c ) { - return ( _PDCLIB_lconv.ctype[c].flags & _PDCLIB_CTYPE_GRAPH ); + return ( _PDCLIB_threadlocale()->_CType[c].flags & _PDCLIB_CTYPE_GRAPH ); } #endif diff --git a/functions/ctype/islower.c b/functions/ctype/islower.c index db0649d..689e65f 100644 --- a/functions/ctype/islower.c +++ b/functions/ctype/islower.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int islower( int c ) { - return ( _PDCLIB_lconv.ctype[c].flags & _PDCLIB_CTYPE_LOWER ); + return ( _PDCLIB_threadlocale()->_CType[c].flags & _PDCLIB_CTYPE_LOWER ); } #endif diff --git a/functions/ctype/isprint.c b/functions/ctype/isprint.c index 50b0ad8..6a5366a 100644 --- a/functions/ctype/isprint.c +++ b/functions/ctype/isprint.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int isprint( int c ) { - return ( _PDCLIB_lconv.ctype[c].flags & _PDCLIB_CTYPE_GRAPH ) || ( c == ' ' ); + return ( _PDCLIB_threadlocale()->_CType[c].flags & _PDCLIB_CTYPE_GRAPH ) || ( c == ' ' ); } #endif diff --git a/functions/ctype/ispunct.c b/functions/ctype/ispunct.c index 4dfd52a..6c06788 100644 --- a/functions/ctype/ispunct.c +++ b/functions/ctype/ispunct.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int ispunct( int c ) { - return ( _PDCLIB_lconv.ctype[c].flags & _PDCLIB_CTYPE_PUNCT ); + return ( _PDCLIB_threadlocale()->_CType[c].flags & _PDCLIB_CTYPE_PUNCT ); } #endif diff --git a/functions/ctype/isspace.c b/functions/ctype/isspace.c index b443f6f..097a520 100644 --- a/functions/ctype/isspace.c +++ b/functions/ctype/isspace.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int isspace( int c ) { - return ( _PDCLIB_lconv.ctype[c].flags & _PDCLIB_CTYPE_SPACE ); + return ( _PDCLIB_threadlocale()->_CType[c].flags & _PDCLIB_CTYPE_SPACE ); } #endif diff --git a/functions/ctype/isupper.c b/functions/ctype/isupper.c index 5953946..9d45a74 100644 --- a/functions/ctype/isupper.c +++ b/functions/ctype/isupper.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int isupper( int c ) { - return ( _PDCLIB_lconv.ctype[c].flags & _PDCLIB_CTYPE_UPPER ); + return ( _PDCLIB_threadlocale()->_CType[c].flags & _PDCLIB_CTYPE_UPPER ); } #endif diff --git a/functions/ctype/isxdigit.c b/functions/ctype/isxdigit.c index 7f5dfec..e0b0f60 100644 --- a/functions/ctype/isxdigit.c +++ b/functions/ctype/isxdigit.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int isxdigit( int c ) { - return ( _PDCLIB_lconv.ctype[c].flags & _PDCLIB_CTYPE_XDIGT ); + return ( _PDCLIB_threadlocale()->_CType[c].flags & _PDCLIB_CTYPE_XDIGT ); } #endif diff --git a/functions/ctype/tolower.c b/functions/ctype/tolower.c index d051ba5..a77001e 100644 --- a/functions/ctype/tolower.c +++ b/functions/ctype/tolower.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int tolower( int c ) { - return _PDCLIB_lconv.ctype[c].lower; + return _PDCLIB_threadlocale()->_CType[c].lower; } #endif diff --git a/functions/ctype/toupper.c b/functions/ctype/toupper.c index 801c8ef..2972b51 100644 --- a/functions/ctype/toupper.c +++ b/functions/ctype/toupper.c @@ -9,12 +9,11 @@ #include #ifndef REGTEST - -#include +#include <_PDCLIB_locale.h> int toupper( int c ) { - return _PDCLIB_lconv.ctype[c].upper; + return _PDCLIB_threadlocale()->_CType[c].upper; } #endif diff --git a/functions/locale/localeconv.c b/functions/locale/localeconv.c index e23fb6a..5b49571 100644 --- a/functions/locale/localeconv.c +++ b/functions/locale/localeconv.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /* localeconv( void ) This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. */ -#include +#include <_PDCLIB_locale.h> #ifndef REGTEST struct lconv * localeconv( void ) { - return &_PDCLIB_lconv; + return &_PDCLIB_threadlocale()->_Conv; } #endif diff --git a/functions/stdio/perror.c b/functions/stdio/perror.c index 5a794fb..9fe6948 100644 --- a/functions/stdio/perror.c +++ b/functions/stdio/perror.c @@ -10,7 +10,7 @@ #ifndef REGTEST #include -#include +#include <_PDCLIB_locale.h> /* TODO: Doing this via a static array is not the way to do it. */ void perror( const char * s ) @@ -25,7 +25,7 @@ void perror( const char * s ) } else { - fprintf( stderr, "%s\n", _PDCLIB_lconv._PDCLIB_errno_texts[errno] ); + fprintf( stderr, "%s\n", _PDCLIB_threadlocale()->_ErrnoStr[errno] ); } return; } diff --git a/functions/string/strcoll.c b/functions/string/strcoll.c index 16a5680..b6a4cd6 100644 --- a/functions/string/strcoll.c +++ b/functions/string/strcoll.c @@ -10,16 +10,18 @@ #ifndef REGTEST -#include +#include <_PDCLIB_locale.h> int strcoll( const char * s1, const char * s2 ) { - while ( ( *s1 ) && ( _PDCLIB_lconv.ctype[(unsigned char)*s1].collation == _PDCLIB_lconv.ctype[(unsigned char)*s2].collation ) ) + _PDCLIB_ctype_t * ctype = _PDCLIB_threadlocale()->_CType; + + while ( ( *s1 ) && ( ctype[(unsigned char)*s1].collation == ctype[(unsigned char)*s2].collation ) ) { ++s1; ++s2; } - return ( _PDCLIB_lconv.ctype[(unsigned char)*s1].collation == _PDCLIB_lconv.ctype[(unsigned char)*s2].collation ); + return ( ctype[(unsigned char)*s1].collation == ctype[(unsigned char)*s2].collation ); } #endif diff --git a/functions/string/strerror.c b/functions/string/strerror.c index b0ced5d..e050394 100644 --- a/functions/string/strerror.c +++ b/functions/string/strerror.c @@ -10,7 +10,7 @@ #ifndef REGTEST -#include +#include <_PDCLIB_locale.h> /* TODO: Doing this via a static array is not the way to do it. */ char * strerror( int errnum ) @@ -21,7 +21,7 @@ char * strerror( int errnum ) } else { - return _PDCLIB_lconv._PDCLIB_errno_texts[errnum]; + return _PDCLIB_threadlocale()->_ErrnoStr[errnum]; } } diff --git a/functions/string/strxfrm.c b/functions/string/strxfrm.c index 4f5e4a0..3ea8d0f 100644 --- a/functions/string/strxfrm.c +++ b/functions/string/strxfrm.c @@ -10,17 +10,18 @@ #ifndef REGTEST -#include +#include <_PDCLIB_locale.h> size_t strxfrm( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ) { + _PDCLIB_ctype_t *ctype = _PDCLIB_threadlocale()->_CType; size_t len = strlen( s2 ); if ( len < n ) { /* Cannot use strncpy() here as the filling of s1 with '\0' is not part of the spec. */ - while ( n-- && ( *s1++ = _PDCLIB_lconv.ctype[(unsigned char)*s2++].collation ) ); + while ( n-- && ( *s1++ = ctype[(unsigned char)*s2++].collation ) ); } return len; } diff --git a/includes/locale.h b/includes/locale.h index 21221e3..1fb04e7 100644 --- a/includes/locale.h +++ b/includes/locale.h @@ -34,8 +34,6 @@ _PDCLIB_BEGIN_EXTERN_C */ struct lconv { - struct _PDCLIB_ctype_t * ctype; /* internal information */ - char * _PDCLIB_errno_texts[_PDCLIB_ERRNO_MAX]; /* strerror() / perror() */ char * decimal_point; /* decimal point character */ char * thousands_sep; /* character for seperating groups of digits */ char * grouping; /* string indicating the size of digit groups */ @@ -62,9 +60,6 @@ struct lconv char int_n_sign_posn; /* Same as above, for international format */ }; -/* This is strictly internal, and visible here for technical reasons only. */ -extern struct lconv _PDCLIB_lconv; - /* First arguments to setlocale(). TODO: Beware, values might change before v0.6 is released. */ @@ -98,8 +93,14 @@ char * setlocale( int category, const char * locale ) _PDCLIB_nothrow; struct lconv * localeconv( void ) _PDCLIB_nothrow; #if _PDCLIB_POSIX_MIN(2008) + +/* POSIX locale type */ typedef _PDCLIB_locale_t locale_t; +/* Global locale */ +extern struct _PDCLIB_locale _PDCLIB_global_locale; +#define LC_GLOBAL_LOCALE (&_PDCLIB_global_locale) + /* Set the thread locale to newlocale * * If newlocale is (locale_t)0, then doesn't change the locale and just returns diff --git a/internals/_PDCLIB_int.h b/internals/_PDCLIB_int.h index 315a0e3..c9988a9 100644 --- a/internals/_PDCLIB_int.h +++ b/internals/_PDCLIB_int.h @@ -325,29 +325,6 @@ extern int _PDCLIB_errno; */ int * _PDCLIB_errno_func( void ) _PDCLIB_nothrow; -/* -------------------------------------------------------------------------- */ -/* lookup tables */ -/* -------------------------------------------------------------------------- */ - -#define _PDCLIB_CTYPE_ALPHA 1 -#define _PDCLIB_CTYPE_BLANK 2 -#define _PDCLIB_CTYPE_CNTRL 4 -#define _PDCLIB_CTYPE_GRAPH 8 -#define _PDCLIB_CTYPE_PUNCT 16 -#define _PDCLIB_CTYPE_SPACE 32 -#define _PDCLIB_CTYPE_LOWER 64 -#define _PDCLIB_CTYPE_UPPER 128 -#define _PDCLIB_CTYPE_DIGIT 256 -#define _PDCLIB_CTYPE_XDIGT 512 - -struct _PDCLIB_ctype_t -{ - _PDCLIB_uint16_t flags; - unsigned char upper; - unsigned char lower; - unsigned char collation; -}; - /* -------------------------------------------------------------------------- */ /* locale / wchar / uchar */ /* -------------------------------------------------------------------------- */ @@ -383,7 +360,7 @@ typedef struct _PDCLIB_mbstate { }; } _PDCLIB_mbstate_t; -typedef struct _PDCLIB_charcodec _PDCLIB_charcodec_t; +typedef struct _PDCLIB_charcodec *_PDCLIB_charcodec_t; typedef struct _PDCLIB_locale *_PDCLIB_locale_t; typedef struct lconv _PDCLIB_lconv_t; diff --git a/internals/_PDCLIB_locale.h b/internals/_PDCLIB_locale.h index bed89b5..e99d9ca 100644 --- a/internals/_PDCLIB_locale.h +++ b/internals/_PDCLIB_locale.h @@ -1,12 +1,81 @@ #ifndef __PDCLIB_LOCALE_H #define __PDCLIB_LOCALE_H __PDCLIB_LOCALE_H +#include <_PDCLIB_int.h> #include +#include +#include -#define _PDCLIB_threadlocale() (uselocale(NULL)) +#define _PDCLIB_LOCALE_METHOD_TSS 't' +#define _PDCLIB_LOCALE_METHOD_THREAD_LOCAL 'T' + +#if !defined(_PDCLIB_LOCALE_METHOD) + #error _PDCLIB_LOCALE_METHOD undefined: don't know where I'm storing the thread locale +#elif _PDCLIB_LOCALE_METHOD == _PDCLIB_LOCALE_METHOD_TSS + extern tss_t _PDCLIB_locale_tss; + static inline locale_t _PDCLIB_threadlocale( void ) + { + locale_t l = tss_get(_PDCLIB_locale_tss); + if(l == NULL) + l = &_PDCLIB_global_locale; + return l; + } + + static inline void _PDCLIB_setthreadlocale( locale_t l ) + { + if(tss_set(_PDCLIB_locale_tss, l) != thrd_success) + abort(); + } +#elif _PDCLIB_LOCALE_METHOD == _PDCLIB_LOCALE_METHOD_THREAD_LOCAL + extern thread_local locale_t _PDCLIB_locale_tls; + #define _PDCLIB_threadlocale() (_PDCLIB_locale_tls || &_PDCLIB_global_locale) + static inline locale_t _PDCLIB_threadlocale( void ) + { + locale_t l = _PDCLIB_locale_tls; + if(l == NULL) + l = &_PDCLIB_global_locale; + return l; + } + + static inline void _PDCLIB_setthreadlocale( locale_t l ) + { + _PDCLIB_locale_tls = l; + } +#else + #error Locale TSS method unspecified +#endif + +/* -------------------------------------------------------------------------- */ +/* lookup tables */ +/* -------------------------------------------------------------------------- */ + +#define _PDCLIB_CTYPE_ALPHA 1 +#define _PDCLIB_CTYPE_BLANK 2 +#define _PDCLIB_CTYPE_CNTRL 4 +#define _PDCLIB_CTYPE_GRAPH 8 +#define _PDCLIB_CTYPE_PUNCT 16 +#define _PDCLIB_CTYPE_SPACE 32 +#define _PDCLIB_CTYPE_LOWER 64 +#define _PDCLIB_CTYPE_UPPER 128 +#define _PDCLIB_CTYPE_DIGIT 256 +#define _PDCLIB_CTYPE_XDIGT 512 + +typedef struct _PDCLIB_ctype +{ + _PDCLIB_uint16_t flags; + unsigned char upper; + unsigned char lower; + unsigned char collation; +} _PDCLIB_ctype_t; struct _PDCLIB_locale { - struct _PDCLIB_charcodec *_Codec; + _PDCLIB_charcodec_t _Codec; struct lconv _Conv; + + /* ctype */ + _PDCLIB_ctype_t *_CType; + + /* perror/strerror */ + char *_ErrnoStr[_PDCLIB_ERRNO_MAX]; }; #endif diff --git a/opt/basecodecs/_PDCLIB_ascii.c b/opt/basecodecs/_PDCLIB_ascii.c index d178a54..86001af 100644 --- a/opt/basecodecs/_PDCLIB_ascii.c +++ b/opt/basecodecs/_PDCLIB_ascii.c @@ -59,7 +59,7 @@ static bool c32toascii( return true; } -_PDCLIB_charcodec_t _PDCLIB_ascii_codec = { +struct _PDCLIB_charcodec _PDCLIB_ascii_codec = { .__mbstoc32s = asciitoc32, .__c32stombs = c32toascii, }; diff --git a/opt/basecodecs/_PDCLIB_latin1.c b/opt/basecodecs/_PDCLIB_latin1.c index cec13a0..b397001 100644 --- a/opt/basecodecs/_PDCLIB_latin1.c +++ b/opt/basecodecs/_PDCLIB_latin1.c @@ -57,7 +57,7 @@ static bool c32tolatin1( return true; } -_PDCLIB_charcodec_t _PDCLIB_latin1_codec = { +struct _PDCLIB_charcodec _PDCLIB_latin1_codec = { .__mbstoc32s = latin1toc32, .__c32stombs = c32tolatin1, }; diff --git a/opt/basecodecs/_PDCLIB_utf8.c b/opt/basecodecs/_PDCLIB_utf8.c index b0d3413..2b3f4f6 100644 --- a/opt/basecodecs/_PDCLIB_utf8.c +++ b/opt/basecodecs/_PDCLIB_utf8.c @@ -228,7 +228,7 @@ static bool c32toutf8( END_CONVERSION; } -_PDCLIB_charcodec_t _PDCLIB_utf8_codec = { +struct _PDCLIB_charcodec _PDCLIB_utf8_codec = { .__mbstoc32s = utf8toc32, .__c32stombs = c32toutf8, }; diff --git a/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c b/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c index 4c4ba4a..3f479f5 100644 --- a/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c +++ b/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c @@ -17,6 +17,7 @@ #ifndef REGTEST #include <_PDCLIB_io.h> +#include <_PDCLIB_locale.h> #include /* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file @@ -77,9 +78,11 @@ FILE * stdin = &_PDCLIB_sin; FILE * stdout = &_PDCLIB_sout; FILE * stderr = &_PDCLIB_serr; +tss_t _PDCLIB_locale_tss; /* Todo: Better solution than this! */ __attribute__((constructor)) void init_stdio(void) { + tss_create(&_PDCLIB_locale_tss, (tss_dtor_t) freelocale); mtx_init(&stdin->lock, mtx_recursive); mtx_init(&stdout->lock, mtx_recursive); mtx_init(&stderr->lock, mtx_recursive); @@ -92,7 +95,8 @@ FILE * _PDCLIB_filelist = &_PDCLIB_sin; 1 kByte (+ 4 byte) of data. Each line: flags, lowercase, uppercase, collation. */ -static struct _PDCLIB_ctype_t _ctype[] = { +static +_PDCLIB_ctype_t global_ctype[] = { { /* EOF */ 0, 0, 0, 0 }, { /* NUL */ _PDCLIB_CTYPE_CNTRL, 0x00, 0x00, 0x00 }, { /* SOH */ _PDCLIB_CTYPE_CNTRL, 0x01, 0x01, 0x01 }, @@ -352,15 +356,7 @@ static struct _PDCLIB_ctype_t _ctype[] = { { 0x00, 0xFF, 0xFF, 0xFF } }; -struct lconv _PDCLIB_lconv = { - /* _PDCLIB_ctype */ _ctype + 1, - /* _PDCLIB_errno_texts */ - { - /* no error */ (char *)"", - /* ERANGE */ (char *)"ERANGE (Range error)", - /* EDOM */ (char *)"EDOM (Domain error)", - /* EILSEQ */ (char *)"EILSEQ (Illegal sequence)" - }, +static struct lconv global_lconv = { /* decimal_point */ (char *)".", /* thousands_sep */ (char *)"", /* grouping */ (char *)"", @@ -387,6 +383,20 @@ struct lconv _PDCLIB_lconv = { /* int_n_sign_posn */ CHAR_MAX, }; +extern struct _PDCLIB_charcodec _PDCLIB_ascii_codec; +struct _PDCLIB_locale _PDCLIB_global_locale += { + ._Codec = &_PDCLIB_ascii_codec, + ._Conv = &global_lconv, + ._CType = &global_ctype[1], + ._ErrnoStr = { + /* no error */ (char *)"", + /* ERANGE */ (char *)"ERANGE (Range error)", + /* EDOM */ (char *)"EDOM (Domain error)", + /* EILSEQ */ (char *)"EILSEQ (Illegal sequence)" + }, +}; + #endif #ifdef TEST diff --git a/platform/posix/internals/_PDCLIB_config.h b/platform/posix/internals/_PDCLIB_config.h index 099e970..273f2d2 100644 --- a/platform/posix/internals/_PDCLIB_config.h +++ b/platform/posix/internals/_PDCLIB_config.h @@ -322,6 +322,11 @@ struct _PDCLIB_imaxdiv_t /* TODO: Better document these */ +/* Locale --------------------------------------------------------------------*/ + +/* Locale method. See _PDCLIB_locale.h */ +#define _PDCLIB_LOCALE_METHOD _PDCLIB_LOCALE_METHOD_TSS + /* I/O ---------------------------------------------------------------------- */ /* The default size for file buffers. Must be at least 256. */ diff --git a/platform/win32/internals/_PDCLIB_config.h b/platform/win32/internals/_PDCLIB_config.h index 5e91db5..4e40501 100644 --- a/platform/win32/internals/_PDCLIB_config.h +++ b/platform/win32/internals/_PDCLIB_config.h @@ -333,6 +333,11 @@ struct _PDCLIB_imaxdiv_t /* TODO: Better document these */ +/* Locale --------------------------------------------------------------------*/ + +/* Locale method. See _PDCLIB_locale.h */ +#define _PDCLIB_LOCALE_METHOD _PDCLIB_LOCALE_METHOD_TSS + /* I/O ---------------------------------------------------------------------- */ /* The default size for file buffers. Must be at least 256. */ -- 2.40.0