@@ -126,35 +126,34 @@ abspath(a::AbstractString, b::AbstractString...) = abspath(joinpath(a,b...))
126
126
127
127
@windows_only realpath (path:: AbstractString ) = realpath (utf16 (path))
128
128
@windows_only function realpath (path:: UTF16String )
129
- p = UInt32 (( sizeof (path)>> 2 ) + 1 )
129
+ p:: UInt32 = sizeof (path)>> 1
130
130
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,
134
133
UInt32, (Cwstring, UInt32, Ptr{UInt16}, Ptr{Void}),
135
- path, buflength , buf, C_NULL )
134
+ path, length (buf) , buf, C_NULL )
136
135
systemerror (:realpath , p == 0 )
137
- if (p < buflength )
138
- resize! (buf, p+ 1 )
136
+ if (p < length (buf) )
137
+ resize! (buf, p + 1 )
139
138
return utf8 (UTF16String (buf))
140
139
end
141
140
end
142
141
end
143
142
144
143
@windows_only longpath (path:: AbstractString ) = longpath (utf16 (path))
145
144
@windows_only function longpath (path:: UTF16String )
146
- buf = Array (UInt16, length ( path. data))
145
+ p :: UInt32 = sizeof ( path) >> 1
147
146
while true
148
- p = ccall ((:GetLongPathNameW , " Kernel32" ), stdcall, UInt32,
147
+ buf = zeros (UInt16, p + 1 )
148
+ p = ccall ((:GetLongPathNameW , " kernel32" ), stdcall, UInt32,
149
149
(Cwstring, Ptr{UInt16}, UInt32),
150
150
path, buf, length (buf))
151
151
systemerror (:longpath , p == 0 )
152
152
# 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))
156
156
end
157
- return utf8 (UTF16String (buf))
158
157
end
159
158
end
160
159
0 commit comments