diff --git a/base/path.jl b/base/path.jl index cb1c4121b895df..07c23c676a7661 100644 --- a/base/path.jl +++ b/base/path.jl @@ -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"[/\\]+" @@ -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 @@ -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 """