changeset 20051:47d420d769ba

* sysdep.cc (Fget_home_directory): New function.
author John W. Eaton <jwe@octave.org>
date Thu, 02 Apr 2015 13:08:34 -0400
parents 519eb032ac35
children 4b7b7ac7af2c
files libinterp/corefcn/sysdep.cc
diffstat 1 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/sysdep.cc	Thu Apr 02 13:08:56 2015 -0400
+++ b/libinterp/corefcn/sysdep.cc	Thu Apr 02 13:08:34 2015 -0400
@@ -1003,15 +1003,25 @@
 
 /*
 %!test
-%! if (isempty (getenv ("HOME")))
-%!   setenv ("HOME", "foobar");
-%! endif
-%! home = getenv ("HOME");
-%! assert (tilde_expand ("~/foobar"), strcat (home, "/foobar"));
+%! home = get_home_directory ();
+%! assert (tilde_expand ("~/foobar"), fullfile (home, "/foobar"));
 %! assert (tilde_expand ("/foo/bar"), "/foo/bar");
 %! assert (tilde_expand ("foo/bar"), "foo/bar");
 */
 
+DEFUN (get_home_directory, , ,
+       "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} get_home_directory ()\n\
+Return the current home directory.  On most systems, this is equivalent\n\
+to @code{getenv (\"HOME\")}.  On Windows systems, if @env{HOME} is not\n\
+set in the environment, it is equivalent to\n\
+@code{fullfile (getenv (\"HOMEDRIVE\"), getenv (\"HOMEPATH\"))}\n\
+@seealso{getenv}\n\
+@end deftypefn")
+{
+  return octave_value (octave_env::get_home_directory ());
+}
+
 // This function really belongs in display.cc, but including defun.h in
 // that file results in conflicts with symbols from headers that are
 // needed for X11 and Carbon functions.