From: Karsten Blees <blees@xxxxxxx> Date: Fri, 7 Jan 2011 19:47:23 +0100 The code in the MinGW main macro is getting more and more complex, move to a separate initialization function for readabiliy and extensibility. Signed-off-by: Karsten Blees <blees@xxxxxxx> Signed-off-by: Erik Faye-Lund <kusmabite@xxxxxxxxx> Signed-off-by: Pat Thoyts <patthoyts@xxxxxxxxxxxxxxxxxxxxx> Signed-off-by: Stepan Kasal <kasal@xxxxxx> --- Hello, this is commit 0115ef83 alias 9206e7fd that Karsten mentioned. Junio, this one has been in msysgit for 2 or 3 years, so you can suppose it is acked. Have a nice day, Stepan compat/mingw.c | 15 +++++++++++++++ compat/mingw.h | 16 +++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index e9892f8..1d11e9f 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1823,3 +1823,18 @@ pid_t waitpid(pid_t pid, int *status, int options) errno = EINVAL; return -1; } + +void mingw_startup() +{ + /* copy executable name to argv[0] */ + __argv[0] = xstrdup(_pgmptr); + + /* initialize critical section for waitpid pinfo_t list */ + InitializeCriticalSection(&pinfo_cs); + + /* set up default file mode and file modes for stdin/out/err */ + _fmode = _O_BINARY; + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); + _setmode(_fileno(stderr), _O_BINARY); +} diff --git a/compat/mingw.h b/compat/mingw.h index e033e72..95bcc75 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -361,22 +361,16 @@ void free_environ(char **env); extern CRITICAL_SECTION pinfo_cs; /* - * A replacement of main() that ensures that argv[0] has a path - * and that default fmode and std(in|out|err) are in binary mode + * A replacement of main() that adds win32 specific initialization. */ +void mingw_startup(); #define main(c,v) dummy_decl_mingw_main(); \ static int mingw_main(c,v); \ -int main(int argc, char **argv) \ +int main(c,v) \ { \ - extern CRITICAL_SECTION pinfo_cs; \ - _fmode = _O_BINARY; \ - _setmode(_fileno(stdin), _O_BINARY); \ - _setmode(_fileno(stdout), _O_BINARY); \ - _setmode(_fileno(stderr), _O_BINARY); \ - argv[0] = xstrdup(_pgmptr); \ - InitializeCriticalSection(&pinfo_cs); \ - return mingw_main(argc, argv); \ + mingw_startup(); \ + return mingw_main(__argc, __argv); \ } \ static int mingw_main(c,v) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html