diff options
author | Dan Gudmundsson <[email protected]> | 2017-09-26 13:25:50 +0200 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2017-09-27 16:02:15 +0200 |
commit | 73500d2a456023ca36172f5af896d0b1f10853b7 (patch) | |
tree | 378af5a7204b55eba7b16e3cbd4ec0fbe845671a /lib/stdlib | |
parent | 44c0da287d683609319b74c25dbade61408501b3 (diff) | |
download | otp-73500d2a456023ca36172f5af896d0b1f10853b7.tar.gz otp-73500d2a456023ca36172f5af896d0b1f10853b7.tar.bz2 otp-73500d2a456023ca36172f5af896d0b1f10853b7.zip |
Do not load .erlang from current dir
It may be confusing that "hidden" .erlang is loaded from the current
working directory. Use c:erlangrc([Dir1,..]) to search and
load .erlang from other places than "$HOME/.erlang".
Implies that c:erlangrc() needs to be documented.
Diffstat (limited to 'lib/stdlib')
-rw-r--r-- | lib/stdlib/doc/src/c.xml | 9 | ||||
-rw-r--r-- | lib/stdlib/src/c.erl | 18 |
2 files changed, 20 insertions, 7 deletions
diff --git a/lib/stdlib/doc/src/c.xml b/lib/stdlib/doc/src/c.xml index 7666699183..697e1715e7 100644 --- a/lib/stdlib/doc/src/c.xml +++ b/lib/stdlib/doc/src/c.xml @@ -94,6 +94,15 @@ </func> <func> + <name name="erlangrc" arity="1"/> + <fsummary>Load an erlang resource file.</fsummary> + <desc> + <p>Search <c>PathList</c> and load <c>.erlang</c> resource file if + found.</p> + </desc> + </func> + + <func> <name name="flush" arity="0"/> <fsummary>Flush any messages sent to the shell.</fsummary> <desc> diff --git a/lib/stdlib/src/c.erl b/lib/stdlib/src/c.erl index c04a201ce1..9a447af5b7 100644 --- a/lib/stdlib/src/c.erl +++ b/lib/stdlib/src/c.erl @@ -668,19 +668,23 @@ lm() -> [l(M) || M <- mm()]. %% erlangrc(Home) -%% Try to run a ".erlang" file, first in the current directory -%% else in home directory. +%% Try to run a ".erlang" file in home directory. + +-spec erlangrc() -> {ok, file:filename()} | {error, term()}. erlangrc() -> case init:get_argument(home) of {ok,[[Home]]} -> erlangrc([Home]); _ -> - f_p_e(["."], ".erlang") + {error, enoent} end. -erlangrc([Home]) -> - f_p_e([".",Home], ".erlang"). +-spec erlangrc(PathList) -> {ok, file:filename()} | {error, term()} + when PathList :: [Dir :: file:name()]. + +erlangrc([Home|_]=Paths) when is_list(Home) -> + f_p_e(Paths, ".erlang"). error(Fmt, Args) -> error_logger:error_msg(Fmt, Args). @@ -692,11 +696,11 @@ f_p_e(P, F) -> {error, E={Line, _Mod, _Term}} -> error("file:path_eval(~tp,~tp): error on line ~p: ~ts~n", [P, F, Line, file:format_error(E)]), - ok; + {error, E}; {error, E} -> error("file:path_eval(~tp,~tp): ~ts~n", [P, F, file:format_error(E)]), - ok; + {error, E}; Other -> Other end. |