Win32: move main macro to a function
authorKarsten Blees <blees@dcon.de>
Fri, 7 Jan 2011 18:47:23 +0000 (19:47 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 10 Jun 2014 20:31:01 +0000 (13:31 -0700)
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>
compat/mingw.c
compat/mingw.h
index a0e13bc862c052d8c18a6cba1c47a5a15fd12f7b..c03bafa9c44644e4b5d92fafbe99b1845e7ef768 100644 (file)
@@ -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);
+}
index 3eaf822e28e23e6e46e82a9bb7c9db1ed42d252c..15f0c9d790f4da850c98f2da0571955f922a2114 100644 (file)
@@ -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)