Commit 4319860c60d84ec2513be34ee1a65dec5eceb6c4

Ramsay Jones 2009-06-04T16:45:59

win32: Add some file operation stubs and wrapper functions Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Andreas Ericsson <ae@op5.se>

diff --git a/src/fileops.h b/src/fileops.h
index dca7499..5684642 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -16,6 +16,34 @@
 #include <fcntl.h>
 #include <time.h>
 
+#ifdef GIT_WIN32
+static inline int link(const char *old, const char *new)
+{
+	errno = ENOSYS;
+	return -1;
+}
+
+static inline int fsync(int fd)
+{
+	return 0;
+}
+
+static inline int git__mkdir(const char *path, int mode)
+{
+	return mkdir(path);
+}
+
+extern int git__unlink(const char *path);
+extern int git__mkstemp(char *template);
+
+# ifndef GIT__WIN32_NO_HIDE_FILEOPS
+#  define unlink(p) git__unlink(p)
+#  define mkstemp(t) git__mkstemp(t)
+#  define mkdir(p,m) git__mkdir(p,m)
+# endif
+#endif  /* GIT_WIN32 */
+
+
 #if !defined(O_BINARY)
 #define O_BINARY 0
 #endif
@@ -45,12 +73,11 @@ extern void gitfo_free_buf(gitfo_buf *obj);
 #define gitfo_unlink(p) unlink(p)
 #define gitfo_rmdir(p) rmdir(p)
 #define gitfo_chdir(p) chdir(p)
-
-#ifdef GIT_WIN32
-#define gitfo_mkdir(p,m) mkdir(p)
-#else
 #define gitfo_mkdir(p,m) mkdir(p, m)
-#endif
+
+#define gitfo_mkstemp(t) mkstemp(t)
+#define gitfo_fsync(fd) fsync(fd)
+#define gitfo_chmod(p,m) chmod(p, m)
 
 /**
  * Read-only map all or part of a file into memory.
diff --git a/src/win32/fileops.c b/src/win32/fileops.c
new file mode 100644
index 0000000..c6039d8
--- /dev/null
+++ b/src/win32/fileops.c
@@ -0,0 +1,17 @@
+#define GIT__WIN32_NO_HIDE_FILEOPS
+#include "fileops.h"
+
+int git__unlink(const char *path)
+{
+	chmod(path, 0666);
+	return unlink(path);
+}
+
+int git__mkstemp(char *template)
+{
+	char *file = mktemp(template);
+	if (file == NULL)
+		return -1;
+	return open(file, O_RDWR | O_CREAT | O_BINARY, 0600);
+}
+