changeset 19470:6ca096827123

Use tempname() rather than tmpnam() in core Octave. * scripts/miscellaneous/tempname.m: Removed m-file as function is now C++. * scripts/miscellaneous/tmpnam.m: New m-file is an alias that calls tempname. * scripts/miscellaneous/module.mk: Add tmpnam.m to build system. * io.txi: Place tempname, tempdir, P_tmpdir docstrings in section on temporary files. * system.txi: Remove tempname, tempdir, P_tmpdir docstrings from generic system functions section of manual. * dirfns.cc, dlmread.cc, md5sum.cc, ov-fcn-handle.cc: Replace instances of tmpnam with tempname in BIST code. * file-io.cc (Ftempname): Change DEFUNX for tmpnam to DEFUN for tempname. Remove seealso links to tmpnam. * ftp.m, playaudio.m, wavwrite.m, imformats.m, imread.m, imwrite.m, imageIO.m, csvwrite.m, dlmwrite.m, fileread.m, importdata.m, textread.m, textscan.m, genvarname.m, unpack.m, install.m, legend.m, __gnuplot_drawnow__.m, copyobj.m, hgsave.m, print.m, __ghostscript__.m, __gnuplot_get_var__.m, __gnuplot_ginput__.m, __gnuplot_print__.m: Replace tmpnam with tempname in core code. * build-sparse-tests.sh, io.tst, prefer.tst, system.tst: Replace tmpnam with tempname in test code.
author Rik <rik@octave.org>
date Wed, 22 Oct 2014 10:41:15 -0700
parents 18a3eaf7bdf0
children da86488d3d59
files doc/interpreter/io.txi doc/interpreter/system.txi libinterp/corefcn/dirfns.cc libinterp/corefcn/dlmread.cc libinterp/corefcn/file-io.cc libinterp/corefcn/md5sum.cc libinterp/octave-value/ov-fcn-handle.cc scripts/@ftp/ftp.m scripts/audio/playaudio.m scripts/audio/wavwrite.m scripts/image/imformats.m scripts/image/imread.m scripts/image/imwrite.m scripts/image/private/imageIO.m scripts/io/csvwrite.m scripts/io/dlmwrite.m scripts/io/fileread.m scripts/io/importdata.m scripts/io/textread.m scripts/io/textscan.m scripts/miscellaneous/genvarname.m scripts/miscellaneous/module.mk scripts/miscellaneous/tempname.m scripts/miscellaneous/tmpnam.m scripts/miscellaneous/unpack.m scripts/pkg/private/install.m scripts/plot/appearance/legend.m scripts/plot/util/__gnuplot_drawnow__.m scripts/plot/util/copyobj.m scripts/plot/util/hgsave.m scripts/plot/util/print.m scripts/plot/util/private/__ghostscript__.m scripts/plot/util/private/__gnuplot_get_var__.m scripts/plot/util/private/__gnuplot_ginput__.m scripts/plot/util/private/__gnuplot_print__.m test/build-sparse-tests.sh test/io.tst test/prefer.tst test/system.tst
diffstat 39 files changed, 161 insertions(+), 161 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/io.txi
+++ b/doc/interpreter/io.txi
@@ -1006,7 +1006,11 @@
 
 @DOCSTRING(tmpfile)
 
-@DOCSTRING(tmpnam)
+@DOCSTRING(tempname)
+
+@DOCSTRING(tempdir)
+
+@DOCSTRING(P_tmpdir)
 
 @node EOF and Errors
 @subsection End of File and Errors
--- a/doc/interpreter/system.txi
+++ b/doc/interpreter/system.txi
@@ -222,12 +222,6 @@
 
 @DOCSTRING(is_rooted_relative_filename)
 
-@DOCSTRING(P_tmpdir)
-
-@DOCSTRING(tempdir)
-
-@DOCSTRING(tempname)
-
 @DOCSTRING(recycle)
 
 @node File Archiving Utilities
