# HG changeset patch # User jwe # Date 822896309 0 # Node ID 8173b1fa052db1e079c778551c3934217248fbbc # Parent 401f4226c63911614d74fc07962fc45ae6df308a [project @ 1996-01-29 06:10:18 by jwe] diff -r 401f4226c639 -r 8173b1fa052d liboctave/file-ops.cc --- a/liboctave/file-ops.cc Mon Jan 29 06:03:49 1996 +0000 +++ b/liboctave/file-ops.cc Mon Jan 29 06:18:29 1996 +0000 @@ -26,6 +26,8 @@ #endif #include +#include +#include #include #ifdef HAVE_UNISTD_H @@ -34,6 +36,7 @@ #endif #include "file-ops.h" +#include "lo-error.h" #include "statdefs.h" // These must come after and . @@ -221,6 +224,26 @@ return rmdir (name.c_str ()); } +string +oct_tempnam (void) +{ + string retval; + + char *tmp = tempnam (0, "oct-"); + + if (tmp) + { + retval = tmp; + + free (tmp); + } + else + (*current_liboctave_error_handler) ("can't open temporary file!"); + + return retval; +} + + int oct_umask (mode_t mode) { diff -r 401f4226c639 -r 8173b1fa052d src/file-io.cc --- a/src/file-io.cc Mon Jan 29 06:03:49 1996 +0000 +++ b/src/file-io.cc Mon Jan 29 06:18:29 1996 +0000 @@ -1384,7 +1384,7 @@ xstring = xstring_str.c_str (); } - tmp_file = octave_tmp_file_name (); + tmp_file = oct_tempnam (); fptr = fopen (tmp_file.c_str (), "w+"); if (! fptr) @@ -2513,6 +2513,20 @@ return retval; } +DEFUN ("octave_tmp_file_name", Foctave_tmp_file_name, + Soctave_tmp_file_name, 10, + "octave_tmp_file_name ()") +{ + tree_constant retval; + + if (args.length () == 0) + retval = oct_tempnam (); + else + print_usage ("octave_tmp_file_name"); + + return retval; +} + static int convert (int x, int ibase, int obase) { diff -r 401f4226c639 -r 8173b1fa052d src/oct-hist.cc --- a/src/oct-hist.cc Mon Jan 29 06:03:49 1996 +0000 +++ b/src/oct-hist.cc Mon Jan 29 06:18:29 1996 +0000 @@ -47,6 +47,7 @@ #endif #include "cmd-hist.h" +#include "file-ops.h" #include "str-vec.h" #include "defun.h" @@ -387,7 +388,7 @@ reverse = 1; } - string name = octave_tmp_file_name (); + string name = oct_tempnam (); fstream file (name.c_str (), ios::out); diff -r 401f4226c639 -r 8173b1fa052d src/pt-plot.cc --- a/src/pt-plot.cc Mon Jan 29 06:03:49 1996 +0000 +++ b/src/pt-plot.cc Mon Jan 29 06:18:29 1996 +0000 @@ -45,6 +45,7 @@ #include "SLStack.h" #include "procstream.h" +#include "file-ops.h" #include "str-vec.h" #include "defun.h" @@ -914,7 +915,7 @@ string save_in_tmp_file (tree_constant& t, int ndim, int parametric) { - string name = octave_tmp_file_name (); + string name = oct_tempnam (); if (! name.empty ()) { diff -r 401f4226c639 -r 8173b1fa052d src/utils.cc --- a/src/utils.cc Mon Jan 29 06:03:49 1996 +0000 +++ b/src/utils.cc Mon Jan 29 06:18:29 1996 +0000 @@ -166,41 +166,6 @@ } #endif -// Get a temporary file name. - -string -octave_tmp_file_name (void) -{ - string retval; - - char *tmp = tempnam (0, "oct-"); - - if (tmp) - { - retval = tmp; - - free (tmp); - } - else - error ("can't open temporary file!"); - - return retval; -} - -DEFUN ("octave_tmp_file_name", Foctave_tmp_file_name, - Soctave_tmp_file_name, 10, - "octave_tmp_file_name ()") -{ - tree_constant retval; - - if (args.length () == 0) - retval = octave_tmp_file_name (); - else - print_usage ("octave_tmp_file_name"); - - return retval; -} - // Return to the main command loop in octave.cc. extern "C" void