From b8ba0563f25d5ac40d80718d5d05503c27806765 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Wed, 14 Apr 2010 06:59:24 +0200 Subject: win32: add link() --- include/mingw.h | 2 +- win32/mingw.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/mingw.h b/include/mingw.h index 0ff7f5442..40c11aabf 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -256,7 +256,7 @@ NOIMPL(fcntl,int fd UNUSED_PARAM, int cmd UNUSED_PARAM, ...); #define fork() -1 IMPL(fsync,int,0,int fd UNUSED_PARAM); NOIMPL(kill,pid_t pid UNUSED_PARAM, int sig UNUSED_PARAM); -NOIMPL(link,const char *oldpath UNUSED_PARAM, const char *newpath UNUSED_PARAM); +int link(const char *oldpath, const char *newpath); NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM); int pipe(int filedes[2]); NOIMPL(readlink,const char *path UNUSED_PARAM, char *buf UNUSED_PARAM, size_t bufsiz UNUSED_PARAM); diff --git a/win32/mingw.c b/win32/mingw.c index afd017e87..eccd37cc3 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -327,3 +327,24 @@ sighandler_t mingw_signal(int sig, sighandler_t handler) timer_fn = handler; return old; } + +int link(const char *oldpath, const char *newpath) +{ + typedef BOOL WINAPI (*T)(const char*, const char*, LPSECURITY_ATTRIBUTES); + static T create_hard_link = NULL; + if (!create_hard_link) { + create_hard_link = (T) GetProcAddress( + GetModuleHandle("kernel32.dll"), "CreateHardLinkA"); + if (!create_hard_link) + create_hard_link = (T)-1; + } + if (create_hard_link == (T)-1) { + errno = ENOSYS; + return -1; + } + if (!create_hard_link(newpath, oldpath, NULL)) { + errno = err_win_to_posix(GetLastError()); + return -1; + } + return 0; +} -- cgit v1.2.3-55-g6feb