X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fposix%2Ffunctions%2F_PDCLIB%2F_PDCLIB_stdinit.c;h=3f479f53889860e466e359f368e33171f53b5db1;hb=ed01ab8d9fcc47f6a4089ef72a73ef7a084d1ed3;hp=a3c9e8b6e2ec19025187f46c5ef0998e6c683581;hpb=6e4640ca32adb3f1ac3094664b2d7814d58777e2;p=pdclib.old diff --git a/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c b/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c index a3c9e8b..3f479f5 100644 --- a/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c +++ b/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c @@ -16,6 +16,8 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> +#include <_PDCLIB_locale.h> #include /* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file @@ -32,42 +34,39 @@ static unsigned char _PDCLIB_serr_ungetbuf[_PDCLIB_UNGETCBUFSIZE]; extern _PDCLIB_fileops_t _PDCLIB_fileops; -static struct _PDCLIB_file_t _PDCLIB_serr = { +static FILE _PDCLIB_serr = { .ops = &_PDCLIB_fileops, .handle = { .sval = 2 }, .buffer = _PDCLIB_serr_buffer, .bufsize = BUFSIZ, .bufidx = 0, .bufend = 0, - .pos = { 0, 0 }, .ungetidx = 0, .ungetbuf = _PDCLIB_serr_ungetbuf, .status = _IONBF | _PDCLIB_FWRITE | _PDCLIB_STATIC, .filename = NULL, .next = NULL, }; -static struct _PDCLIB_file_t _PDCLIB_sout = { +static FILE _PDCLIB_sout = { .ops = &_PDCLIB_fileops, .handle = { .sval = 1 }, .buffer = _PDCLIB_sout_buffer, .bufsize = BUFSIZ, .bufidx = 0, .bufend = 0, - .pos = { 0, 0 }, .ungetidx = 0, .ungetbuf = _PDCLIB_sout_ungetbuf, .status = _IOLBF | _PDCLIB_FWRITE | _PDCLIB_STATIC, .filename = NULL, .next = &_PDCLIB_serr }; -static struct _PDCLIB_file_t _PDCLIB_sin = { +static FILE _PDCLIB_sin = { .ops = &_PDCLIB_fileops, .handle = { .sval = 0 }, .buffer = _PDCLIB_sin_buffer, .bufsize = BUFSIZ, .bufidx = 0, .bufend = 0, - .pos = { 0, 0 }, .ungetidx = 0, .ungetbuf = _PDCLIB_sin_ungetbuf, .status = _IOLBF | _PDCLIB_FREAD | _PDCLIB_STATIC, @@ -75,26 +74,29 @@ static struct _PDCLIB_file_t _PDCLIB_sin = { .next = &_PDCLIB_sout }; -struct _PDCLIB_file_t * stdin = &_PDCLIB_sin; -struct _PDCLIB_file_t * stdout = &_PDCLIB_sout; -struct _PDCLIB_file_t * stderr = &_PDCLIB_serr; +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); } /* FIXME: This approach is a possible attack vector. */ -struct _PDCLIB_file_t * _PDCLIB_filelist = &_PDCLIB_sin; +FILE * _PDCLIB_filelist = &_PDCLIB_sin; /* "C" locale - defaulting to ASCII-7. 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 }, @@ -354,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 *)"", @@ -389,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