diff options
author | Tony Cook <tony@develop-help.com> | 2020-11-09 13:52:09 +1100 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2020-12-01 15:29:33 +1100 |
commit | 7c04651411221e54ce561cd41ae8fa76347bbd5a (patch) | |
tree | 8a537e494821aff242065a43d4488022e18b20a6 /win32 | |
parent | d9f9953f74a41a404d61c6ddef3ed682eec1aa1c (diff) | |
download | perl-7c04651411221e54ce561cd41ae8fa76347bbd5a.tar.gz |
pre-vista support for win32_symlink
Diffstat (limited to 'win32')
-rw-r--r-- | win32/win32.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/win32/win32.c b/win32/win32.c index 65d154d75a..f18223d2ad 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -3448,6 +3448,12 @@ win32_link(const char *oldname, const char *newname) return -1; } +typedef BOOLEAN (__stdcall *pCreateSymbolicLinkA_t)(LPCSTR, LPCSTR, DWORD); + +#ifndef SYMBOLIC_LINK_FLAG_DIRECTORY +# define SYMBOLIC_LINK_FLAG_DIRECTORY 0x1 +#endif + #ifndef SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE # define SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE 0x2 #endif @@ -3459,6 +3465,8 @@ win32_symlink(const char *oldfile, const char *newfile) const char *dest_path = oldfile; char szTargetName[MAX_PATH+1]; size_t oldfile_len = strlen(oldfile); + pCreateSymbolicLinkA_t pCreateSymbolicLinkA = + (pCreateSymbolicLinkA_t)GetProcAddress(GetModuleHandle("kernel32.dll"), "CreateSymbolicLinkA"); DWORD dest_attr; DWORD create_flags = 0; @@ -3470,6 +3478,11 @@ win32_symlink(const char *oldfile, const char *newfile) create_flags |= SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE; } + if (!pCreateSymbolicLinkA) { + errno = ENOSYS; + return -1; + } + /* oldfile might be relative and we don't want to change that, so don't map that. */ @@ -3514,7 +3527,7 @@ win32_symlink(const char *oldfile, const char *newfile) create_flags |= SYMBOLIC_LINK_FLAG_DIRECTORY; } - if (!CreateSymbolicLinkA(newfile, oldfile, create_flags)) { + if (!pCreateSymbolicLinkA(newfile, oldfile, create_flags)) { translate_to_errno(); return -1; } |