From 5c2ca4b74f6f35d1613bfff9cbada2b9d6093b2d Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Sat, 17 Dec 2016 13:47:46 -0800 Subject: [PATCH] Rewrite homedir based on uv_os_homedir --- base/path.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 """