Re: [PATCH 05/14] Change regerror() declaration from K&R style to ANSI C (C89)

Previous thread: Display bug in gitk -S by Martin Stjernholm on Friday, August 21, 2009 - 4:46 am. (1 message)

Next thread: [PATCH 01/14] Fix non-constant array creation by Marius Storm-Olsen on Friday, August 21, 2009 - 6:30 am. (16 messages)
From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 6:30 am

Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/win32.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/compat/win32.h b/compat/win32.h
index c26384e..e8c178d 100644
--- a/compat/win32.h
+++ b/compat/win32.h
@@ -1,3 +1,6 @@
+#ifndef WIN32_H
+#define WIN32_H
+
 /* common Win32 functions for MinGW and Cygwin */
 #include <windows.h>
 
@@ -32,3 +35,5 @@ static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fd
 		return ENOENT;
 	}
 }
+
+#endif
-- 
1.6.3.msysgit.0.18.gef407

--

From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 6:30 am

From: Frank Li <lznuaa@gmail.com>

compat/msvc.h includes winsock2.h which conflicts with windows.h.
msvc.h also defines the oldest Windows API version required.

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/winansi.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/compat/winansi.c b/compat/winansi.c
index 9217c24..0d79845 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -2,7 +2,9 @@
  * Copyright 2008 Peter Harris <git@peter.is-a-geek.org>
  */
 
+#ifndef _MSC_VER
 #include <windows.h>
