From 13f1df432ea78a9dda2e70036215f754db182934 Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Fri, 7 Jan 2011 19:47:23 +0100 Subject: 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 Signed-off-by: Erik Faye-Lund Signed-off-by: Stepan Kasal Signed-off-by: Junio C Hamano --- compat/mingw.c | 15 +++++++++++++++ compat/mingw.h | 14 ++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'compat') diff --git a/compat/mingw.c b/compat/mingw.c index a0e13bc862..c03bafa9c4 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1847,3 +1847,18 @@ int mingw_offset_1st_component(const char *path) return offset + is_dir_sep(path[offset]); } + +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 3eaf822e28..15f0c9d790 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -363,22 +363,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) \ { \ - 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) -- cgit v1.2.3 From a15d4af4497d147bfdb672e121b67db335ec1c21 Mon Sep 17 00:00:00 2001 From: Stepan Kasal Date: Sat, 7 Jun 2014 08:46:41 +0200 Subject: mingw: avoid const warning Fix const warnings in http-fetch.c and remote-curl.c main() where is argv declared as const. The fix should work for all future declarations of main, no matter whether the second parameter's type is "char**", "const char**", or "char *[]". Signed-off-by: Stepan Kasal Signed-off-by: Junio C Hamano --- compat/mingw.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compat') diff --git a/compat/mingw.h b/compat/mingw.h index 15f0c9d790..6dc8b1a1b4 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -372,7 +372,7 @@ static int mingw_main(c,v); \ int main(int argc, char **argv) \ { \ mingw_startup(); \ - return mingw_main(__argc, __argv); \ + return mingw_main(__argc, (void *)__argv); \ } \ static int mingw_main(c,v) -- cgit v1.2.3