diff --git a/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs b/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs index 82f154364..4db589fed 100644 --- a/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs +++ b/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs @@ -286,9 +286,7 @@ namespace ICSharpCode.Decompiler.Metadata { if ((new FileInfo(fileName).Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint) { - var sb = new StringBuilder(); - realpath(fileName, sb); - fileName = sb.ToString(); + fileName = GetRealPath(fileName, Encoding.Default); if (!File.Exists(fileName)) continue; } @@ -300,7 +298,33 @@ namespace ICSharpCode.Decompiler.Metadata return null; } - [DllImport("libc")] - static extern void realpath(string path, StringBuilder resolvedPath); + static unsafe string GetRealPath(string path, Encoding encoding) + { + var bytes = encoding.GetBytes(path); + fixed (byte* input = bytes) + { + + byte* output = GetRealPath(input, null); + if (output == null) + { + return null; + } + int len = 0; + for (byte* c = output; *c != 0; c++) + { + len++; + } + byte[] result = new byte[len]; + Marshal.Copy((IntPtr)output, result, 0, result.Length); + Free(output); + return encoding.GetString(result); + } + } + + [DllImport("libc", EntryPoint = "realpath")] + static extern unsafe byte* GetRealPath(byte* path, byte* resolvedPath); + + [DllImport("libc", EntryPoint = "free")] + static extern unsafe void Free(void* ptr); } }