From 1e015144a5b4f3280bec128f8889a1abf08ecef7 Mon Sep 17 00:00:00 2001 From: "nospam.kotarou.dono@gmail.com" Date: Mon, 22 Aug 2011 14:22:03 +0200 Subject: [PATCH] Bug 672024 - Mingw build error: undefined reference to `WinMain@16\' in nsinstall_win.c r=khuey --- config/nsinstall_win.c | 32 ++++++++++++++++++++++++++++++++ js/src/config/nsinstall_win.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/config/nsinstall_win.c b/config/nsinstall_win.c index d9b723b2c7c5..1c1623f82fa0 100644 --- a/config/nsinstall_win.c +++ b/config/nsinstall_win.c @@ -41,6 +41,38 @@ static BOOL sh_DoCopy(wchar_t *srcFileName, DWORD srcFileAttributes, #define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0])) #define STR_LEN(a) (ARRAY_LEN(a) - 1) +#ifdef __MINGW32__ + +/* MingW currently does not implement a wide version of the + startup routines. Workaround is to implement something like + it ourselves. */ + +#include + +int wmain(int argc, WCHAR **argv); + +int main(int argc, char **argv) +{ + int result; + wchar_t *commandLine = GetCommandLineW(); + int argcw = 0; + wchar_t **_argvw = CommandLineToArgvW( commandLine, &argcw ); + wchar_t *argvw[argcw + 1]; + int i; + if (!_argvw) + return 127; + /* CommandLineToArgvW doesn't output the ending NULL so + we have to manually add it on */ + for ( i = 0; i < argcw; i++ ) + argvw[i] = _argvw[i]; + argvw[argcw] = NULL; + + result = wmain(argcw, argvw); + LocalFree(_argvw); + return result; +} +#endif /* __MINGW32__ */ + /* changes all forward slashes in token to backslashes */ void changeForwardSlashesToBackSlashes ( wchar_t *arg ) { diff --git a/js/src/config/nsinstall_win.c b/js/src/config/nsinstall_win.c index d9b723b2c7c5..1c1623f82fa0 100644 --- a/js/src/config/nsinstall_win.c +++ b/js/src/config/nsinstall_win.c @@ -41,6 +41,38 @@ static BOOL sh_DoCopy(wchar_t *srcFileName, DWORD srcFileAttributes, #define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0])) #define STR_LEN(a) (ARRAY_LEN(a) - 1) +#ifdef __MINGW32__ + +/* MingW currently does not implement a wide version of the + startup routines. Workaround is to implement something like + it ourselves. */ + +#include + +int wmain(int argc, WCHAR **argv); + +int main(int argc, char **argv) +{ + int result; + wchar_t *commandLine = GetCommandLineW(); + int argcw = 0; + wchar_t **_argvw = CommandLineToArgvW( commandLine, &argcw ); + wchar_t *argvw[argcw + 1]; + int i; + if (!_argvw) + return 127; + /* CommandLineToArgvW doesn't output the ending NULL so + we have to manually add it on */ + for ( i = 0; i < argcw; i++ ) + argvw[i] = _argvw[i]; + argvw[argcw] = NULL; + + result = wmain(argcw, argvw); + LocalFree(_argvw); + return result; +} +#endif /* __MINGW32__ */ + /* changes all forward slashes in token to backslashes */ void changeForwardSlashesToBackSlashes ( wchar_t *arg ) {