@@ -126,35 +126,34 @@ abspath(a::AbstractString, b::AbstractString...) = abspath(joinpath(a,b...))
126126
127127@windows_only realpath (path:: AbstractString ) = realpath (utf16 (path))
128128@windows_only function realpath (path:: UTF16String )
129- p = UInt32 (( sizeof (path)>> 2 ) + 1 )
129+ p:: UInt32 = sizeof (path)>> 1
130130 while true
131- buflength = p
132- buf = zeros (UInt16,buflength)
133- p = ccall ((:GetFullPathNameW , " Kernel32" ), stdcall,
131+ buf = zeros (UInt16, p + 1 )
132+ p = ccall ((:GetFullPathNameW , " kernel32" ), stdcall,
134133 UInt32, (Cwstring, UInt32, Ptr{UInt16}, Ptr{Void}),
135- path, buflength , buf, C_NULL )
134+ path, length (buf) , buf, C_NULL )
136135 systemerror (:realpath , p == 0 )
137- if (p < buflength )
138- resize! (buf, p+ 1 )
136+ if (p < length (buf) )
137+ resize! (buf, p + 1 )
139138 return utf8 (UTF16String (buf))
140139 end
141140 end
142141end
143142
144143@windows_only longpath (path:: AbstractString ) = longpath (utf16 (path))
145144@windows_only function longpath (path:: UTF16String )
146- buf = Array (UInt16, length ( path. data))
145+ p :: UInt32 = sizeof ( path) >> 1
147146 while true
148- p = ccall ((:GetLongPathNameW , " Kernel32" ), stdcall, UInt32,
147+ buf = zeros (UInt16, p + 1 )
148+ p = ccall ((:GetLongPathNameW , " kernel32" ), stdcall, UInt32,
149149 (Cwstring, Ptr{UInt16}, UInt32),
150150 path, buf, length (buf))
151151 systemerror (:longpath , p == 0 )
152152 # Buffer wasn't big enough, in which case `p` is the necessary buffer size
153- if (p > length (buf))
154- resize! (buf, p)
155- continue
153+ if (p < length (buf))
154+ resize! (buf, p + 1 )
155+ return utf8 ( UTF16String (buf))
156156 end
157- return utf8 (UTF16String (buf))
158157 end
159158end
160159
0 commit comments