+#endif
 #include "../git-compat-util.h"
 
 /*
-- 
1.6.3.msysgit.0.18.gef407

--

From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 6:30 am

From: Frank Li <lznuaa@gmail.com>

Add a README file to tell users how to build git with MSVC.

Also add a gitignore file to make git ignore files generated
by a MSVC build.

Signed-off-by: Frank Li <lznuaa@gmail.com>
---
 compat/vcbuild/.gitignore |    3 +++
 compat/vcbuild/README     |   13 +++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)
 create mode 100644 compat/vcbuild/.gitignore
 create mode 100644 compat/vcbuild/README

diff --git a/compat/vcbuild/.gitignore b/compat/vcbuild/.gitignore
new file mode 100644
index 0000000..297ee5b
--- /dev/null
+++ b/compat/vcbuild/.gitignore
@@ -0,0 +1,3 @@
+Debug
+Release
+*.user
diff --git a/compat/vcbuild/README b/compat/vcbuild/README
new file mode 100644
index 0000000..3667ca3
--- /dev/null
+++ b/compat/vcbuild/README
@@ -0,0 +1,13 @@
+The Steps of Build Git with VS2008
+
+1. Create VC Build Environment.
+
+   git clone git://repo.or.cz/gitbuild.git
+
+   gitbuild include VS solution file and library such as zlib.
+
+2. Get Submodule
+
+   git submodule update --init
+
+3. Open gitbuild\gitbuild.sln with VS2008. Then press F7.
-- 
1.6.3.msysgit.0.18.gef407

--

From: Thiago Farina
Date: Sunday, August 23, 2009 - 9:26 am

Hi,

F7 does nothing in VS2008, to build the solution you have to press
Ctrl+Shift+B. To build and start debugging you have to press F5, and
for start without debbuging support is Ctrl+F5.

Regards
--

From: Reece Dunn
Date: Sunday, August 23, 2009 - 11:22 am

IIRC, Visual Studio can be configured to use different keyboard shortcuts.

However, saying "press F7" says nothing of the intent. It would
probably be better to have this say something like "Then build the
solution." or "Open gitbuild\gitbuild.sln with Visual Studio 2008,
then build it." But then you don't need to open Visual Studio 2008 to
build it (you can build it from command line).

So, how about:
   3. You can now build git with Visual Studio 2008 using the
gitbuild\gitbuild.sln file.

- Reece
--

From: Marius Storm-Olsen
Date: Sunday, August 23, 2009 - 11:59 am

Agreed.
Thanks guys.

--
.marius

--

From: Thiago Farina
Date: Sunday, August 23, 2009 - 12:29 pm

Marius, how common-cmds.h will be generated? In the header file says
that it's generated by generate-cmdlist.sh, so the VS user will need
to generate this file first (before compiling)?
When I tried to compile after pulling from the repository, I couldn't,
so I copied it from the the msysgit.
--

From: Marius Storm-Olsen
Date: Monday, August 24, 2009 - 12:03 am

The easiest is just do the following on the command line, provided 
that you have the msysgit environment available (so GNU Make etc):
     make common-cmds.h

That will ensure that the file is generated correctly. After that you 
can build with msvc, based on the patch series.

--
.marius
--

From: Frank Li
Date: Tuesday, August 25, 2009 - 7:32 am

I update http://repo.or.cz/w/gitbuild.git.
Add create_command.bat to create common-cmds.h.
--

From: Thiago Farina
Date: Tuesday, August 25, 2009 - 10:24 am

Hi,
This is great, thank you for adding this tool.

Today I ran 'git submodule update --init' and I recieved this error:
No submodule mapping found in .gitmodules for path 'ext/zlib'
The entry I have for zlib in .gitmodules is:

[submodule "ext\\zlib"]
       path = ext\\zlib
       url = git://repo.or.cz/zlib.git

Is this correct?  All the others entries are configured like this:
[submodule ext/git]
      path = ext/git
      url = git://repo.or.cz/tgit.git

Another question: Is not better to put the README inside gitbuild with
the other files instead of compat/vcbuild/?
--

From: Frank Li
Date: Thursday, August 27, 2009 - 6:16 am

I fixed this problem
It should be ext/zlib
--

From: Thiago Farina
Date: Thursday, August 27, 2009 - 7:26 am

Hi
Thanks!

Now when I run 'git submodule update' I recieve this error:
'fatal: Needed a single revision
Unable to find the current revision in submodule path 'ext/OpenSSL''

If the output of 'git submodule status' help, this is:
 fdd0f73b9a3e7c1fdf15c2e2a52582c637ec96f1 ext/OpenSSL
+3136d3b72e199ad1484629e8ff4563a918cad953 ext/git (remotes/origin/vcpatch)
-c891963b1c9d2ffbf194b2c2283639d784fa3690 ext/libcurl
-62cb93cb25e2fbdbc89f90249cd8a024afad8a94 ext/zlib
--

From: Erik Faye-Lund
Date: Monday, September 7, 2009 - 5:26 am

I just gave this script a try, but if I simply click the .bat-file, I
get the following crash in sh.exe: "Unhandled exception at 0x77ba8e7c
in sh.exe: 0xC0000005: Access violation writing location 0x00000014."

Here's the output I get on the console:

--->8---

C:\Users\Erik\src\git-msvc\gitbuild>setlocal

C:\Users\Erik\src\git-msvc\gitbuild>set tools=C:\Users\Erik\src\git-msvc\gitbuil
d\tools

C:\Users\Erik\src\git-msvc\gitbuild>echo C:\Users\Erik\src\git-msvc\gitbuild\too
ls
C:\Users\Erik\src\git-msvc\gitbuild\tools

C:\Users\Erik\src\git-msvc\gitbuild>set path=C:\Users\Erik\src\git-msvc\gitbuild
\tools

C:\Users\Erik\src\git-msvc\gitbuild>cd ext\git

C:\Users\Erik\src\git-msvc\gitbuild\ext\git>sh generate-cmdlist.sh  1>common-cmd
s.h

abnormal program termination

--->8---

Since the path is set to only point to the tools, my guess is that
other msys installations (I've got two) shouldn't affect this, no?

I'm running Vista 64bit.

-- 
Erik "kusma" Faye-Lund
kusmabite@gmail.com
(+47) 986 59 656
--

From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 6:30 am

MSVC lacks many of the header files included by git-compat-util.h,
so add blank header files for these instead of going ifdef crazy.

Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/vcbuild/include/arpa/inet.h   |    1 +
 compat/vcbuild/include/grp.h         |    1 +
 compat/vcbuild/include/inttypes.h    |    1 +
 compat/vcbuild/include/netdb.h       |    1 +
 compat/vcbuild/include/netinet/in.h  |    1 +
 compat/vcbuild/include/netinet/tcp.h |    1 +
 compat/vcbuild/include/pwd.h         |    1 +
 compat/vcbuild/include/sys/ioctl.h   |    1 +
 compat/vcbuild/include/sys/param.h   |    1 +
 compat/vcbuild/include/sys/poll.h    |    1 +
 compat/vcbuild/include/sys/select.h  |    1 +
 compat/vcbuild/include/sys/socket.h  |    1 +
 compat/vcbuild/include/sys/time.h    |    1 +
 compat/vcbuild/include/sys/wait.h    |    1 +
 14 files changed, 14 insertions(+), 0 deletions(-)
 create mode 100644 compat/vcbuild/include/arpa/inet.h
 create mode 100644 compat/vcbuild/include/grp.h
 create mode 100644 compat/vcbuild/include/inttypes.h
 create mode 100644 compat/vcbuild/include/netdb.h
 create mode 100644 compat/vcbuild/include/netinet/in.h
 create mode 100644 compat/vcbuild/include/netinet/tcp.h
 create mode 100644 compat/vcbuild/include/pwd.h
 create mode 100644 compat/vcbuild/include/sys/ioctl.h
 create mode 100644 compat/vcbuild/include/sys/param.h
 create mode 100644 compat/vcbuild/include/sys/poll.h
 create mode 100644 compat/vcbuild/include/sys/select.h
 create mode 100644 compat/vcbuild/include/sys/socket.h
 create mode 100644 compat/vcbuild/include/sys/time.h
 create mode 100644 compat/vcbuild/include/sys/wait.h

diff --git a/compat/vcbuild/include/arpa/inet.h b/compat/vcbuild/include/arpa/inet.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/arpa/inet.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/grp.h b/compat/vcbuild/include/grp.h
new ...
From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 6:30 am

From: Frank Li <lznuaa@gmail.com>

Add msvc.c and msvc.h to build git under MSVC

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/msvc.c     |   35 ++++++++++++++++++
 compat/msvc.h     |  102 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 git-compat-util.h |    3 ++
 3 files changed, 140 insertions(+), 0 deletions(-)
 create mode 100644 compat/msvc.c
 create mode 100644 compat/msvc.h

diff --git a/compat/msvc.c b/compat/msvc.c
new file mode 100644
index 0000000..ac04a4c
--- /dev/null
+++ b/compat/msvc.c
@@ -0,0 +1,35 @@
+#include "../git-compat-util.h"
+#include "win32.h"
+#include <conio.h>
+#include "../strbuf.h"
+
+DIR *opendir(const char *name)
+{
+	int len;
+	DIR *p;
+	p = (DIR*)malloc(sizeof(DIR));
+	memset(p, 0, sizeof(DIR));
+	strncpy(p->dd_name, name, PATH_MAX);
+	len = strlen(p->dd_name);
+	p->dd_name[len] = '/';
+	p->dd_name[len+1] = '*';
+
+	if (p == NULL)
+		return NULL;
+
+	p->dd_handle = _findfirst(p->dd_name, &p->dd_dta);
+
+	if (p->dd_handle == -1) {
+		free(p);
+		return NULL;
+	}
+	return p;
+}
+int closedir(DIR *dir)
+{
+	_findclose(dir->dd_handle);
+	free(dir);
+	return 0;
+}
+
+#include "mingw.c"
diff --git a/compat/msvc.h b/compat/msvc.h
new file mode 100644
index 0000000..3e22186
--- /dev/null
+++ b/compat/msvc.h
@@ -0,0 +1,102 @@
+#ifndef __MSVC__HEAD
+#define __MSVC__HEAD
+
+/* Define minimize windows version */
+#define WINVER 0x0500
+#define _WIN32_WINNT 0x0500
+#define _WIN32_WINDOWS 0x0410
+#define _WIN32_IE 0x0700
+#define NTDDI_VERSION NTDDI_WIN2KSP1
+#include <winsock2.h>
+#include <direct.h>
+#include <process.h>
+
+/* Configuration */
+#define NO_PREAD
+#define NO_OPENSSL
+#define NO_LIBGEN_H
+#define NO_SYMLINK_HEAD
+#define NO_IPV6
+#define NO_SETENV
+#define NO_UNSETENV
+#define NO_STRCASESTR
+#define NO_STRLCPY
+#define NO_MEMMEM
+#define NO_C99_FORMAT
+#define NO_STRTOUMAX
+#define NO_MKDTEMP
+#define ...
From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 6:30 am

