From: Stepan Kasal Date: Wed, 30 Apr 2014 22:28:36 GMT Subject: [PATCH] Win32: move main macro to a function Message-ID: <20140430222836.GB27914@camelia.ucw.cz> In-Reply-To: <20140430221728.GA27914@camelia.ucw.cz> From: Karsten Blees 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 Signed-off-by: Erik Faye-Lund Signed-off-by: Pat Thoyts Signed-off-by: Stepan Kasal --- 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) -- -- *** Please reply-to-all at all times *** *** (do not pretend to know who is subscribed and who is not) *** *** Please avoid top-posting. *** The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free. You received this message because you are subscribed to the Google Groups "msysGit" group. To post to this group, send email to msysgit@googlegroups.com To unsubscribe from this group, send email to msysgit+unsubscribe@googlegroups.com For more options, and view previous threads, visit this group at http://groups.google.com/group/msysgit?hl=en_US?hl=en --- You received this message because you are subscribed to the Google Groups "msysGit" group. To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.