<html lang="en"> <head> <title>Temporary Files - Untitled</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="Untitled"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions" title="C-Style I/O Functions"> <link rel="prev" href="Binary-I_002fO.html#Binary-I_002fO" title="Binary I/O"> <link rel="next" href="EOF-and-Errors.html#EOF-and-Errors" title="EOF and Errors"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="Temporary-Files"></a> <p> Next: <a rel="next" accesskey="n" href="EOF-and-Errors.html#EOF-and-Errors">EOF and Errors</a>, Previous: <a rel="previous" accesskey="p" href="Binary-I_002fO.html#Binary-I_002fO">Binary I/O</a>, Up: <a rel="up" accesskey="u" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions">C-Style I/O Functions</a> <hr> </div> <h4 class="subsection">14.2.17 Temporary Files</h4> <p>Sometimes one needs to write data to a file that is only temporary. This is most commonly used when an external program launched from within Octave needs to access data. When Octave exits all temporary files will be deleted, so this step need not be executed manually. <!-- file-io.cc --> <p><a name="doc_002dmkstemp"></a> <div class="defun"> — Built-in Function: [<var>fid</var>, <var>name</var>, <var>msg</var>] = <b>mkstemp</b> (<var>template, delete</var>)<var><a name="index-mkstemp-802"></a></var><br> <blockquote><p>Return the file ID corresponding to a new temporary file with a unique name created from <var>template</var>. The last six characters of <var>template</var> must be <code>XXXXXX</code> and these are replaced with a string that makes the filename unique. The file is then created with mode read/write and permissions that are system dependent (on GNU/Linux systems, the permissions will be 0600 for versions of glibc 2.0.7 and later). The file is opened with the <code>O_EXCL</code><!-- /@w --> flag. <p>If the optional argument <var>delete</var> is supplied and is true, the file will be deleted automatically when Octave exits, or when the function <code>purge_tmp_files</code> is called. <p>If successful, <var>fid</var> is a valid file ID, <var>name</var> is the name of the file, and <var>msg</var> is an empty string. Otherwise, <var>fid</var> is -1, <var>name</var> is empty, and <var>msg</var> contains a system-dependent error message. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dtmpfile.html#doc_002dtmpfile">tmpfile</a>, <a href="doc_002dtmpnam.html#doc_002dtmpnam">tmpnam</a>, <a href="doc_002dP_005ftmpdir.html#doc_002dP_005ftmpdir">P_tmpdir</a>. </p></blockquote></div> <!-- file-io.cc --> <p><a name="doc_002dtmpfile"></a> <div class="defun"> — Built-in Function: [<var>fid</var>, <var>msg</var>] = <b>tmpfile</b> ()<var><a name="index-tmpfile-803"></a></var><br> <blockquote><p>Return the file ID corresponding to a new temporary file with a unique name. The file is opened in binary read/write (<code>"w+b"</code>) mode. The file will be deleted automatically when it is closed or when Octave exits. <p>If successful, <var>fid</var> is a valid file ID and <var>msg</var> is an empty string. Otherwise, <var>fid</var> is -1 and <var>msg</var> contains a system-dependent error message. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dtmpnam.html#doc_002dtmpnam">tmpnam</a>, <a href="doc_002dmkstemp.html#doc_002dmkstemp">mkstemp</a>, <a href="doc_002dP_005ftmpdir.html#doc_002dP_005ftmpdir">P_tmpdir</a>. </p></blockquote></div> <!-- file-io.cc --> <p><a name="doc_002dtmpnam"></a> <div class="defun"> — Built-in Function: <b>tmpnam</b> (<var>dir, prefix</var>)<var><a name="index-tmpnam-804"></a></var><br> <blockquote><p>Return a unique temporary file name as a string. <p>If <var>prefix</var> is omitted, a value of <code>"oct-"</code> is used. If <var>dir</var> is also omitted, the default directory for temporary files is used. If <var>dir</var> is provided, it must exist, otherwise the default directory for temporary files is used. Since the named file is not opened, by <code>tmpnam</code>, it is possible (though relatively unlikely) that it will not be available by the time your program attempts to open it. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dtmpfile.html#doc_002dtmpfile">tmpfile</a>, <a href="doc_002dmkstemp.html#doc_002dmkstemp">mkstemp</a>, <a href="doc_002dP_005ftmpdir.html#doc_002dP_005ftmpdir">P_tmpdir</a>. </p></blockquote></div> </body></html>