X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=platform%2Fposix%2Ffunctions%2F_PDCLIB%2F_PDCLIB_stdinit.c;h=18fcc22efd0dbf7d2f457932eaa23dbc17ad430e;hp=7d246795343005361247e6805a584d28b4b1614b;hb=14bc57c5c4d93263e08fe50e67eb61815cd0592f;hpb=222cb240ebb173f5d71546cdb92f8d0f1d4a3a6f diff --git a/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c b/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c index 7d24679..18fcc22 100644 --- a/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c +++ b/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /* _PDCLIB_stdinit This file is part of the Public Domain C Library (PDCLib). @@ -18,6 +16,7 @@ #ifndef REGTEST #include <_PDCLIB_io.h> #include <_PDCLIB_locale.h> +#include <_PDCLIB_clocale.h> #include /* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file @@ -79,14 +78,6 @@ 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); -} /* FIXME: This approach is a possible attack vector. */ FILE * _PDCLIB_filelist = &_PDCLIB_sin; @@ -95,8 +86,7 @@ FILE * _PDCLIB_filelist = &_PDCLIB_sin; 1 kByte (+ 4 byte) of data. Each line: flags, lowercase, uppercase, collation. */ -static -_PDCLIB_ctype_t global_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 }, @@ -356,7 +346,7 @@ _PDCLIB_ctype_t global_ctype[] = { { 0x00, 0xFF, 0xFF, 0xFF } }; -extern struct _PDCLIB_charcodec _PDCLIB_ascii_codec; +extern const struct _PDCLIB_charcodec _PDCLIB_ascii_codec; struct _PDCLIB_locale _PDCLIB_global_locale = { ._Codec = &_PDCLIB_ascii_codec, ._Conv = { @@ -394,6 +384,16 @@ struct _PDCLIB_locale _PDCLIB_global_locale = { }, }; +/* 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