From: Frank Li <lznuaa@gmail.com>

Add libgit.vcproj to build common library, and git.vcproj to
build git itself.

Signed-off-by: Frank Li <lznuaa@gmail.com>
---
 compat/vcbuild/git/git.vcproj       |  197 +++++
 compat/vcbuild/libgit/libgit.vcproj | 1359 +++++++++++++++++++++++++++++++++++
 2 files changed, 1556 insertions(+), 0 deletions(-)
 create mode 100644 compat/vcbuild/git/git.vcproj
 create mode 100644 compat/vcbuild/libgit/libgit.vcproj

diff --git a/compat/vcbuild/git/git.vcproj b/compat/vcbuild/git/git.vcproj
new file mode 100644
index 0000000..6f85de3
--- /dev/null
+++ b/compat/vcbuild/git/git.vcproj
@@ -0,0 +1,197 @@
+<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioProject
+	ProjectType="Visual ...
From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 6:30 am

From: Frank Li <lznuaa@gmail.com>

Added the header files dirent.h, unistd.h and utime.h

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/vcbuild/include/dirent.h    |  128 ++++++++++++++++++++++++++++++++++++
 compat/vcbuild/include/sys/utime.h |   34 ++++++++++
 compat/vcbuild/include/unistd.h    |   92 ++++++++++++++++++++++++++
 compat/vcbuild/include/utime.h     |    1 +
 4 files changed, 255 insertions(+), 0 deletions(-)
 create mode 100644 compat/vcbuild/include/dirent.h
 create mode 100644 compat/vcbuild/include/sys/utime.h
 create mode 100644 compat/vcbuild/include/unistd.h
 create mode 100644 compat/vcbuild/include/utime.h

