summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamsay Jones <ramsay@ramsay1.demon.co.uk>2009-03-16 17:08:45 +0000
committerShawn O. Pearce <spearce@spearce.org>2009-03-17 19:10:51 -0700
commit7a6cf8153799563464d6f1761e55352c327b4122 (patch)
treed0f0c327029d770d1b10efc7a6c93080ed7d6844
parent0f39781c25a06c1d38877adef4ff5a6a5f67f1ca (diff)
downloadlibgit2-7a6cf8153799563464d6f1761e55352c327b4122.tar.gz
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>
-rw-r--r--src/fileops.c4
-rw-r--r--src/fileops.h4
2 files changed, 6 insertions, 2 deletions
diff --git a/src/fileops.c b/src/fileops.c
index c7f0591ff..e2ec61507 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -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();
}
diff --git a/src/fileops.h b/src/fileops.h
index 963dd0fe0..3cc1e1683 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -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;