Mercurial > hg > octave-nkf
diff libinterp/corefcn/sysdep.cc @ 19359:6f0290863d50
Add new function unsetenv from gnulib to Octave.
* NEWS: Announce new function.
* bootstrap.conf: Pull unsetenv from gnulib.
* sysdep.cc (Fgetenv): Add seealso references to setenv, unsetenv.
* sysdep.cc (Fsetenv): Rename from Fputenv. Change DEFALIAS to be from setenv
to putenv. Redo docstring. Use unsetenv in BIST tests to get rid of temporary
environment variable.
* sysdep.cc (Funsetenv): New function.
* system.txi: Add unsetenv to manual.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 27 Sep 2014 12:26:57 -0700 |
parents | 7bccc182e2f7 |
children | efccb2a65b9a |
line wrap: on
line diff
--- a/libinterp/corefcn/sysdep.cc +++ b/libinterp/corefcn/sysdep.cc @@ -555,6 +555,7 @@ \n\ @noindent\n\ returns a string containing the value of your path.\n\ +@seealso{setenv, unsetenv}\n\ @end deftypefn") { octave_value retval; @@ -574,11 +575,20 @@ return retval; } -DEFUN (putenv, args, , +/* +%!assert (ischar (getenv ("OCTAVE_HOME"))) +*/ + +DEFUN (setenv, args, , "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} putenv (@var{var}, @var{value})\n\ -@deftypefnx {Built-in Function} {} setenv (@var{var}, @var{value})\n\ +@deftypefn {Built-in Function} {} setenv (@var{var}, @var{value})\n\ +@deftypefnx {Built-in Function} {} setenv (@var{var})\n\ +@deftypefnx {Built-in Function} {} putenv (@dots{})\n\ Set the value of the environment variable @var{var} to @var{value}.\n\ +\n\ +If no @var{value} is specified then the variable will be assigned the null\n\ +string.\n\ +@seealso{unsetenv, getenv}\n\ @end deftypefn") { octave_value_list retval; @@ -597,10 +607,10 @@ if (! error_state) octave_env::putenv (var, val); else - error ("putenv: VALUE must be a string"); + error ("setenv: VALUE must be a string"); } else - error ("putenv: VAR must be a string"); + error ("setenv: VAR must be a string"); } else print_usage (); @@ -608,13 +618,48 @@ return retval; } -DEFALIAS (setenv, putenv); +DEFALIAS (putenv, setenv); /* -%!assert (ischar (getenv ("OCTAVE_HOME"))) %!test %! setenv ("dummy_variable_that_cannot_matter", "foobar"); %! assert (getenv ("dummy_variable_that_cannot_matter"), "foobar"); +%! unsetenv ("dummy_variable_that_cannot_matter"); +%! assert (getenv ("dummy_variable_that_cannot_matter"), ""); +*/ + +DEFUN (unsetenv, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{status} =} unsetenv (@var{var})\n\ +Delete the environment variable @var{var}.\n\ +\n\ +Return 0 if the variable was deleted, or did not exist, and -1 if an error\n\ +occurred.\n\ +@seealso{setenv, getenv}\n\ +@end deftypefn") +{ + octave_value retval; + + int nargin = args.length (); + + if (nargin == 1) + { + const char *var = args(0).string_value ().c_str (); + + if (! error_state) + { + int status = gnulib::unsetenv (var); + retval = status; + } + } + else + print_usage (); + + return retval; +} + +/* +## Test for unsetenv is in setenv test */ // FIXME: perhaps kbhit should also be able to print a prompt?