Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions base/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,17 @@ abspath(a::AbstractString, b::AbstractString...) = abspath(joinpath(a,b...))

@windows_only realpath(path::AbstractString) = realpath(utf16(path))
@windows_only function realpath(path::UTF16String)
p = UInt32((sizeof(path)>>2) + 1)
buf = Array(UInt16, length(path.data))
while true
buflength = p
buf = zeros(UInt16,buflength)
p = ccall((:GetFullPathNameW, "Kernel32"), stdcall,
UInt32, (Cwstring, UInt32, Ptr{UInt16}, Ptr{Void}),
path, buflength, buf, C_NULL)
path, length(buf), buf, C_NULL)
systemerror(:realpath, p == 0)
if (p < buflength)
resize!(buf, p+1)
return utf8(UTF16String(buf))
if p > length(buf)
resize!(buf, p)
continue
end
return encode_to_utf8(UInt16, buf, p)
end
end

Expand All @@ -134,11 +133,11 @@ end
path, buf, length(buf))
systemerror(:longpath, p == 0)
# Buffer wasn't big enough, in which case `p` is the necessary buffer size
if (p > length(buf))
if p > length(buf)
resize!(buf, p)
continue
end
return utf8(UTF16String(buf))
return encode_to_utf8(UInt16, buf, p)
end
end

Expand Down