From 5b04cb002ed65f4bbd8c0ea82cc4e3ba855dff56 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 | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/base/path.jl b/base/path.jl index cb1c4121b895d..1f4e6eb8b547b 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,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 """