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

[PATCH 04/12] mingw.c: Use the O_BINARY flag to open files

From
Frank Li <lznuaa@gmail.com>
Date
Aug 19, 2009, 15:52 UTC
Message-ID
<1250697167-5536-4-git-send-email-lznuaa@gmail.com>
In-Reply-To
<1250697167-5536-3-git-send-email-lznuaa@gmail.com>

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.

Signed-off-by: Frank Li <lznuaa@gmail.com>
---
 compat/mingw.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index 75c74b1..d5fa0ed 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.4.msysgit.0
Previous: Frank LiNext: Frank Li
Message 4 of 12 in “Avoid declaration after instruction”
  1. 01/12 Avoid declaration after instructionFrank Li, Aug 19, 2009
  2. 02/12 Define SNPRINTF_SIZE_CORR=1 for Microsoft Visual C++Frank Li, Aug 19, 2009
  3. 03/12 Using macro WIN32 replace __MINGW32_ at Windows special handler The code which is conditional on MinGW32 is actually conditional on Windows. Use WIN32 macro will share both MINGW32 and MSVC environment.Frank Li, Aug 19, 2009
  4. 04/12 mingw.c: Use the O_BINARY flag to open filesFrank Li, Aug 19, 2009
  5. 05/12 Place __stdcall between return value and function nameFrank Li, Aug 19, 2009
  6. 06/12 Add _MSC_VER in porting head file git-compat-util.hFrank Li, Aug 19, 2009
  7. 07/12 Add Unix header files to build git at MSVC.Frank Li, Aug 19, 2009
  8. 08/12 Add MSVC porting files.Frank Li, Aug 19, 2009
  9. 09/12 Don't include windows.h at winansi.c at MSVC buildFrank Li, Aug 19, 2009
  10. 10/12 Fix errcode have defined as int at MSVCFrank Li, Aug 19, 2009
  11. 11/12 Add MSVC Project fileFrank Li, Aug 19, 2009
  12. Erik Faye-LundAug 19, 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.