Win32: move main macro to a function

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@dcon.de> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Stepan Kasal <kasal@ucw.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karsten Blees committed Jan 7, 2011 at 19:47 UTC 13f1df432ea78a9dda2e70036215f754db182934
2 files changed +19 -10
compat/mingw.c
+15
@@ -1847,3 +1847,18 @@ int mingw_offset_1st_component(const char *path)
1847
1848 return offset + is_dir_sep(path[offset]);
1849 }
1850 +
1851 +void mingw_startup()
1852 +{
1853 + /* copy executable name to argv[0] */
1854 + __argv[0] = xstrdup(_pgmptr);
1855 +
1856 + /* initialize critical section for waitpid pinfo_t list */
1857 + InitializeCriticalSection(&pinfo_cs);
1858 +
1859 + /* set up default file mode and file modes for stdin/out/err */
1860 + _fmode = _O_BINARY;
1861 + _setmode(_fileno(stdin), _O_BINARY);
1862 + _setmode(_fileno(stdout), _O_BINARY);
1863 + _setmode(_fileno(stderr), _O_BINARY);
1864 +}
compat/mingw.h
+4 -10
@@ -363,22 +363,16 @@ void free_environ(char **env);
363 extern CRITICAL_SECTION pinfo_cs;
364
365 /*
366 - * A replacement of main() that ensures that argv[0] has a path
367 - * and that default fmode and std(in|out|err) are in binary mode
366 + * A replacement of main() that adds win32 specific initialization.
367 */
368
369 +void mingw_startup();
370 #define main(c,v) dummy_decl_mingw_main(); \
371 static int mingw_main(c,v); \
372 int main(int argc, char **argv) \
373 { \
374 - extern CRITICAL_SECTION pinfo_cs; \
375 - _fmode = _O_BINARY; \
376 - _setmode(_fileno(stdin), _O_BINARY); \
377 - _setmode(_fileno(stdout), _O_BINARY); \
378 - _setmode(_fileno(stderr), _O_BINARY); \
379 - argv[0] = xstrdup(_pgmptr); \
380 - InitializeCriticalSection(&pinfo_cs); \
381 - return mingw_main(argc, argv); \
374 + mingw_startup(); \
375 + return mingw_main(__argc, __argv); \
376 } \
377 static int mingw_main(c,v)
378