diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-06-27 22:59:47 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-06-27 22:59:47 -0700 |
commit | b30b39c069b4dd20153c2252c900400a75c31a86 (patch) | |
tree | aa9c2dc116af99570b971d924bc84b18a5671b1d | |
parent | 368e8a45196958936b92fa5bd9e22cacdd808fdf (diff) | |
download | txr-b30b39c069b4dd20153c2252c900400a75c31a86.tar.gz txr-b30b39c069b4dd20153c2252c900400a75c31a86.tar.bz2 txr-b30b39c069b4dd20153c2252c900400a75c31a86.zip |
Handle two possible home dir locations on Cygwin.
Under the Cygwin port, if we are running in the Cygwin shell
enviroment, there is a HOME variable which contains a POSIX
path like /home/kaz. This path works fine and we use that.
If we are not running in the Cygwin environment, but running
as an application that uses the Cygwin DLL, then the HOME
variable is still defined, but the path doesn't resolve.
We must detect this, and fall back on the USERPROFILE
environment variable, which holds something like C:\Users\kaz.
* parser.c (get_home_path): New static function,
defined separately for Cygwin and other platforms.
(repl): Use get_home_path to determine home directory.
-rw-r--r-- | parser.c | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -644,6 +644,32 @@ static val read_eval_ret_last(val env, val counter, return t; } +#ifdef __CYGWIN__ +static val get_home_path(void) +{ + val path_exists_p = intern(lit("path-exists-p"), user_package); + + { + val posixy_home = getenv_wrap(lit("HOME")); + if (funcall1(path_exists_p, posixy_home)) + return posixy_home; + } + + { + val windowsy_home = getenv_wrap(lit("USERPROFILE")); + if (funcall1(path_exists_p, windowsy_home)) + return windowsy_home; + } + + return nil; +} +#else +static val get_home_path(void) +{ + return getenv_wrap(lit("HOME")); +} +#endif + val repl(val bindings, val in_stream, val out_stream) { val ifd = stream_get_prop(in_stream, fd_k); @@ -661,7 +687,7 @@ val repl(val bindings, val in_stream, val out_stream) val result_hash = make_hash(nil, nil, nil); val done = nil; val counter = one; - val home = getenv_wrap(lit("HOME")); + val home = get_home_path(); val histfile = if2(home, format(nil, lit("~a/.txr_history"), home, nao)); char *histfile_u8 = if3(home, utf8_dup_to(c_str(histfile)), NULL); val rcfile = if2(home, format(nil, lit("~a/.txr_profile"), home, nao)); |