X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fwin32%2Fcrt0.c;h=533ee98b862785cb6cabaee6be391629bf7bedd6;hb=fa53a74861e1ac9513ae57b7bd7889b85ac0fbe9;hp=e910bd1168c39283bd8fd2b970c247f05f1fe79a;hpb=0d8c88997f429be369fc6bd1b45a6b437fcee923;p=pdclib diff --git a/platform/win32/crt0.c b/platform/win32/crt0.c index e910bd1..533ee98 100644 --- a/platform/win32/crt0.c +++ b/platform/win32/crt0.c @@ -2,8 +2,12 @@ #include #include #include +#include #include // Watcom bug: winnt.h assumes string.h defines wchar_t #include +#include <_PDCLIB_io.h> +#include <_PDCLIB_locale.h> +#include <_PDCLIB_clocale.h> static char ** argvToAnsi( wchar_t ** wargv, int argc ) { @@ -23,6 +27,7 @@ static char ** argvToAnsi( wchar_t ** wargv, int argc ) if(rv != sz) { fputs("Error in C runtime initialization: " "size mismatch during character set conversion", stderr); + abort(); } } return argv; @@ -98,17 +103,37 @@ static LONG CALLBACK sehExceptionFilter( EXCEPTION_POINTERS * exInfo ) extern int main( int argc, char ** argv, char ** envp ); +void __cdecl mainCRTStartup( void ); + void __cdecl mainCRTStartup( void ) { - stdin->handle = GetStdHandle(STD_INPUT_HANDLE); - stdout->handle = GetStdHandle(STD_OUTPUT_HANDLE); - stderr->handle = GetStdHandle(STD_ERROR_HANDLE); + stdin->handle.pointer = GetStdHandle(STD_INPUT_HANDLE); + stdout->handle.pointer = GetStdHandle(STD_OUTPUT_HANDLE); + stderr->handle.pointer = GetStdHandle(STD_ERROR_HANDLE); oldFilter = SetUnhandledExceptionFilter( sehExceptionFilter ); cl = GetCommandLineW(); wargv = CommandLineToArgvW(cl, &argc); argv = argvToAnsi(wargv, argc); + + _PDCLIB_initclocale( &_PDCLIB_global_locale ); + + if(tss_create(&_PDCLIB_locale_tss, (tss_dtor_t) freelocale) + != thrd_success) { + fputs( "Error during C runtime initialization: " + "Unable to allocate locale TLS", stderr ); + exit( EXIT_FAILURE ); + } + + if( mtx_init(&stdin->lock, mtx_recursive) != thrd_success + || mtx_init(&stdout->lock, mtx_recursive) != thrd_success + || mtx_init(&stderr->lock, mtx_recursive) != thrd_success ) { + fputs( "Error during C runtime initialization: " + "Unable to allocate stdio mutex", stderr ); + exit( EXIT_FAILURE ); + } + atexit(freeArgs); int exitStatus = main(argc, argv, NULL);