]> pd.if.org Git - pdclib.old/blobdiff - platform/win32/crt0.c
PDCLIB-15 PDCLIB-16:
[pdclib.old] / platform / win32 / crt0.c
index f7f6a925243cc76ebb59e4b1fe0661abf4f1cd8d..7da2a8151e2ad3b279e0c9005d45b8b56b22c919 100644 (file)
@@ -1,8 +1,10 @@
-#include <windows.h>\r
 #include <string.h>\r
 #include <stdlib.h>\r
 #include <stdio.h>\r
 #include <signal.h>\r
+#include <threads.h>\r
+#include <wchar.h> // Watcom bug: winnt.h assumes string.h defines wchar_t\r
+#include <windows.h>\r
 \r
 static char ** argvToAnsi( wchar_t ** wargv, int argc )\r
 {\r
@@ -22,6 +24,7 @@ static char ** argvToAnsi( wchar_t ** wargv, int argc )
         if(rv != sz) {\r
             fputs("Error in C runtime initialization: "\r
                   "size mismatch during character set conversion", stderr);\r
+            abort();\r
         }\r
     }\r
     return argv;\r
@@ -96,7 +99,10 @@ static LONG CALLBACK sehExceptionFilter( EXCEPTION_POINTERS * exInfo )
 }\r
 \r
 extern int main( int argc, char ** argv, char ** envp );\r
-_PDCLIB_noreturn void mainCRTStartup( void ) \r
+\r
+void __cdecl mainCRTStartup( void );\r
+\r
+void __cdecl mainCRTStartup( void ) \r
 {\r
     stdin->handle  = GetStdHandle(STD_INPUT_HANDLE);\r
     stdout->handle = GetStdHandle(STD_OUTPUT_HANDLE);\r
@@ -107,9 +113,17 @@ _PDCLIB_noreturn void mainCRTStartup( void )
     cl    = GetCommandLineW();\r
     wargv = CommandLineToArgvW(cl, &argc);\r
     argv  = argvToAnsi(wargv, argc);\r
+\r
+    if(        mtx_init(&stdin->lock, mtx_recursive) != thrd_success \r
+            || mtx_init(&stdout->lock, mtx_recursive) != thrd_success\r
+            || mtx_init(&stderr->lock, mtx_recursive) != thrd_success ) {\r
+        fputs( "Error during C runtime initialization: "\r
+            "Unable to allocate stdio mutex", stderr );\r
+    }\r
+\r
     atexit(freeArgs);\r
 \r
     int exitStatus = main(argc, argv, NULL);\r
 \r
     exit(exitStatus);\r
-}\r
+}
\ No newline at end of file