Mercurial > hg > octave-lyh
changeset 2947:cf676ff8b702
[project @ 1997-05-09 13:32:46 by jwe]
author | jwe |
---|---|
date | Fri, 09 May 1997 13:32:52 +0000 |
parents | 6744ac301eef |
children | 56be458e237f |
files | liboctave/file-ops.cc liboctave/oct-env.cc |
diffstat | 2 files changed, 23 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/file-ops.cc +++ b/liboctave/file-ops.cc @@ -213,7 +213,8 @@ if (beg != NPOS && name[beg] == '~') { - // If `~' or `~/', use $HOME if it exists, or `.' if it doesn't. + // If `~' or `~/', use the user's home directory. If that is + // empty, just use ".". // If `~user' or `~user/', look up user in the passwd database. @@ -237,21 +238,24 @@ size_t len = end; - if (len != NPOS) + if (end != NPOS) len -= beg + 1; string user = name.substr (beg+1, len); octave_passwd pw = octave_passwd::getpwnam (user); - // If no such user, just use `.'. + // If no such user, just return the original string. + + if (pw) + { + expansion = string (" ", beg) + pw.dir (); - string home = pw ? string (".") : pw.dir (); - - expansion = string (" ", beg) + home; - - if (end != NPOS) - expansion.append (name.substr (end)); + if (end != NPOS) + expansion.append (name.substr (end)); + } + else + expansion = name; } }
--- a/liboctave/oct-env.cc +++ b/liboctave/oct-env.cc @@ -54,6 +54,7 @@ #include "lo-utils.h" #include "oct-env.h" #include "oct-passwd.h" +#include "oct-syscalls.h" octave_env::octave_env (void) : follow_symbolic_links (true), verbatim_pwd (true), @@ -359,7 +360,14 @@ { string hd = do_getenv ("HOME"); - return hd.empty () ? string ("I have no home!") : hd; + if (hd.empty ()) + { + octave_passwd pw = octave_passwd::getpwuid (octave_syscalls::getuid ()); + + hd = pw ? pw.dir () : string ("I have no home!"); + } + + return hd; } string @@ -370,7 +378,7 @@ if (user_name.empty ()) { - octave_passwd pw = octave_passwd::getpwuid (getuid ()); + octave_passwd pw = octave_passwd::getpwuid (octave_syscalls::getuid ()); user_name = pw ? string ("I have no name!") : pw.name (); }