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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
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);
+}
+