git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Win32: move main macro to a function

From
Stepan Kasal <kasal@ucw.cz>
Date
Apr 30, 2014, 22:28 UTC
Message-ID
<20140430222836.GB27914@camelia.ucw.cz>
In-Reply-To
<20140430221728.GA27914@camelia.ucw.cz>
From: Karsten Blees <blees@dcon.de>
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 <blees@dcon.de>
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
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.
Previous: Stepan KasalNext: Marat Radchenko
Message 15 of 29 in “MinGW(-W64) cross-compilation”
  1. MinGW(-W64) cross-compilationMarat Radchenko, Apr 29, 2014
  2. 01/12 MINGW: compat/mingw.h: do not attempt to redefine lseek on mingw-w64Marat Radchenko, Apr 29, 2014
  3. 02/12 MSVC: config.mak.uname: drop -D__USE_MINGW_ACCESS from CFLAGSMarat Radchenko, Apr 29, 2014
  4. 03/12 MINGW: compat/mingw.h: drop fork() definitionMarat Radchenko, Apr 29, 2014
  5. 04/12 MINGW: do not fail at redefining pid_t on MinGW-W64Marat Radchenko, Apr 29, 2014
  6. 05/12 MINGW: config.mak.uname: allow using cURL for non-msysGit buildsMarat Radchenko, Apr 29, 2014
  7. 06/12 MINGW: git-compat-util.h: use inttypes.h for printf macrosMarat Radchenko, Apr 29, 2014
  8. 07/12 MINGW: config.mak.uname: reorganize MINGW settingsMarat Radchenko, Apr 29, 2014
  9. 08/12 MINGW: fix main() signature in http-fetch.c and remote-curl.cMarat Radchenko, Apr 29, 2014
  10. Karsten BleesApr 30, 2014
  11. Erik Faye-LundApr 30, 2014
  12. Johannes SchindelinApr 30, 2014
  13. Felipe ContrerasApr 30, 2014
  14. Stepan KasalApr 30, 2014
  15. Win32: move main macro to a functionStepan Kasal, Apr 30, 2014
  16. Marat RadchenkoMay 3, 2014
  17. 09/12 Makefile: introduce CROSS_COMPILE variableMarat Radchenko, Apr 29, 2014
  18. 10/12 MINGW: compat/poll/poll.c: undef NOGDIMarat Radchenko, Apr 29, 2014
  19. Stepan KasalApr 30, 2014
  20. Marat RadchenkoMay 3, 2014
  21. Stepan KasalMay 4, 2014
  22. Marat RadchenkoMay 4, 2014
  23. '502304919' via msysGitMay 4, 2014
  24. Stepan KasalMay 5, 2014
  25. Felipe ContrerasMay 5, 2014
  26. Stepan KasalMay 5, 2014
  27. Felipe ContrerasMay 4, 2014
  28. 11/12 compat/nedmalloc/malloc.c.h: fix compilation under MinGW-W64Marat Radchenko, Apr 29, 2014
  29. 12/12 MINGW: config.mak.uname: add explicit way to request MinGW-buildMarat Radchenko, Apr 29, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.