--- a/libinterp/corefcn/dirfns.cc
+++ b/libinterp/corefcn/dirfns.cc
@@ -634,7 +634,7 @@
 
 /*
 %!test
-%! tmpdir = tmpnam;
+%! tmpdir = tempname;
 %! filename = {"file1", "file2", "file3", "myfile1", "myfile1b"};
 %! if (mkdir (tmpdir))
 %!   cwd = pwd;
--- a/libinterp/corefcn/dlmread.cc
+++ b/libinterp/corefcn/dlmread.cc
@@ -491,7 +491,7 @@
 
 /*
 %!shared file
-%! file = tmpnam ();
+%! file = tempname ();
 %! fid = fopen (file, "wt");
 %! fwrite (fid, "1, 2, 3\n4, 5, 6\n7, 8, 9\n10, 11, 12");
 %! fclose (fid);
@@ -510,7 +510,7 @@
 %! unlink (file);
 
 %!shared file
-%! file = tmpnam ();
+%! file = tempname ();
 %! fid = fopen (file, "wt");
 %! fwrite (fid, "1, 2, 3\n4+4i, 5, 6\n7, 8, 9\n10, 11, 12");
 %! fclose (fid);
--- a/libinterp/corefcn/file-io.cc
+++ b/libinterp/corefcn/file-io.cc
@@ -1930,11 +1930,11 @@
   return retval;
 }
 
-DEFUNX ("tmpnam", Ftmpnam, args, ,
-        "-*- texinfo -*-\n\
-@deftypefn  {Built-in Function} {@var{fname} =} tmpnam ()\n\
-@deftypefnx {Built-in Function} {@var{fname} =} tmpnam (@var{dir})\n\
-@deftypefnx {Built-in Function} {@var{fname} =} tmpnam (@var{dir}, @var{prefix})\n\
+DEFUN (tempname, args, ,
+       "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{fname} =} tempname ()\n\
+@deftypefnx {Built-in Function} {@var{fname} =} tempname (@var{dir})\n\
+@deftypefnx {Built-in Function} {@var{fname} =} tempname (@var{dir}, @var{prefix})\n\
 Return a unique temporary file name as a string.\n\
 \n\
 If @var{prefix} is omitted, a value of @qcode{\"oct-\"} is used.\n\
@@ -1942,12 +1942,11 @@
 (@code{P_tmpdir} is used.  If @var{dir} is provided, it must exist,\n\
 otherwise the default directory for temporary files is used.\n\
 \n\
-Programming Note: Because the named file is not opened by @code{tmpnam},\n\
+Programming Note: Because the named file is not opened by @code{tempname},\n\
 it is possible, though relatively unlikely, that it will not be available\n\
 by the time your program attempts to open it.  If this is a concern,\n\
-see @code{tmpfile}.  The functions @code{tmpnam} and @code{tempname} are\n\
-equivalent with the latter provided for @sc{matlab} compatibility.\n\
-@seealso{tempname, mkstemp, tempdir, P_tmpdir, tmpfile}\n\
+see @code{tmpfile}.\n\
+@seealso{mkstemp, tempdir, P_tmpdir, tmpfile}\n\
 @end deftypefn")
 {
   octave_value retval;
@@ -1989,7 +1988,7 @@
 If successful, @var{fid} is a valid file ID and @var{msg} is an empty\n\
 string.  Otherwise, @var{fid} is -1 and @var{msg} contains a\n\
 system-dependent error message.\n\
-@seealso{tempname, tmpnam, mkstemp, tempdir, P_tmpdir}\n\
+@seealso{tempname, mkstemp, tempdir, P_tmpdir}\n\
 @end deftypefn")
 {
   octave_value_list retval;
@@ -2049,7 +2048,7 @@
 If successful, @var{fid} is a valid file ID, @var{name} is the name of the\n\
 file, and @var{msg} is an empty string.  Otherwise, @var{fid} is -1,\n\
 @var{name} is empty, and @var{msg} contains a system-dependent error message.\n\
-@seealso{tempname, tmpnam, tempdir, P_tmpdir, tmpfile, fopen}\n\
+@seealso{tempname, tempdir, P_tmpdir, tmpfile, fopen}\n\
 @end deftypefn")
 {
   octave_value_list retval;
@@ -2220,7 +2219,7 @@
 default location.  This value may not agree with that returned from\n\
 @code{tempdir} if the user has overriden the default with the @env{TMPDIR}\n\
 environment variable.\n\
-@seealso{tempdir, tempname, tmpnam, mkstemp, tmpfile}\n\
+@seealso{tempdir, tempname, mkstemp, tmpfile}\n\
 @end deftypefn")
 {
   octave_value retval;
--- a/libinterp/corefcn/md5sum.cc
+++ b/libinterp/corefcn/md5sum.cc
@@ -80,7 +80,7 @@
 %!assert (md5sum ("abc\0", true), "147a664a2ca9410911e61986d3f0d52a");
 
 %!test
-%! tfile = tmpnam ();
+%! tfile = tempname ();
 %! fid = fopen (tfile, "wb");
 %! fwrite (fid, "abc\0");
 %! fclose (fid);
--- a/libinterp/octave-value/ov-fcn-handle.cc
+++ b/libinterp/octave-value/ov-fcn-handle.cc
@@ -1316,7 +1316,7 @@
 %! endif
 %! for i = 1:numel (modes)
 %!   mode = modes{i};
-%!   nm = tmpnam ();
+%!   nm = tempname ();
 %!   unwind_protect
 %!     f2 (1); # bug #33857
 %!     save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2");
@@ -1369,7 +1369,7 @@
 %! endif
 %! for i = 1:numel (modes)
 %!   mode = modes{i};
-%!   nm = tmpnam ();
+%!   nm = tempname ();
 %!   unwind_protect
 %!     fcn_handle_save_recurse (2, mode, nm, f2, g2, hm2, hdld2, hbi2);
 %!     clear f2 g2 hm2 hdld2 hbi2
--- a/scripts/@ftp/ftp.m
+++ b/scripts/@ftp/ftp.m
@@ -51,7 +51,7 @@
     p.host = host;
     p.username = username;
     p.password = password;
-    p.curlhandle = tmpnam ("ftp-");
+    p.curlhandle = tempname ("ftp-");
     if (nargin > 0)
       p.curlhandle = __ftp__ (host, username, password);
     endif
--- a/scripts/audio/playaudio.m
+++ b/scripts/audio/playaudio.m
@@ -41,7 +41,7 @@
     endif
     X = name(:) + 127;
     unwind_protect
-      file = tmpnam ();
+      file = tempname ();
       fid = fopen (file, "wb");
       fwrite (fid, X, "uchar");
       fclose (fid);
--- a/scripts/audio/wavwrite.m
+++ b/scripts/audio/wavwrite.m
@@ -151,7 +151,7 @@
 
 
 %!shared fname
-%! fname = tmpnam ();
+%! fname = tempname ();
 
 %!test
 %! A = [-1:0.1:1; -1:0.1:1]';
--- a/scripts/image/imformats.m
+++ b/scripts/image/imformats.m
@@ -286,7 +286,7 @@
 
 ## changing the function that does the reading
 %!testif HAVE_MAGICK
-%! fname = [tmpnam() ".jpg"];
+%! fname = [tempname() ".jpg"];
 %! def_fmt = imformats ();
 %! fid = fopen (fname, "w");
 %! unwind_protect
@@ -302,7 +302,7 @@
 
 ## adding a new format
 %!testif HAVE_MAGICK
-%! fname = [tmpnam() ".new_fmt"];
+%! fname = [tempname() ".new_fmt"];
 %! def_fmt = imformats ();
 %! fid = fopen (fname, "w");
 %! unwind_protect
@@ -319,9 +319,9 @@
 
 ## adding multiple formats at the same time
 %!testif HAVE_MAGICK
-%! fname1 = [tmpnam() ".new_fmt1"];
+%! fname1 = [tempname() ".new_fmt1"];
 %! fid1 = fopen (fname1, "w");
-%! fname2 = [tmpnam() ".new_fmt2"];
+%! fname2 = [tempname() ".new_fmt2"];
 %! fid2 = fopen (fname2, "w");
 %! def_fmt = imformats ();
 %! unwind_protect
--- a/scripts/image/imread.m
+++ b/scripts/image/imread.m
@@ -127,7 +127,7 @@
 %!   16,  28, 160,  16,   0, 197, 214,  13,  34,  74, ...
 %!  117, 213,  17,   0,   0,   0,   0,  73,  69,  78, ...
 %!   68, 174,  66,  96, 130];
-%! filename = [tmpnam() ".png"];
+%! filename = [tempname() ".png"];
 %! unwind_protect
 %!   fid = fopen (filename, "wb");
 %!   fwrite (fid, vpng);
@@ -141,7 +141,7 @@
 %! assert (A(:,:,3), uint8 ([0, 255, 0; 255,  36, 255; 0, 255, 0]));
 
 %!function [r, cmap, a] = write_and_read (w, varargin)
-%!  filename = [tmpnam() ".tif"];
+%!  filename = [tempname() ".tif"];
 %!  unwind_protect
 %!    imwrite (w, filename);
 %!    [r, cmap, a] = imread (filename, varargin{:});
@@ -183,7 +183,7 @@
 ## make one of the formats read, return what it received as input to
 ## confirm that the input parsing is working correcly
 %!testif HAVE_MAGICK
-%! fname = [tmpnam() ".jpg"];
+%! fname = [tempname() ".jpg"];
 %! def_fmt = imformats ();
 %! fid = fopen (fname, "w");
 %! unwind_protect
--- a/scripts/image/imwrite.m
+++ b/scripts/image/imwrite.m
@@ -126,7 +126,7 @@
 %!error imwrite (spones (2), "filename.jpg")  # Invalid sparse img
 
 %!function [r, cmap, a] = write_and_read (varargin)
-%!  filename = [tmpnam() ".tif"];
+%!  filename = [tempname() ".tif"];
 %!  unwind_protect
 %!    imwrite (varargin{1}, filename, varargin{2:end});
 %!    [r, cmap, a] = imread (filename, "Index", "all");
--- a/scripts/image/private/imageIO.m
+++ b/scripts/image/private/imageIO.m
@@ -61,10 +61,10 @@
   ## Maybe we have an URL
   if (isempty (fn))
     file_2_delete = true; # mark file for deletion
-    [fn, ~] = urlwrite (filename, tmpnam ());
+    [fn, ~] = urlwrite (filename, tempname ());
     ## Maybe the URL is missing the file extension
     if (isempty (fn) && ! isempty (varargin))
-      [fn, ~] = urlwrite ([filename "." varargin{1}], tmpnam ());
+      [fn, ~] = urlwrite ([filename "." varargin{1}], tempname ());
     endif
 
     if (isempty (fn))
--- a/scripts/io/csvwrite.m
+++ b/scripts/io/csvwrite.m
@@ -37,7 +37,7 @@
 
 
 %!shared fname
-%! fname = tmpnam ();
+%! fname = tempname ();
 
 %!test
 %! csvwrite (fname, magic (3));
--- a/scripts/io/dlmwrite.m
+++ b/scripts/io/dlmwrite.m
@@ -201,7 +201,7 @@
 
 
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! dlmwrite (f,[1,2;3,4],"precision","%5.2f","newline","unix","roffset",1,"coffset",1);
 %! fid = fopen (f,"rt");
 %! f1 = char (fread (fid,Inf,"char")');
--- a/scripts/io/fileread.m
+++ b/scripts/io/fileread.m
@@ -48,7 +48,7 @@
 
 %!test
 %! cstr = {"Hello World", "The answer is 42", "Goodbye World"};
-%! fname = tmpnam ();
+%! fname = tempname ();
 %! fid = fopen (fname, "w");
 %! fprintf (fid, "%s\n", cstr{:});
 %! fclose (fid);
--- a/scripts/io/importdata.m
+++ b/scripts/io/importdata.m
@@ -292,7 +292,7 @@
 %!test
 %! ## Comma separated values
 %! A = [3.1 -7.2 0; 0.012 6.5 128];
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fputs (fid, "3.1,-7.2,0\n0.012,6.5,128");
 %! fclose (fid);
@@ -309,7 +309,7 @@
 %!test
 %! ## Tab separated values
 %! A = [3.1 -7.2 0; 0.012 6.5 128];
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fputs (fid, "3.1\t-7.2\t0\n0.012\t6.5\t128");
 %! fclose (fid);
@@ -326,7 +326,7 @@
 %!test
 %! ## Space separated values, using multiple spaces to align in columns.
 %! A = [3.1 -7.2 0; 0.012 6.5 128];
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fprintf (fid, "%10.3f %10.3f %10.3f\n", A');
 %! fclose (fid);
@@ -343,7 +343,7 @@
 %!test
 %! ## No separator, 1 column of data only
 %! A = [3.1;-7.2;0;0.012;6.5;128];
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fprintf (fid, "%f\n", A);
 %! fclose (fid);
@@ -363,7 +363,7 @@
 %! A.textdata = {"This is a header row."; ...
 %!               "this row does not contain any data, but the next one does."};
 %! A.colheaders = A.textdata (2);
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fprintf (fid, "%s\n", A.textdata{:});
 %! fputs (fid, "3.1\t-7.2\t0\n0.012\t6.5\t128");
@@ -380,7 +380,7 @@
 %! A.textdata = {"Label1\tLabel2\tLabel3";
 %!               "col 1\tcol 2\tcol 3"};
 %! A.colheaders = {"col 1", "col 2", "col 3"};
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fprintf (fid, "%s\n", A.textdata{:});
 %! fputs (fid, "3.1\t-7.2\t0\n0.012\t6.5\t128");
@@ -396,7 +396,7 @@
 %! A.data = [3.1 -7.2 0; 0.012 6.5 128];
 %! A.textdata = {"row1"; "row2"};
 %! A.rowheaders = A.textdata;
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fputs (fid, "row1\t3.1\t-7.2\t0\nrow2\t0.012\t6.5\t128");
 %! fclose (fid);
@@ -413,7 +413,7 @@
 %!               "      col1 col2 col3"
 %!               "row1"
 %!               "row2"};
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fprintf (fid, "%s\n", A.textdata{1:2});
 %! fputs (fid, "row1\t3.1\t-7.2\t0\nrow2\t0.012\t6.5\t128");
@@ -427,7 +427,7 @@
 %!test
 %! ## Ignore empty rows containing only spaces
 %! A = [3.1 -7.2 0; 0.012 6.5 128];
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fprintf (fid, "%10.3f %10.3f %10.3f\n", A(1,:));
 %! fputs (fid, "      ");
@@ -442,7 +442,7 @@
 %!test
 %! ## Exponentials
 %! A = [3.1 -7.2 0; 0.012 6.5 128];
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fputs (fid, "+3.1e0\t-72E-1\t0\n12e-3\t6.5\t128");
 %! fclose (fid);
@@ -455,7 +455,7 @@
 %!test
 %! ## Complex numbers
 %! A = [3.1 -7.2 0-3.4i; 0.012 -6.5+7.2i 128];
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fputs (fid, "3.1\t-7.2\t0-3.4i\n0.012\t-6.5+7.2i\t128");
 %! fclose (fid);
@@ -468,7 +468,7 @@
 %!test
 %! ## Exceptional values (Inf, NaN, NA)
 %! A = [3.1 Inf NA; -Inf NaN 128];
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fputs (fid, "3.1\tInf\tNA\n-Inf\tNaN\t128");
 %! fclose (fid);
@@ -483,7 +483,7 @@
 %! A.data = [3.1 NA 0; 0.012 NA 128];
 %! A.textdata = {char(zeros(1,0))
 %!               "NO DATA"};
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fputs (fid, "3.1\t\t0\n0.012\tNO DATA\t128");
 %! fclose (fid);
@@ -496,7 +496,7 @@
 %!#test
 %! ## CRLF for line breaks
 %! A = [3.1 -7.2 0; 0.012 6.5 128];
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fputs (fid, "3.1\t-7.2\t0\r\n0.012\t6.5\t128");
 %! fclose (fid);
@@ -509,7 +509,7 @@
 %!#test
 %! ## CR for line breaks
 %! A = [3.1 -7.2 0; 0.012 6.5 128];
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fputs (fid, "3.1\t-7.2\t0\r0.012\t6.5\t128");
 %! fclose (fid);
@@ -521,7 +521,7 @@
 
 %!test
 %! ## Only text / no numeric data; \n as EOL
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fputs (fid, "aaaa 11\nbbbbb 22\nccccc 3\n");
 %! fclose (fid);
@@ -533,7 +533,7 @@
 
 %!test
 %! ## Only text / no numeric data; \r\n as EOL; missing last EOL before EOF
-%! fn  = tmpnam ();
+%! fn  = tempname ();
 %! fid = fopen (fn, "w");
 %! fputs (fid, "aaaa 11\r\nbbbbb 22\r\nccccc 3");
 %! fclose (fid);
--- a/scripts/io/textread.m
+++ b/scripts/io/textread.m
@@ -221,7 +221,7 @@
 
 
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! d = rand (5, 3);
 %! dlmwrite (f, d, "precision", "%5.2f");
 %! [a, b, c] = textread (f, "%f %f %f", "delimiter", ",", "headerlines", 3);
@@ -231,7 +231,7 @@
 %! assert (c, d(4:5, 3), 1e-2);
 
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! d = rand (7, 2);
 %! dlmwrite (f, d, "precision", "%5.2f");
 %! [a, b] = textread (f, "%f, %f", "headerlines", 1);
@@ -240,7 +240,7 @@
 
 %% Test reading 2D matrix with empty format
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! d = rand (5, 2);
 %! dlmwrite (f, d, "precision", "%5.2f");
 %! A = textread (f, "", "headerlines", 3);
@@ -249,7 +249,7 @@
 
 %% Read multiple lines using empty format string
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! unlink (f);
 %! fid = fopen (f, "w");
 %! d = rand (1, 4);
@@ -261,7 +261,7 @@
 
 %% Empty format, corner case = one line w/o EOL
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! unlink (f);
 %! fid = fopen (f, "w");
 %! d = rand (1, 4);
@@ -273,7 +273,7 @@
 
 %% Read multiple lines using empty format string, missing data (should be 0)
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! unlink (f);
 %! fid = fopen (f, "w");
 %! d = rand (1, 4);
@@ -285,7 +285,7 @@
 
 %% Test with empty positions - ML returns 0 for empty fields
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! unlink (f);
 %! fid = fopen (f, "w");
 %! d = rand (1, 4);
@@ -298,7 +298,7 @@
 %% Another test with empty format + positions, now with more incomplete lower
 %% row (must be appended with zeros to get rectangular matrix)
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! unlink (f);
 %! fid = fopen (f, "w");
 %! d = rand (1, 4);
--- a/scripts/io/textscan.m
+++ b/scripts/io/textscan.m
@@ -581,7 +581,7 @@
 
 %% Test reading from a real file
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! fid = fopen (f, "w+");
 %! d = rand (1, 4);
 %! fprintf (fid, "  %f %f   %f  %f ", d);
@@ -594,7 +594,7 @@
 
 %% Tests reading with empty format, should return proper nr of columns
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! fid = fopen (f, "w+");
 %! fprintf (fid, " 1 2 3 4\n5 6 7 8");
 %! fseek (fid, 0, "bof");
@@ -608,7 +608,7 @@
 
 %% Tests reading with empty format; empty fields & incomplete lower row
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! fid = fopen (f, "w+");
 %! fprintf (fid, " ,2,,4\n5,6");
 %! fseek (fid, 0, "bof");
@@ -620,7 +620,7 @@
 %% Error message tests
 
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! fid = fopen (f, "w+");
 %! msg1 = "Missing or illegal value for 'headerlines'";
 %! try
@@ -631,7 +631,7 @@
 %! assert (msg1, lasterr);
 
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! fid = fopen (f, "w+");
 %! msg1 = "Missing or illegal value for 'headerlines'";
 %! try
@@ -642,7 +642,7 @@
 %! assert (msg1, lasterr);
 
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! fid = fopen (f, "w+");
 %! fprintf (fid,"some_string");
 %! fseek (fid, 0, "bof");
@@ -655,7 +655,7 @@
 %! assert (msg1, lasterr);
 
 %!test
-%! f = tmpnam ();
+%! f = tempname ();
 %! fid = fopen (f, "w+");
 %! fprintf (fid,"some_string");
 %! fseek (fid, 0, "bof");
--- a/scripts/miscellaneous/genvarname.m
+++ b/scripts/miscellaneous/genvarname.m
@@ -90,7 +90,7 @@
 ## appended if necessary.  Note, however, that this does @strong{not} include
 ## function names such as @qcode{"sin"}.  Such names should be included in
 ## @var{exclusions} if necessary.
-## @seealso{isvarname, iskeyword, exist, who, tmpnam, eval}
+## @seealso{isvarname, iskeyword, exist, who, tempname, eval}
 ## @end deftypefn
 
 ## Authors: Rob Platt <robert.platt@postgrad.manchester.ac.uk>
--- a/scripts/miscellaneous/module.mk
+++ b/scripts/miscellaneous/module.mk
@@ -68,7 +68,7 @@
   miscellaneous/symvar.m \
   miscellaneous/tar.m \
   miscellaneous/tempdir.m \
-  miscellaneous/tempname.m \
+  miscellaneous/tmpnam.m \
   miscellaneous/unix.m \
   miscellaneous/unpack.m \
   miscellaneous/untar.m \
deleted file mode 100644
--- a/scripts/miscellaneous/tempname.m
+++ /dev/null
@@ -1,47 +0,0 @@
-## Copyright (C) 2003-2013 John W. Eaton
-##
-## This file is part of Octave.
-##
-## Octave is free software; you can redistribute it and/or modify it
-## under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 3 of the License, or (at
-## your option) any later version.
-##
-## Octave is distributed in the hope that it will be useful, but
-## WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-## General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with Octave; see the file COPYING.  If not, see
-## <http://www.gnu.org/licenses/>.
-
-## -*- texinfo -*-
-## @deftypefn  {Built-in Function} {@var{fname} =} tempname ()
-## @deftypefnx {Built-in Function} {@var{fname} =} tempname (@var{dir})
-## @deftypefnx {Built-in Function} {@var{fname} =} tempname (@var{dir}, @var{prefix})
-## Return a unique temporary file name as a string.
-## 
-## If @var{prefix} is omitted, a value of @qcode{"oct-"} is used.
-## If @var{dir} is also omitted, the default directory for temporary files
-## (@code{P_tmpdir} is used.  If @var{dir} is provided, it must exist,
-## otherwise the default directory for temporary files is used.
-##
-## Programming Note: Because the named file is not opened by @code{tempname},
-## it is possible, though relatively unlikely, that it will not be available
-## by the time your program attempts to open it.  If this is a concern,
-## see @code{tmpfile}.  The functions @code{tmpnam} and @code{tempname} are
-## equivalent with the latter provided for @sc{matlab} compatibility.
-## @seealso{tmpnam, mkstemp, tempdir, P_tmpdir, tmpfile}
-## @end deftypefn
-
-function filename = tempname (varargin)
-
-  filename = tmpnam (varargin{:});
-
-endfunction
-
-
-## No tests needed for alias.
-%!assert (1)
-
new file mode 100644
--- /dev/null
+++ b/scripts/miscellaneous/tmpnam.m
@@ -0,0 +1,50 @@
+## Copyright (C) 2003-2013 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn  {Function File} {@var{fname} =} tmpnam ()
+## @deftypefnx {Function File} {@var{fname} =} tmpnam (@var{dir})
+## @deftypefnx {Function File} {@var{fname} =} tmpnam (@var{dir}, @var{prefix})
+## Return a unique temporary file name as a string.
+## 
+## If @var{prefix} is omitted, a value of @qcode{"oct-"} is used.
+## If @var{dir} is also omitted, the default directory for temporary files
+## (@code{P_tmpdir} is used.  If @var{dir} is provided, it must exist,
+## otherwise the default directory for temporary files is used.
+##
+## Programming Note: Because the named file is not opened by @code{tmpnam},
+## it is possible, though relatively unlikely, that it will not be available
+## by the time your program attempts to open it.  If this is a concern,
+## see @code{tmpfile}.  The functions @code{tmpnam} and @code{tmpnam} are
+## equivalent with the latter provided for @sc{matlab} compatibility.
+##
+## @strong{Caution}: @code{tmpnam} will be removed in a future version of
+## Octave.  Use the equivalent @code{tempname} in all new code.
+## @seealso{tempname, mkstemp, tempdir, P_tmpdir, tmpfile}
+## @end deftypefn
+
+function filename = tmpnam (varargin)
+
+  filename = tempname (varargin{:});
+
+endfunction
+
+
+## No tests needed for alias.
+%!assert (1)
+
--- a/scripts/miscellaneous/unpack.m
+++ b/scripts/miscellaneous/unpack.m
@@ -135,7 +135,7 @@
     if (! isempty (strfind (file, "://")))
       ## FIXME: The above code is not a perfect test for a URL
       urlfile = file;
-      tmpfile = [tmpnam() ext];
+      tmpfile = [tempname ext];
       [file, success, msg] = urlwrite (urlfile, tmpfile);
       if (! success)
         error ('unpack: could not fetch "%s": %s', urlfile, msg);
--- a/scripts/pkg/private/install.m
+++ b/scripts/pkg/private/install.m
@@ -64,7 +64,7 @@
 
       if (exist (tgz, "file"))
         ## Create a temporary directory.
-        tmpdir = tmpnam ();
+        tmpdir = tempname ();
         tmpdirs{end+1} = tmpdir;
         if (verbose)
           printf ("mkdir (%s)\n", tmpdir);
--- a/scripts/plot/appearance/legend.m
+++ b/scripts/plot/appearance/legend.m
@@ -1626,7 +1626,7 @@
 %!   position = get (h, "position");
 %!   plot (rand (3));
 %!   legend ();
-%!   filename = sprintf ("%s.eps", tmpnam ());
+%!   filename = sprintf ("%s.eps", tempname ());
 %!   print (filename);
 %!   unlink (filename);
 %!   assert (get (h, "position"), position);
--- a/scripts/plot/util/__gnuplot_drawnow__.m
+++ b/scripts/plot/util/__gnuplot_drawnow__.m
@@ -77,7 +77,7 @@
     term = gnuplot_default_term (plot_stream);
     if (strcmp (term, "dumb"))
       ## popen2 eats stdout of gnuplot, use temporary file instead
-      dumb_tmp_file = tmpnam ();
+      dumb_tmp_file = tempname ();
       enhanced = gnuplot_set_term (plot_stream(1), new_stream, h,
                                    term, dumb_tmp_file);
     else
--- a/scripts/plot/util/copyobj.m
+++ b/scripts/plot/util/copyobj.m
@@ -148,8 +148,8 @@
 %!   s1 = hdl2struct (h1);
 %!   h2 = struct2hdl (s1);
 %!   s2 = hdl2struct (h2);
-%!   png1 = strcat (tmpnam (), ".png");
-%!   png2 = strcat (tmpnam (), ".png");
+%!   png1 = [tempname() ".png"];
+%!   png2 = [tempname() ".png"];
 %!   unwind_protect
 %!     print (h1, png1);
 %!     [img1, map1, alpha1] = imread (png1);
--- a/scripts/plot/util/hgsave.m
+++ b/scripts/plot/util/hgsave.m
@@ -97,9 +97,9 @@
 %!   axes (ax(2));
 %!   text (4.5, 80, "Right Axis", ...
 %!         "color", [0 0.5 0], "horizontalalignment", "center");
-%!   ftmp = [tmpnam() ".ofig"];
-%!   png1 = [tmpnam() ".png"];
-%!   png2 = [tmpnam() ".png"];
+%!   ftmp = [tempname() ".ofig"];
+%!   png1 = [tempname() ".png"];
+%!   png2 = [tempname() ".png"];
 %!   unwind_protect
 %!     hgsave (h1, ftmp);
 %!     print (h1, png1);
--- a/scripts/plot/util/print.m
+++ b/scripts/plot/util/print.m
@@ -306,7 +306,7 @@
 
   if (opts.append_to_file)
     [~, ~, ext] = fileparts (opts.ghostscript.output);
-    opts.ghostscript.prepend = strcat (tmpnam (), ext);
+    opts.ghostscript.prepend = [tempname() ext];
     copyfile (opts.ghostscript.output, opts.ghostscript.prepend);
   endif
 
@@ -484,7 +484,7 @@
 
   if (nargin < 2 || strcmp (filein, "-") || isempty (filein))
     pipein = true;
-    filein = strcat (tmpnam (), ".eps");
+    filein = [tempname() ".eps"];
     if (dos_shell)
       cleanup = sprintf ("& del %s ", strrep (filein, '/', '\'));
     else
@@ -496,7 +496,7 @@
   endif
   if (strcmp (fileout, "-"))
     pipeout = true;
-    fileout = strcat (tmpnam (), ".eps");
+    fileout = [tempname() ".eps"];
     if (dos_shell)
       cleanup = horzcat (cleanup, sprintf ("& del %s ", strrep (fileout, '/', '\')));
     else
--- a/scripts/plot/util/private/__ghostscript__.m
+++ b/scripts/plot/util/private/__ghostscript__.m
@@ -112,7 +112,7 @@
       offsetfile = opts.offsetfile;
       cleanup_cmd = "";
     else
-      offsetfile = strcat (tmpnam (), ".ps");
+      offsetfile = [tempname() ".ps"];
       cleanup_cmd = sprintf ("rm %s", offsetfile);
     endif
     unwind_protect
--- a/scripts/plot/util/private/__gnuplot_get_var__.m
+++ b/scripts/plot/util/private/__gnuplot_get_var__.m
@@ -50,7 +50,7 @@
   endif
 
   if (use_mkfifo)
-    gpin_name = tmpnam ();
+    gpin_name = tempname ();
 
     ## Mode: 0600 == 6*8*8
     [err, msg] = mkfifo (gpin_name, 6*8*8);
--- a/scripts/plot/util/private/__gnuplot_ginput__.m
+++ b/scripts/plot/util/private/__gnuplot_ginput__.m
@@ -61,7 +61,7 @@
   endif
 
   if (use_mkfifo)
-    gpin_name = tmpnam ();
+    gpin_name = tempname ();
 
     ##Mode: 6*8*8 ==  0600
     [err, msg] = mkfifo (gpin_name, 6*8*8);
--- a/scripts/plot/util/private/__gnuplot_print__.m
+++ b/scripts/plot/util/private/__gnuplot_print__.m
@@ -54,7 +54,7 @@
         gp_opts = [gp_opts " level1"];
       endif
       if (opts.tight_flag || ! isempty (opts.preview))
-        tmp_file = strcat (tmpnam (), ".eps");
+        tmp_file = [tempname() ".eps"];
         eps_drawnow (opts, tmp_file, gp_opts);
         if (dos_shell)
           cleanup = [" & del " strrep(tmp_file, '/', '\')];
@@ -119,7 +119,7 @@
     case opts.ghostscript.device
       gp_opts = font_spec (opts, "devopt", "eps");
       opts.ghostscript.output = opts.name;
-      opts.ghostscript.source = strcat (tmpnam (), ".eps");
+      opts.ghostscript.source = [tempname() ".eps"];
       eps_drawnow (opts, opts.ghostscript.source, gp_opts);
       [cmd_gs, cmd_cleanup] = __ghostscript__ (opts.ghostscript);
       if (opts.send_to_printer || isempty (opts.name))
--- a/test/build-sparse-tests.sh
+++ b/test/build-sparse-tests.sh
@@ -914,7 +914,7 @@
 gen_save_tests() {
     cat >>$TESTS <<EOF
 %!test # save ascii
-%! savefile = tmpnam ();
+%! savefile = tempname ();
 %! as_save = as;
 %! save ("-text", savefile, "bf", "as_save", "af");
 %! clear as_save;
@@ -922,7 +922,7 @@
 %! unlink (savefile);
 %! assert (as_save, sparse (af));
 %!test # save binary
-%! savefile = tmpnam ();
+%! savefile = tempname ();
 %! as_save = as;
 %! save ("-binary", savefile, "bf", "as_save", "af");
 %! clear as_save;
@@ -930,7 +930,7 @@
 %! unlink (savefile);
 %! assert (as_save, sparse (af));
 %!testif HAVE_HDF5   # save hdf5
-%! savefile = tmpnam ();
+%! savefile = tempname ();
 %! as_save = as;
 %! save ("-hdf5", savefile, "bf", "as_save", "af");
 %! clear as_save;
@@ -941,7 +941,7 @@
 ## saving sparse matrices to MAT files when using 64-bit indexing since
 ## that is not implemented yet.
 %!test # save matlab
-%! savefile = tmpnam ();
+%! savefile = tempname ();
 %! as_save = as;
 %! save ("-mat", savefile, "bf", "as_save", "af");
 %! clear as_save;
--- a/test/io.tst
+++ b/test/io.tst
@@ -295,7 +295,7 @@
 
 %% Note use fprintf so output not sent to stdout
 %!test
-%! nm = tmpnam ();
+%! nm = tempname ();
 %! fid1 = fopen (nm,"w");
 %! x = fprintf (fid1, "%s: %d\n", "test", 1);
 %! fclose (fid1);
@@ -340,7 +340,7 @@
 %!     elseif (j == 4)
 %!       mode_list = {"W+"; "R+"; "A+"};
 %!     endif
-%!     nm = tmpnam ();
+%!     nm = tempname ();
 %!     for k = 1:3
 %!       mode = mode_list{k};
 %!       [id, err] = fopen (nm, mode, arch);
@@ -397,12 +397,12 @@
 %!error fclose (0)
 %!error <Invalid call to fclose> fclose (1, 2)
 
-%!assert (ischar (tmpnam ()))
+%!assert (ischar (tempname ()))
 
-%!warning tmpnam (1);
-%!warning tmpnam ("foo", 1);
+%!warning tempname (1);
+%!warning tempname ("foo", 1);
 
-%!error <Invalid call to tmpnam> tmpnam (1, 2, 3)
+%!error <Invalid call to tempname> tempname (1, 2, 3)
 
 %!test
 %! type_list = ["char"; "char*1"; "integer*1"; "int8";
@@ -413,7 +413,7 @@
 %! "real*8"; "int16"; "integer*2"; "int32"; "integer*4"];
 %!
 %! n = rows (type_list);
-%! nm = tmpnam ();
+%! nm = tempname ();
 %! id = fopen (nm, "wb");
 %! if (id > 0)
 %!   for i = 1:n
@@ -440,7 +440,7 @@
 
 %!test
 %! x = char (128:255)';
-%! nm = tmpnam ();
+%! nm = tempname ();
 %! id = fopen (nm, "wb");
 %! fwrite (id, x);
 %! fclose (id);
@@ -451,7 +451,7 @@
 %! assert (x, y);
 
 %!test
-%! nm = tmpnam ();
+%! nm = tempname ();
 %! id = fopen (nm, "wb");
 %! if (id > 0)
 %!   fprintf (id, "%d\n", 1:100);
--- a/test/prefer.tst
+++ b/test/prefer.tst
@@ -115,7 +115,7 @@
 %! sp = save_precision ();
 %! save_precision (1);
 %! x = pi;
-%! nm = tmpnam ();
+%! nm = tempname ();
 %! save ("-text", nm, "x");
 %! clear x;
 %! load (nm);
@@ -127,7 +127,7 @@
 %! sp = save_precision ();
 %! save_precision (5);
 %! x = pi;
-%! nm = tmpnam ();
+%! nm = tempname ();
 %! save ("-text", nm, "x");
 %! clear x;
 %! load (nm);
--- a/test/system.tst
+++ b/test/system.tst
@@ -58,8 +58,8 @@
 %!error <Invalid call to usleep> usleep (1, 2)
 
 %!test
-%! from = tmpnam ();
-%! to = tmpnam ();
+%! from = tempname ();
+%! to = tempname ();
 %! id = fopen (from, "wb");
 %! if (id > 0 && fclose (id) == 0)
 %!   [s, e] = stat (from);
@@ -79,7 +79,7 @@
 %!error <Invalid call to rename> rename ("foo", "bar", 1)
 
 %!test
-%! nm = tmpnam ();
+%! nm = tempname ();
 %! if ((id = fopen (nm, "wb")) > 0)
 %!   [s, err] = stat (nm);
 %!   if (! err && fclose (id) == 0 && unlink (nm) == 0)
@@ -100,7 +100,7 @@
 %!error <Invalid call to readdir> readdir ("foo", 1)
 
 %!test
-%! nm = tmpnam ();
+%! nm = tempname ();
 %! e1 = mkdir (nm);
 %! [s2, e2] = stat (nm);
 %! e3 = rmdir (nm);
@@ -121,14 +121,14 @@
 %! ## Test makes no sense on Windows systems
 %! if (isunix () || ismac ())
 %!   orig_umask = umask (0);
-%!   nm = tmpnam ();
+%!   nm = tempname ();
 %!   id = fopen (nm, "wb");
 %!   s1 = stat (nm);
 %!   fclose (id);
 %!   unlink (nm);
 %!
 %!   umask (777);
-%!   nm = tmpnam ();
+%!   nm = tempname ();
 %!   id = fopen (nm, "wb");
 %!   s2 = stat (nm);
 %!   fclose (id);
@@ -189,7 +189,7 @@
 %!   endif
 %!   assert (S_ISLNK (lstat ("/dev/core").mode));
 %! endif
-%! nm = tmpnam ();
+%! nm = tempname ();
 %! fid = fopen (nm, "wb");
 %! fclose (fid);
 %! r = [ S_ISREG(stat(nm).mode)