@matheusbsbs / matheus-bagliano / commits / 7be401e069
Fork 0

MinGW: a hardlink implementation

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Petr Kodl committed Jan 24, 2009 at 15:04 UTC 7be401e069758cc36d335241d9b80f9aeebf58c7
2 files changed +22 -2
compat/mingw.c
+21
@@ -1118,3 +1118,24 @@ void mingw_open_html(const char *unixpath)
1118 printf("Launching default browser to display HTML ...\n");
1119 ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0);
1120 }
1121 +
1122 +int link(const char *oldpath, const char *newpath)
1123 +{
1124 + typedef BOOL WINAPI (*T)(const char*, const char*, LPSECURITY_ATTRIBUTES);
1125 + static T create_hard_link = NULL;
1126 + if (!create_hard_link) {
1127 + create_hard_link = (T) GetProcAddress(
1128 + GetModuleHandle("kernel32.dll"), "CreateHardLinkA");
1129 + if (!create_hard_link)
1130 + create_hard_link = (T)-1;
1131 + }
1132 + if (create_hard_link == (T)-1) {
1133 + errno = ENOSYS;
1134 + return -1;
1135 + }
1136 + if (!create_hard_link(newpath, oldpath, NULL)) {
1137 + errno = err_win_to_posix(GetLastError());
1138 + return -1;
1139 + }
1140 + return 0;
1141 +}
compat/mingw.h
+1 -2
@@ -67,8 +67,6 @@ static inline int readlink(const char *path, char *buf, size_t bufsiz)
67 { errno = ENOSYS; return -1; }
68 static inline int symlink(const char *oldpath, const char *newpath)
69 { errno = ENOSYS; return -1; }
70 -static inline int link(const char *oldpath, const char *newpath)
71 -{ errno = ENOSYS; return -1; }
70 static inline int fchmod(int fildes, mode_t mode)
71 { errno = ENOSYS; return -1; }
72 static inline int fork(void)
@@ -134,6 +132,7 @@ int getpagesize(void); /* defined in MinGW's libgcc.a */
132 struct passwd *getpwuid(int uid);
133 int setitimer(int type, struct itimerval *in, struct itimerval *out);
134 int sigaction(int sig, struct sigaction *in, struct sigaction *out);
135 +int link(const char *oldpath, const char *newpath);
136
137 /*
138 * replacements of existing functions