From fb878a0af84bd58da55d2d64a15b226529d2dd0f Mon Sep 17 00:00:00 2001 From: Nicolas Ojeda Bar Date: Thu, 21 Sep 2017 11:21:07 +0200 Subject: headernt.c: fix read_runtime_path --- stdlib/Makefile | 6 +++--- stdlib/headernt.c | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/stdlib/Makefile b/stdlib/Makefile index cd659d6dd0..5f7bde13e3 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -158,7 +158,7 @@ else # Windows camlheader target_camlheader camlheader_ur: headernt.c $(CC) -c $(CFLAGS) $(CPPFLAGS) -I../byterun \ - -DRUNTIME_NAME='L"ocamlrun"' $(OUTPUTOBJ)headernt.$(O) $< + -DRUNTIME_NAME='"ocamlrun"' $(OUTPUTOBJ)headernt.$(O) $< $(MKEXE) -o tmpheader.exe headernt.$(O) $(EXTRALIBS) rm -f camlheader.exe mv tmpheader.exe camlheader @@ -167,14 +167,14 @@ camlheader target_camlheader camlheader_ur: headernt.c camlheaderd target_camlheaderd: headernt.c $(CC) -c $(CFLAGS) $(CPPFLAGS) -I../byterun \ - -DRUNTIME_NAME='L"ocamlrund"' $(OUTPUTOBJ)headernt.$(O) $< + -DRUNTIME_NAME='"ocamlrund"' $(OUTPUTOBJ)headernt.$(O) $< $(MKEXE) -o tmpheader.exe headernt.$(O) $(EXTRALIBS) mv tmpheader.exe camlheaderd cp camlheaderd target_camlheaderd camlheaderi: headernt.c $(CC) -c $(CFLAGS) $(CPPFLAGS) -I../byterun \ - -DRUNTIME_NAME='L"ocamlruni"' $(OUTPUTOBJ)headernt.$(O) + -DRUNTIME_NAME='"ocamlruni"' $(OUTPUTOBJ)headernt.$(O) $(MKEXE) -o tmpheader.exe headernt.$(O) $(EXTRALIBS) mv tmpheader.exe camlheaderi diff --git a/stdlib/headernt.c b/stdlib/headernt.c index c6bcea1ba6..93cc1afe0a 100644 --- a/stdlib/headernt.c +++ b/stdlib/headernt.c @@ -31,7 +31,7 @@ #endif #endif -wchar_t * default_runtime_name = RUNTIME_NAME; +char * default_runtime_name = RUNTIME_NAME; static #if _MSC_VER >= 1200 @@ -46,10 +46,10 @@ unsigned long read_size(const char * const ptr) ((unsigned long) p[2] << 8) | p[3]; } -static __inline wchar_t * read_runtime_path(HANDLE h) +static __inline char * read_runtime_path(HANDLE h) { char buffer[TRAILER_SIZE]; - static wchar_t runtime_path[MAX_PATH]; + static char runtime_path[MAX_PATH]; DWORD nread; int num_sections, path_size, i; long ofs; @@ -87,6 +87,12 @@ static BOOL WINAPI ctrl_handler(DWORD event) return FALSE; } +#if WINDOWS_UNICODE +#define CP CP_UTF8 +#else +#define CP CP_THREAD_ACP +#endif + #define msg_and_length(msg) msg , (sizeof(msg) - 1) static __inline void __declspec(noreturn) run_runtime(wchar_t * runtime, @@ -101,9 +107,9 @@ static __inline void __declspec(noreturn) run_runtime(wchar_t * runtime, char runtime_cp[MAX_PATH]; DWORD numwritten; errh = GetStdHandle(STD_ERROR_HANDLE); - WideCharToMultiByte(CP_UTF8, 0, runtime, -1, runtime_cp, sizeof(runtime_cp), NULL, NULL); + WideCharToMultiByte(CP, 0, runtime, -1, runtime_cp, sizeof(runtime_cp), NULL, NULL); WriteFile(errh, msg_and_length("Cannot exec "), &numwritten, NULL); - WriteFile(errh, msg_and_length(runtime_cp), &numwritten, NULL); + WriteFile(errh, runtime_cp, strlen(runtime_cp), &numwritten, NULL); WriteFile(errh, msg_and_length("\r\n"), &numwritten, NULL); ExitProcess(2); #if _MSC_VER >= 1200 @@ -127,6 +133,7 @@ static __inline void __declspec(noreturn) run_runtime(wchar_t * runtime, char runtime_cp[MAX_PATH]; DWORD numwritten; errh = GetStdHandle(STD_ERROR_HANDLE); + WideCharToMultiByte(CP, 0, runtime, -1, runtime_cp, sizeof(runtime_cp), NULL, NULL); WriteFile(errh, msg_and_length("Cannot exec "), &numwritten, NULL); WriteFile(errh, runtime_cp, strlen(runtime_cp), &numwritten, NULL); WriteFile(errh, msg_and_length("\r\n"), &numwritten, NULL); @@ -149,7 +156,8 @@ int wmain(void) { wchar_t truename[MAX_PATH]; wchar_t * cmdline = GetCommandLine(); - wchar_t * runtime_path; + char * runtime_path; + wchar_t wruntime_path[MAX_PATH]; HANDLE h; GetModuleFileName(NULL, truename, sizeof(truename)/sizeof(wchar_t)); @@ -161,8 +169,8 @@ int wmain(void) char truename_cp[MAX_PATH]; DWORD numwritten; errh = GetStdHandle(STD_ERROR_HANDLE); - WideCharToMultiByte(CP_UTF8, 0, truename, -1, truename_cp, sizeof(truename_cp), NULL, NULL); - WriteFile(errh, msg_and_length(truename_cp), &numwritten, NULL); + WideCharToMultiByte(CP, 0, truename, -1, truename_cp, sizeof(truename_cp), NULL, NULL); + WriteFile(errh, truename_cp, strlen(truename_cp), &numwritten, NULL); WriteFile(errh, msg_and_length(" not found or is not a bytecode" " executable file\r\n"), &numwritten, NULL); @@ -172,7 +180,8 @@ int wmain(void) #endif } CloseHandle(h); - run_runtime(runtime_path , cmdline); + MultiByteToWideChar(CP, 0, runtime_path, -1, wruntime_path, sizeof(wruntime_path)/sizeof(wchar_t)); + run_runtime(wruntime_path , cmdline); #if _MSC_VER >= 1200 __assume(0); /* Not reached */ #endif -- cgit v1.2.1