Skip to content

Commit

Permalink
win32: fix several errors in longpath and realpath implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Nov 10, 2015
1 parent 2721da8 commit 9dae3ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ elseif OS_NAME == :Windows
# GetLongPathName Win32 function returns the case-preserved filename on NTFS.
function isfile_casesensitive(path)
isfile(path) || return false # Fail fast
longpath(path) == path
Filesystem.longpath(path) == path
end
elseif OS_NAME == :Darwin
# HFS+ filesystem is case-preserving. The getattrlist API returns
Expand Down
25 changes: 12 additions & 13 deletions base/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,35 +126,34 @@ 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)
p::UInt32 = sizeof(path)>>1
while true
buflength = p
buf = zeros(UInt16,buflength)
p = ccall((:GetFullPathNameW, "Kernel32"), stdcall,
buf = zeros(UInt16, p + 1)
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)
if (p < length(buf))
resize!(buf, p + 1)
return utf8(UTF16String(buf))
end
end
end

@windows_only longpath(path::AbstractString) = longpath(utf16(path))
@windows_only function longpath(path::UTF16String)
buf = Array(UInt16, length(path.data))
p::UInt32 = sizeof(path)>>1
while true
p = ccall((:GetLongPathNameW, "Kernel32"), stdcall, UInt32,
buf = zeros(UInt16, p + 1)
p = ccall((:GetLongPathNameW, "kernel32"), stdcall, UInt32,
(Cwstring, Ptr{UInt16}, UInt32),
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))
resize!(buf, p)
continue
if (p < length(buf))
resize!(buf, p + 1)
return utf8(UTF16String(buf))
end
return utf8(UTF16String(buf))
end
end

Expand Down

0 comments on commit 9dae3ec

Please sign in to comment.