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 5c2ca4b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 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,14 @@ splitdrive(path::AbstractString)
Return the current user's home directory.
"""
homedir()
function homedir()
buf = Vector{Cchar}(1024)
sz = Ref{Csize_t}(sizeof(buf))
rc = ccall(:uv_os_homedir, Cint, (Ptr{Cchar}, Ptr{Csize_t}), buf, sz)
rc == 0 || error("unable to retrieve home directory")
nbytes = Int(sz[])
return unsafe_string(pointer(buf[1:nbytes]))
end


"""
Expand Down

0 comments on commit 5c2ca4b

Please sign in to comment.