[PATCH 06/17] mingw.c: Use the O_BINARY flag to open files
- From
Marius Storm-Olsen <mstormo@gmail.com>
- Date
- Sep 14, 2009, 13:11 UTC
- Message-ID
- <160ceafba5f58cfcadb13380e3d8ef724009b700.1252925290.git.mstormo@gmail.com>
- In-Reply-To
- <54b586ed58d1e9b4204658871f6f34453b48758b.1252925290.git.mstormo@gmail.com>
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 5478b74..12db9a6 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.2.1.418.g33d56.dirty