From 62d2d6829cc7adab30cb2b52bc90a0d70f6952c1 Mon Sep 17 00:00:00 2001 From: Frank Li Date: Mon, 17 Aug 2009 14:52:01 +0800 Subject: [PATCH] mingw.c: Use the O_BINARY flag to open files On Windows, non-text files must be opened using the O_BINARY flag. MinGW does this for us automatically, but Microsoft Visual C++ does not. So let's be explicit. Signed-off-by: Frank Li Signed-off-by: Johannes Schindelin --- compat/mingw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 9e0f5e0ffb..10d67964ed 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -161,7 +161,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); @@ -354,7 +354,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)