Merge pull request #184 from hughbe/symlink-fix
Fix Windows implementation of symlink
diff --git a/lib/Basic/PlatformUtility.cpp b/lib/Basic/PlatformUtility.cpp
index fba346f..2498e96 100644
--- a/lib/Basic/PlatformUtility.cpp
+++ b/lib/Basic/PlatformUtility.cpp
@@ -106,7 +106,13 @@
int sys::symlink(const char *source, const char *target) {
#if defined(_WIN32)
- return ::_symlink(source, target);
+ DWORD attributes = GetFileAttributesA(source);
+ if (attributes != INVALID_FILE_ATTRIBUTES &&
+ (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
+ return ::CreateSymbolicLinkA(source, target, SYMBOLIC_LINK_FLAG_DIRECTORY);
+ }
+
+ return ::CreateSymbolicLinkA(source, target, 0);
#else
return ::symlink(source, target);
#endif