diff --git a/compat/vcbuild/include/dirent.h b/compat/vcbuild/include/dirent.h
new file mode 100644
index 0000000..440618d
--- /dev/null
+++ b/compat/vcbuild/include/dirent.h
@@ -0,0 +1,128 @@
+/*
+ * DIRENT.H (formerly DIRLIB.H)
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is a part of the mingw-runtime package.
+ *
+ * The mingw-runtime package and its code is distributed in the hope that it
+ * will be useful but WITHOUT ANY WARRANTY.  ALL WARRANTIES, EXPRESSED OR
+ * IMPLIED ARE HEREBY DISCLAIMED.  This includes but is not limited to
+ * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You are free to use this package and its code without limitation.
+ */
+#ifndef _DIRENT_H_
+#define _DIRENT_H_
+#include <io.h>
+
+#define PATH_MAX 512
+
+#define __MINGW_NOTHROW
+
+#ifndef RC_INVOKED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct dirent
+{
+	long		d_ino;		/* Always zero. */
+	unsigned short	d_reclen;	/* Always zero. */
+	unsigned short	d_namlen;	/* Length of name in d_name. */
+	char		d_name[FILENAME_MAX]; /* File name. */
+};
+
+/*
+ * This is an internal data structure. Good programmers will not use it
+ * except as an argument to one of the functions below.
+ * dd_stat field is ...
From: Junio C Hamano
Date: Friday, August 21, 2009 - 2:02 pm

The first sentence sort-of makes sense; compat/msvc.h will be included by
git-compat-util.h and including <windows.h> here will bring conflicting
definitions, so we avoid doing so when on MSC.

The second sentence does not make any sense to me.  It may be correctly
stating a fact (i.e. "defines required WAPI version"), but it is unclear 
what relevance it has to this change to stop including <windows.h>.

Having said that, the first sentence hints me that perhaps you guys should
include (conditionally only on windows but not with MSC) <windows.h> not
--

From: Reece Dunn
Date: Friday, August 21, 2009 - 2:16 pm

The way things are configured, windows.h is pulling in winsock.h. In
git-compat-util.h, winsock2.h is included which has conflicting

It would make sense for windows.h to be included in git-compat-util.h.

According to http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/4a90b143-1fb8-43e9-a54...,
the following will work:

#define _WINSOCKAPI_    // stops windows.h including winsock.h
#include <winsock2.h>
#include <windows.h>

Also, if you define WIN32_LEAN_AND_MEAN, windows.h will pull in a
subset of the Windows header files (which also improves compilation
times). Adding this may prevent it from pulling in winsock.h. This
would be a better approach (and would make sense to go into
git-compat-util.h).

I don't have access to a Windows dev box at the moment, so can't
verify that this does indeed work.

- Reece
--

From: Marius Storm-Olsen
Date: Saturday, August 22, 2009 - 4:40 am

I'll check this on Monday, and send out a v3 of the series,
incorporating the pieces commented on, and clarifying some of the
still confusing commit msgs.

--
.marius
--

From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 6:30 am

From: Frank Li <lznuaa@gmail.com>

WINAPI is a macro which translates into the proper calling convention, so
replace __stdcall with that.

MSVC requires WINAPI to be between the functions return value and the
function name, and that the function pointer type is in the form of
    return_type (WINAPI *function_name)(arguments...)

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/mingw.c |    4 ++--
 run-command.c  |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index 836426c..9716528 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1017,7 +1017,7 @@ static sig_handler_t timer_fn = SIG_DFL;
  * length to call the signal handler.
  */
 
