diff --git a/base/error.jl b/base/error.jl index 1ec4baf41804e..5ad40247da736 100644 --- a/base/error.jl +++ b/base/error.jl @@ -13,7 +13,7 @@ end errno() = ccall(:jl_errno, Int32, ()) strerror(e::Integer) = ccall(:jl_strerror, Any, (Int32,), e)::ByteString strerror() = strerror(errno()) -system_error(p, b::Bool) = b ? error(SystemError(string(p))) : nothing +system_error(p, b::Bool) = b ? throw(SystemError(cstring(p))) : nothing ## assertion functions and macros ## diff --git a/base/file.jl b/base/file.jl index f16a20084ec80..06c0e1cf0b65b 100644 --- a/base/file.jl +++ b/base/file.jl @@ -3,18 +3,11 @@ function cwd() b = Array(Uint8,1024) p = ccall(:getcwd, Ptr{Uint8}, (Ptr{Uint8}, Uint), b, length(b)) - if p == C_NULL - error("current directory has been deleted (or has a really long name)") - end + system_error("cwd", p==C_NULL) cstring(p) end -function cd(dir::String) - if ccall(:chdir, Int32, (Ptr{Uint8},), dir) == -1 - throw(SystemError("cd")) - end - cwd() -end +cd(dir::String) = (system_error("cd", ccall(:chdir, Int32, (Ptr{Uint8},), dir)==-1); cwd()) # do stuff in a directory, then return to current directory