Mercurial > octave
diff liboctave/system/oct-env.cc @ 19458:d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
* bootstrap.conf: add tempname module.
* liboctave/system/file-ops.cc:
(toplevel): include tempname.h.
(octave_tempnam): set up template based on input dir and prefix and call
gen_tempname to get temporary name.
* liboctave/system/oct-env.cc:
(octave_env::get_temp_directory): New function.
(octave_env::do_get_temp_directory): New function.
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Thu, 01 Jan 2015 10:01:18 -0500 |
parents | 49a5a4be04a1 |
children | f765fea3ca14 |
line wrap: on
line diff
--- a/liboctave/system/oct-env.cc Wed Dec 31 15:57:37 2014 -0500 +++ b/liboctave/system/oct-env.cc Thu Jan 01 10:01:18 2015 -0500 @@ -150,6 +150,13 @@ } std::string +octave_env::get_temp_directory () +{ + return (instance_ok ()) + ? instance->do_get_temp_directory () : std::string (); +} + +std::string octave_env::get_program_name (void) { return (instance_ok ()) @@ -184,6 +191,45 @@ ? instance->do_get_host_name () : std::string (); } +std::string +octave_env::do_get_temp_directory (void) const +{ + std::string tempd; + +#if defined (__MINGW32__) || defined (_MSC_VER) + + tempd = do_getenv ("TEMP"); + + if (tempd.empty ()) + tempd = do_getenv ("TMP"); + + #if defined (P_tmpdir) + if (tempd.empty ()) + tempd = P_tmpdir; + #endif + + // Some versions of MinGW and MSVC either don't define P_tmpdir, or + // define it to a single backslash. In such cases just use C:\temp. + if (tempd.empty () || tempd == "\\") + tempd = "c:\\temp"; + +#else ## Unix-like OS + + tempd = do_getenv ("TMP"); + + #if defined (P_tmpdir) + if (tempd.empty ()) + tempd = P_tmpdir; + #else + if (tempd.empty ()) + tempd = "/tmp"; + #endif + +#endif + + return tempd; +} + // FIXME: this leaves no way to distinguish between a // variable that is not set and one that is set to the empty string. // Is this a problem?