From 0b710a08982eb517fe8fd428b09d5cea013df7c7 Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Fri, 7 Jan 2011 19:47:23 +0100 Subject: [PATCH] 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 --- compat/mingw.c | 15 +++++++++++++++ compat/mingw.h | 16 +++++----------- http-fetch.c | 3 ++- remote-curl.c | 3 ++- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 7692aa70cf..b88956a758 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 95e289b1d7..dc9b0e5d8d 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) \ +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) diff --git a/http-fetch.c b/http-fetch.c index ba3ea10670..51b26d7af8 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -6,11 +6,12 @@ static const char http_fetch_usage[] = "git http-fetch " "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url"; -int main(int argc, const char **argv) +int main(int argc, char **av) { struct walker *walker; int commits_on_stdin = 0; int commits; + const char **argv = (const char **)av; const char **write_ref = NULL; char **commit_id; char *url = NULL; diff --git a/remote-curl.c b/remote-curl.c index 52c2d96ce6..060a65430a 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -938,9 +938,10 @@ static void parse_push(struct strbuf *buf) free(specs); } -int main(int argc, const char **argv) +int main(int argc, char **av) { struct strbuf buf = STRBUF_INIT; + const char **argv = (const char **)av; int nongit; git_extract_argv0_path(argv[0]);