aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--win32/mingw.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index c9b72ae98..2e9a53393 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1076,13 +1076,22 @@ int symlink(const char *target, const char *linkpath)
1076 DWORD flag = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE; 1076 DWORD flag = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
1077 struct stat st; 1077 struct stat st;
1078 DECLARE_PROC_ADDR(BOOL, CreateSymbolicLinkA, LPCSTR, LPCSTR, DWORD); 1078 DECLARE_PROC_ADDR(BOOL, CreateSymbolicLinkA, LPCSTR, LPCSTR, DWORD);
1079 char *relative = NULL;
1079 1080
1080 if (!INIT_PROC_ADDR(kernel32.dll, CreateSymbolicLinkA)) { 1081 if (!INIT_PROC_ADDR(kernel32.dll, CreateSymbolicLinkA)) {
1081 return -1; 1082 return -1;
1082 } 1083 }
1083 1084
1084 if (stat(target, &st) != -1 && S_ISDIR(st.st_mode)) 1085 if (!is_absolute_path(target) && has_path(linkpath)) {
1086 /* make target's path relative to current directory */
1087 const char *name = bb_get_last_path_component_nostrip(linkpath);
1088 relative = xasprintf("%.*s%s",
1089 (int)(name - linkpath), linkpath, target);
1090 }
1091
1092 if (stat(relative ?: target, &st) != -1 && S_ISDIR(st.st_mode))
1085 flag |= SYMBOLIC_LINK_FLAG_DIRECTORY; 1093 flag |= SYMBOLIC_LINK_FLAG_DIRECTORY;
1094 free(relative);
1086 1095
1087 retry: 1096 retry:
1088 if (!CreateSymbolicLinkA(linkpath, target, flag)) { 1097 if (!CreateSymbolicLinkA(linkpath, target, flag)) {