Commit 7a6cf815 by Ramsay Jones Committed by Shawn O. Pearce

win32: Open or create files in binary mode

On windows, unless we use the O_BINARY flag in the open()
call, the file I/O routines will perform line ending
conversion (\r\n => \n on input, \n => \r\n on output).
In addition to the performance penalty, most files in the
object database are binary and will, therefore, become
corrupted by this conversion.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
parent 0f39781c
......@@ -3,13 +3,13 @@
int gitfo_open(const char *path, int flags)
{
int fd = open(path, flags);
int fd = open(path, flags | O_BINARY);
return fd >= 0 ? fd : git_os_error();
}
int gitfo_creat(const char *path, int mode)
{
int fd = creat(path, mode);
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
return fd >= 0 ? fd : git_os_error();
}
......
......@@ -15,6 +15,10 @@
#include <time.h>
#include <dirent.h>
#if !defined(O_BINARY)
#define O_BINARY 0
#endif
#define GITFO_BUF_INIT {NULL, 0}
typedef int git_file;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment