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

[PATCH 02/11] Fix declare variable at mid of function

From
Frank Li <lznuaa@gmail.com>
Date
Aug 17, 2009, 16:01 UTC
Message-ID
<1250524872-5148-2-git-send-email-lznuaa@gmail.com>
In-Reply-To
<1250524872-5148-1-git-send-email-lznuaa@gmail.com>
Some compiler such as MSVC can't support declear variable at mid of funtion at c file.
Signed-off-by: Frank Li <lznuaa@gmail.com>
---
 compat/mingw.c |   16 ++++++++++++----
 help.c         |    3 ++-
 run-command.c  |    2 ++
 3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index bed4178..75c74b1 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -123,13 +123,17 @@ int mingw_open (const char *filename, int oflags, ...)
 {
 	va_list args;
 	unsigned mode;
+	int fd;
+
 	va_start(args, oflags);
 	mode = va_arg(args, int);
 	va_end(args);
 
 	if (!strcmp(filename, "/dev/null"))
 		filename = "nul";
-	int fd = open(filename, oflags, mode);
+
+	fd = open(filename, oflags, mode);
+
 	if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) {
 		DWORD attrs = GetFileAttributes(filename);
 		if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY))
@@ -580,10 +584,11 @@ static char **get_path_split(void)
 
 static void free_path_split(char **path)
 {
+	char **p = path;
+
 	if (!path)
 		return;
 
-	char **p = path;
 	while (*p)
 		free(*p++);
 	free(path);
@@ -1108,9 +1113,11 @@ int sigaction(int sig, struct sigaction *in, struct sigaction *out)
 #undef signal
 sig_handler_t mingw_signal(int sig, sig_handler_t handler)
 {
+	sig_handler_t old;
+
 	if (sig != SIGALRM)
 		return signal(sig, handler);
-	sig_handler_t old = timer_fn;
+	old = timer_fn;
 	timer_fn = handler;
 	return old;
 }
@@ -1197,8 +1204,9 @@ struct dirent *mingw_readdir(DIR *dir)
 
 	if (dir->dd_handle == (long)INVALID_HANDLE_VALUE && dir->dd_stat == 0)
 	{
+		DWORD lasterr;
 		handle = FindFirstFileA(dir->dd_name, &buf);
-		DWORD lasterr = GetLastError();
+		lasterr = GetLastError();
 		dir->dd_handle = (long)handle;
 		if (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES)) {
 			errno = err_win_to_posix(lasterr);
diff --git a/help.c b/help.c
index 6c46d8b..399b0b4 100644
--- a/help.c
+++ b/help.c
@@ -127,7 +127,7 @@ static int is_executable(const char *name)
 		return 0;
 
 #ifdef __MINGW32__
-	/* cannot trust the executable bit, peek into the file instead */
+{	/* cannot trust the executable bit, peek into the file instead */
 	char buf[3] = { 0 };
 	int n;
 	int fd = open(name, O_RDONLY);
@@ -140,6 +140,7 @@ static int is_executable(const char *name)
 				st.st_mode |= S_IXUSR;
 		close(fd);
 	}
+}
 #endif
 	return st.st_mode & S_IXUSR;
 }
diff --git a/run-command.c b/run-command.c
index ff3d8e2..d1df7ab 100644
--- a/run-command.c
+++ b/run-command.c
@@ -123,6 +123,7 @@ int start_command(struct child_process *cmd)
 		exit(127);
 	}
 #else
+{
 	int s0 = -1, s1 = -1, s2 = -1;	/* backups of stdin, stdout, stderr */
 	const char **sargv = cmd->argv;
 	char **env = environ;
@@ -186,6 +187,7 @@ int start_command(struct child_process *cmd)
 		dup2(s1, 1), close(s1);
 	if (s2 >= 0)
 		dup2(s2, 2), close(s2);
+}
 #endif
 
 	if (cmd->pid < 0) {
-- 
1.6.4.msysgit.0
Previous: Frank LiNext: Frank Li
Message 2 of 26 in “Fix build failure at VC because function declare use old style at regex.c”
  1. 01/11 Fix build failure at VC because function declare use old style at regex.cFrank Li, Aug 17, 2009
  2. 02/11 Fix declare variable at mid of functionFrank Li, Aug 17, 2009
  3. 03/11 Define SNPRINTF_SIZE_CORR 1 when use MSVC build gitFrank Li, Aug 17, 2009
  4. 04/11 Add _MSC_VER predefine macro to make same behaviors with __MINGW32__ Enable MSVC build. MSVC have the save behaviors with msysgit.Frank Li, Aug 17, 2009
  5. Johannes SchindelinAug 17, 2009
  6. Frank LiAug 18, 2009
  7. tom fogalAug 18, 2009
  8. Johannes SchindelinAug 17, 2009
  9. Frank LiAug 18, 2009
  10. Johannes SchindelinAug 18, 2009
  11. Johannes SchindelinAug 17, 2009
  12. Reece DunnAug 17, 2009
  13. Johannes SchindelinAug 17, 2009
  14. Marius Storm-OlsenAug 18, 2009
  15. Johannes SchindelinAug 18, 2009
  16. Frank LiAug 18, 2009
  17. Matthieu MoyAug 18, 2009
  18. Johannes SchindelinAug 19, 2009
  19. Johannes SixtAug 19, 2009
  20. Johannes SchindelinAug 19, 2009
  21. Johannes SixtAug 19, 2009
  22. Junio C HamanoAug 17, 2009
  23. Johannes SchindelinAug 17, 2009
  24. Junio C HamanoAug 17, 2009
  25. Johannes SchindelinAug 17, 2009
  26. Frank LiAug 18, 2009

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.