X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fwin32%2Fcrt0.c;h=d32a6ac703976a8e2793a6c04d5be482b9aba575;hb=c5d49235e09fbd58416f10dec2799e61cf3431c8;hp=076e76e464423df47ae0d5320407bf5b73f301f7;hpb=52f7a90845d89794451eff82982d6fa785d7ef8d;p=pdclib diff --git a/platform/win32/crt0.c b/platform/win32/crt0.c index 076e76e..d32a6ac 100644 --- a/platform/win32/crt0.c +++ b/platform/win32/crt0.c @@ -2,6 +2,7 @@ #include #include #include +#include #include // Watcom bug: winnt.h assumes string.h defines wchar_t #include @@ -103,15 +104,23 @@ 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); + + 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 ); + } + atexit(freeArgs); int exitStatus = main(argc, argv, NULL);