Skip to content

Commit

Permalink
Rewrite homedir based on uv_os_homedir
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Dec 17, 2016
1 parent ded2259 commit 5b04cb0
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions base/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ if is_unix()
const path_ext_splitter = r"^((?:.*/)?(?:\.|[^/\.])[^/]*?)(\.[^/\.]*|)$"

splitdrive(path::String) = ("",path)
homedir() = ENV["HOME"]
elseif is_windows()
const path_separator = "\\"
const path_separator_re = r"[/\\]+"
Expand All @@ -38,7 +37,6 @@ elseif is_windows()
m = match(r"^(\w+:|\\\\\w+\\\w+|\\\\\?\\UNC\\\w+\\\w+|\\\\\?\\\w+:|)(.*)$", path)
String(m.captures[1]), String(m.captures[2])
end
homedir() = get(ENV,"HOME",string(ENV["HOMEDRIVE"],ENV["HOMEPATH"]))
else
error("path primitives for this OS need to be defined")
end
Expand All @@ -57,7 +55,22 @@ splitdrive(path::AbstractString)
Return the current user's home directory.
"""
homedir()
function homedir()
path_max = 1024
buf = Vector{UInt8}(path_max)
sz = Ref{Csize_t}(path_max + 1)
while true
rc = ccall(:uv_os_homedir, Cint, (Ptr{UInt8}, Ptr{Csize_t}), buf, sz)
if rc == 0
resize!(buf, sz[])
return String(buf)
elseif rc == UV_ENOBUFS
resize!(buf, sz[] - 1)
else
error("unable to retrieve home directory")
end
end
end


"""
Expand Down

0 comments on commit 5b04cb0

Please sign in to comment.