-static __stdcall unsigned ticktack(void *dummy)
+static unsigned WINAPI ticktack(void *dummy)
 {
 	while (WaitForSingleObject(timer_event, timer_interval) == WAIT_TIMEOUT) {
 		if (timer_fn == SIG_DFL)
@@ -1144,7 +1144,7 @@ void mingw_open_html(const char *unixpath)
 
 int link(const char *oldpath, const char *newpath)
 {
-	typedef BOOL WINAPI (*T)(const char*, const char*, LPSECURITY_ATTRIBUTES);
+	typedef BOOL (WINAPI *T)(const char*, const char*, LPSECURITY_ATTRIBUTES);
 	static T create_hard_link = NULL;
 	if (!create_hard_link) {
 		create_hard_link = (T) GetProcAddress(
diff --git a/run-command.c b/run-command.c
index efac7ad..98232e9 100644
--- a/run-command.c
+++ b/run-command.c
@@ -319,7 +319,7 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
 }
 
 #ifdef __MINGW32__
-static __stdcall unsigned run_thread(void *data)
+static unsigned WINAPI run_thread(void *data)
 {
 	struct async *async = data;
 	return async->proc(async->fd_for_proc, async->data);
-- 
1.6.3.msysgit.0.18.gef407

--

From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 6:30 am

From: Frank Li <lznuaa@gmail.com>

The code which is conditional on MinGW32 is actually conditional on Windows.
Use the WIN32 symbol, which is defined by the MINGW32 and MSVC environments,
but not by Cygwin.

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 help.c        |    2 +-
 pager.c       |    4 ++--
 run-command.c |    8 ++++----
 run-command.h |    2 +-
 setup.c       |    2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/help.c b/help.c
index fd51b8e..e8db31f 100644
--- a/help.c
+++ b/help.c
@@ -126,7 +126,7 @@ static int is_executable(const char *name)
 	    !S_ISREG(st.st_mode))
 		return 0;
 
-#ifdef __MINGW32__
+#ifdef WIN32
 {	/* cannot trust the executable bit, peek into the file instead */
 	char buf[3] = { 0 };
 	int n;
diff --git a/pager.c b/pager.c
index 4921843..37d1948 100644
--- a/pager.c
+++ b/pager.c
@@ -9,7 +9,7 @@
 
 static int spawned_pager;
 
-#ifndef __MINGW32__
+#ifndef WIN32
 static void pager_preexec(void)
 {
 	/*
@@ -70,7 +70,7 @@ void setup_pager(void)
 	pager_argv[2] = pager;
 	pager_process.argv = pager_argv;
 	pager_process.in = -1;
-#ifndef __MINGW32__
+#ifndef WIN32
 	pager_process.preexec_cb = pager_preexec;
 #endif
 	if (start_command(&pager_process))
diff --git a/run-command.c b/run-command.c
index 98232e9..2c6da42 100644
--- a/run-command.c
+++ b/run-command.c
@@ -75,7 +75,7 @@ fail_pipe:
 
 	trace_argv_printf(cmd->argv, "trace: run_command:");
 
-#ifndef __MINGW32__
+#ifndef WIN32
 	fflush(NULL);
 	cmd->pid = fork();
 	if (!cmd->pid) {
@@ -318,7 +318,7 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
 	return run_command(&cmd);
 }
 
-#ifdef __MINGW32__
+#ifdef WIN32
 static unsigned WINAPI run_thread(void *data)
 {
 	struct async *async = data;
@@ -334,7 +334,7 @@ int start_async(struct async *async)
 		return error("cannot create pipe: %s", strerror(errno));
 	async->out = ...
From: Paolo Bonzini
Date: Friday, August 28, 2009 - 1:15 am

Since you are doing this, you may as well change patch 3 from

+#if (defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 4) || 
defined(_MSC_VER)

to this:

#if defined WIN32 && (!defined (__GNUC__) || __GNUC__ < 4))

Paolo
--

From: Johannes Sixt
Date: Friday, August 21, 2009 - 10:37 am

These two are not nice. As I said in an earlier mail: The documentation says 
that the thread function pointer that is passed to _beginthreadex must have 
__stdcall calling convention. Therefore, you should not change these to 
WINAPI.

-- Hannes
--

From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 12:42 pm

WINAPI is just a define for __stdcall (since _MSC_VER >= 800 anyways; VC 
6.0 being _MSC_VER == 1200), and won't change.

So, IMO the change is not bad, and makes things less convoluted by using 
the same convention all over.

(And _beginthreadex actually accepts both __stdcall and __clrcall 
calling conventions.)

--
.marius
--

From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 6:30 am

From: Frank Li <lznuaa@gmail.com>

On Windows, binary files must be opened using the O_BINARY flag for
untranslated mode. MinGW does this for us automatically, but Microsoft
Visual C++ does not.

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/mingw.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index e4e0e60..836426c 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -132,7 +132,7 @@ int mingw_open (const char *filename, int oflags, ...)
 	if (!strcmp(filename, "/dev/null"))
 		filename = "nul";
 
-	fd = open(filename, oflags, mode);
+	fd = open(filename, oflags | O_BINARY, mode);
 
 	if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) {
 		DWORD attrs = GetFileAttributes(filename);
@@ -278,7 +278,7 @@ int mkstemp(char *template)
 	char *filename = mktemp(template);
 	if (filename == NULL)
 		return -1;
-	return open(filename, O_RDWR | O_CREAT, 0600);
+	return open(filename, O_RDWR | O_CREAT | O_BINARY, 0600);
 }
 
 int gettimeofday(struct timeval *tv, void *tz)
-- 
1.6.3.msysgit.0.18.gef407

--

From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 6:30 am

From: Frank Li <lznuaa@gmail.com>

The MSVC compiler doesn't like K&R style.

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/regex/regex.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/compat/regex/regex.c b/compat/regex/regex.c
index 5ea0075..67d5c37 100644
--- a/compat/regex/regex.c
+++ b/compat/regex/regex.c
@@ -4852,11 +4852,8 @@ regexec (preg, string, nmatch, pmatch, eflags)
    from either regcomp or regexec.   We don't use PREG here.  */
 
 size_t
-regerror (errcode, preg, errbuf, errbuf_size)
-    int errcode;
-    const regex_t *preg;
-    char *errbuf;
-    size_t errbuf_size;
+regerror(int errcode, const regex_t *preg,
+	 char *errbuf, size_t errbuf_size)
 {
   const char *msg;
   size_t msg_size;
-- 
1.6.3.msysgit.0.18.gef407

--

From: Frank Li
Date: Friday, August 21, 2009 - 7:37 am

The true reason is MSVC type define errcode as int.
Frank Li
--

From: Marius Storm-Olsen
Date: Friday, August 21, 2009 - 1:10 pm

From: Frank Li <lznuaa@gmail.com>

The MSVC headers typedef errcode as int, and thus confused the
compiler in the K&R style definition. ANSI style deconfuses it.

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 Frank, like this one better?

 compat/regex/regex.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/compat/regex/regex.c b/compat/regex/regex.c
index 5ea0075..67d5c37 100644
--- a/compat/regex/regex.c
+++ b/compat/regex/regex.c
@@ -4852,11 +4852,8 @@ regexec (preg, string, nmatch, pmatch, eflags)
    from either regcomp or regexec.   We don't use PREG here.  */
 
 size_t
-regerror (errcode, preg, errbuf, errbuf_size)
-    int errcode;
-    const regex_t *preg;
-    char *errbuf;
-    size_t errbuf_size;
+regerror(int errcode, const regex_t *preg,
+	 char *errbuf, size_t errbuf_size)
 {
   const char *msg;
   size_t msg_size;
-- 
1.6.3.msysgit.0.18.gef407

--

From: Frank Li
Date: Friday, August 21, 2009 - 5:15 pm

It is better
best regards
Frank Li
--

From: Erik Faye-Lund
Date: Monday, August 24, 2009 - 2:42 am

Since the real reason isn't the K&R style defintion, but that
"errcode" has been typedef'ed, perhaps it's better to either do
something like this:

#ifdef _MSC_VER
#define errcode dummy_def
#include <crtdefs.h>
#undef errcode
#endif

...before the first crt-inclusion, or simply to rename "errcode" to
something like "error"? The latter can be done with the preprocessor
after the first crt-inclusion.

-- 
Erik "kusma" Faye-Lund
kusmabite@gmail.com
(+47) 986 59 656
--

Previous thread: Display bug in gitk -S by Martin Stjernholm on Friday, August 21, 2009 - 4:46 am. (1 message)

Next thread: [PATCH 01/14] Fix non-constant array creation by Marius Storm-Olsen on Friday, August 21, 2009 - 6:30 am. (16 messages)