]> pd.if.org Git - pdclib/blobdiff - platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c
Local helpers made static, silencing compiler warnings.
[pdclib] / platform / posix / functions / _PDCLIB / _PDCLIB_stdinit.c
index 4c4ba4af8cf1465f45f6ea420e6c41f9e162c866..18fcc22efd0dbf7d2f457932eaa23dbc17ad430e 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /* _PDCLIB_stdinit
 
    This file is part of the Public Domain C Library (PDCLib).
@@ -17,6 +15,8 @@
 
 #ifndef REGTEST
 #include <_PDCLIB_io.h>
+#include <_PDCLIB_locale.h>
+#include <_PDCLIB_clocale.h>
 #include <threads.h>
 
 /* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file
@@ -77,13 +77,7 @@ FILE * stdin  = &_PDCLIB_sin;
 FILE * stdout = &_PDCLIB_sout;
 FILE * stderr = &_PDCLIB_serr;
 
-/* Todo: Better solution than this! */
-__attribute__((constructor)) void init_stdio(void)
-{
-    mtx_init(&stdin->lock,  mtx_recursive);
-    mtx_init(&stdout->lock, mtx_recursive);
-    mtx_init(&stderr->lock, mtx_recursive);
-}
+tss_t _PDCLIB_locale_tss;
 
 /* FIXME: This approach is a possible attack vector. */
 FILE * _PDCLIB_filelist = &_PDCLIB_sin;
@@ -92,7 +86,7 @@ FILE * _PDCLIB_filelist = &_PDCLIB_sin;
    1 kByte (+ 4 byte) of <ctype.h> data.
    Each line: flags, lowercase, uppercase, collation.
 */
-static struct _PDCLIB_ctype_t _ctype[] = {
+static const _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,41 +346,54 @@ static struct _PDCLIB_ctype_t _ctype[] = {
     { 0x00, 0xFF, 0xFF, 0xFF }
 };
 
-struct lconv _PDCLIB_lconv = { 
-    /* _PDCLIB_ctype      */ _ctype + 1,
-    /* _PDCLIB_errno_texts */
-    {
+extern const struct _PDCLIB_charcodec _PDCLIB_ascii_codec;
+struct _PDCLIB_locale _PDCLIB_global_locale = {
+    ._Codec = &_PDCLIB_ascii_codec,
+    ._Conv  = { 
+        /* decimal_point      */ (char *)".",
+        /* thousands_sep      */ (char *)"",
+        /* grouping           */ (char *)"",
+        /* mon_decimal_point  */ (char *)"",
+        /* mon_thousands_sep  */ (char *)"",
+        /* mon_grouping       */ (char *)"",
+        /* positive_sign      */ (char *)"",
+        /* negative_sign      */ (char *)"",
+        /* currency_symbol    */ (char *)"",
+        /* int_curr_symbol    */ (char *)"",
+        /* frac_digits        */ CHAR_MAX,
+        /* p_cs_precedes      */ CHAR_MAX,
+        /* n_cs_precedes      */ CHAR_MAX,
+        /* p_sep_by_space     */ CHAR_MAX,
+        /* n_sep_by_space     */ CHAR_MAX,
+        /* p_sign_posn        */ CHAR_MAX,
+        /* n_sign_posn        */ CHAR_MAX,
+        /* int_frac_digits    */ CHAR_MAX,
+        /* int_p_cs_precedes  */ CHAR_MAX,
+        /* int_n_cs_precedes  */ CHAR_MAX,
+        /* int_p_sep_by_space */ CHAR_MAX,
+        /* int_n_sep_by_space */ CHAR_MAX,
+        /* int_p_sign_posn    */ CHAR_MAX,
+        /* int_n_sign_posn    */ CHAR_MAX,
+    },
+    ._CType = &global_ctype[1],
+    ._ErrnoStr = {
         /* no error */ (char *)"",
         /* ERANGE   */ (char *)"ERANGE (Range error)",
         /* EDOM     */ (char *)"EDOM (Domain error)",
         /* EILSEQ   */ (char *)"EILSEQ (Illegal sequence)"
     },
-    /* decimal_point      */ (char *)".",
-    /* thousands_sep      */ (char *)"",
-    /* grouping           */ (char *)"",
-    /* mon_decimal_point  */ (char *)"",
-    /* mon_thousands_sep  */ (char *)"",
-    /* mon_grouping       */ (char *)"",
-    /* positive_sign      */ (char *)"",
-    /* negative_sign      */ (char *)"",
-    /* currency_symbol    */ (char *)"",
-    /* int_curr_symbol    */ (char *)"",
-    /* frac_digits        */ CHAR_MAX,
-    /* p_cs_precedes      */ CHAR_MAX,
-    /* n_cs_precedes      */ CHAR_MAX,
-    /* p_sep_by_space     */ CHAR_MAX,
-    /* n_sep_by_space     */ CHAR_MAX,
-    /* p_sign_posn        */ CHAR_MAX,
-    /* n_sign_posn        */ CHAR_MAX,
-    /* int_frac_digits    */ CHAR_MAX,
-    /* int_p_cs_precedes  */ CHAR_MAX,
-    /* int_n_cs_precedes  */ CHAR_MAX,
-    /* int_p_sep_by_space */ CHAR_MAX,
-    /* int_n_sep_by_space */ CHAR_MAX,
-    /* int_p_sign_posn    */ CHAR_MAX,
-    /* int_n_sign_posn    */ CHAR_MAX,
 };
 
+/* Todo: Better solution than this! */
+__attribute__((constructor)) static void init_stdio(void)
+{
+    _PDCLIB_initclocale( &_PDCLIB_global_locale );
+    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);
+}
+
 #endif
 
 #ifdef TEST