# HG changeset patch # User jwe # Date 863184772 0 # Node ID cf676ff8b702d0d6e120f9415e2e2402cd5fd4b8 # Parent 6744ac301eef60b9d2738a3ca757916f8dea3b68 [project @ 1997-05-09 13:32:46 by jwe] diff -r 6744ac301eef -r cf676ff8b702 liboctave/file-ops.cc --- a/liboctave/file-ops.cc Fri May 09 12:42:36 1997 +0000 +++ b/liboctave/file-ops.cc Fri May 09 13:32:52 1997 +0000 @@ -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; } } diff -r 6744ac301eef -r cf676ff8b702 liboctave/oct-env.cc --- a/liboctave/oct-env.cc Fri May 09 12:42:36 1997 +0000 +++ b/liboctave/oct-env.cc Fri May 09 13:32:52 1997 +0000 @@ -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 (); }