📄 tempnam.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>tempnam</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="tempnam"></a> <a name="tag_03_772"></a><!-- tempnam --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_772_01"></a>NAME</h4><blockquote>tempnam - create a name for a temporary file</blockquote><h4><a name="tag_03_772_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/stdio.h.html">stdio.h</a>><br><br> char *tempnam(const char *</tt><i>dir</i><tt>, const char *</tt><i>pfx</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_772_03"></a>DESCRIPTION</h4><blockquote><p>The <i>tempnam</i>() function shall generate a pathname that may be used for a temporary file.</p><p>The <i>tempnam</i>() function allows the user to control the choice of a directory. The <i>dir</i> argument points to the nameof the directory in which the file is to be created. If <i>dir</i> is a null pointer or points to a string which is not a name foran appropriate directory, the path prefix defined as P_tmpdir in the <a href="../basedefs/stdio.h.html"><i><stdio.h></i></a>header shall be used. If that directory is not accessible, an implementation-defined directory may be used.</p><p>Many applications prefer their temporary files to have certain initial letter sequences in their names. The <i>pfx</i> argumentshould be used for this. This argument may be a null pointer or point to a string of up to five bytes to be used as the beginningof the filename.</p><p>Some implementations of <i>tempnam</i>() may use <a href="../functions/tmpnam.html"><i>tmpnam</i>()</a> internally. On suchimplementations, if called more than {TMP_MAX} times in a single process, the behavior is implementation-defined.</p></blockquote><h4><a name="tag_03_772_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>tempnam</i>() shall allocate space for a string, put the generated pathname in that space, andreturn a pointer to it. The pointer shall be suitable for use in a subsequent call to <a href="../functions/free.html"><i>free</i>()</a>. Otherwise, it shall return a null pointer and set <i>errno</i> to indicate theerror.</p></blockquote><h4><a name="tag_03_772_05"></a>ERRORS</h4><blockquote><p>The <i>tempnam</i>() function shall fail if:</p><dl compact><dt>[ENOMEM]</dt><dd>Insufficient storage space is available.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_772_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_772_06_01"></a>Generating a Pathname</h5><p>The following example generates a pathname for a temporary file in directory <b>/tmp</b>, with the prefix <i>file</i>. After thefilename has been created, the call to <a href="../functions/free.html"><i>free</i>()</a> deallocates the space used to store thefilename.</p><pre><tt>#include <stdio.h>#include <stdlib.h>...char *directory = "/tmp";char *fileprefix = "file";char *file;<br>file = tempnam(directory, fileprefix);free(file);</tt></pre></blockquote><h4><a name="tag_03_772_07"></a>APPLICATION USAGE</h4><blockquote><p>This function only creates pathnames. It is the application's responsibility to create and remove the files. Between the time apathname is created and the file is opened, it is possible for some other process to create a file with the same name. Applicationsmay find <a href="../functions/tmpfile.html"><i>tmpfile</i>()</a> more useful.</p></blockquote><h4><a name="tag_03_772_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_772_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_772_10"></a>SEE ALSO</h4><blockquote><p><a href="fopen.html"><i>fopen</i>()</a> , <a href="free.html"><i>free</i>()</a> , <a href="open.html"><i>open</i>()</a> , <ahref="tmpfile.html"><i>tmpfile</i>()</a> , <a href="tmpnam.html"><i>tmpnam</i>()</a> , <a href="unlink.html"><i>unlink</i>()</a> ,the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/stdio.h.html"><i><stdio.h></i></a></p></blockquote><h4><a name="tag_03_772_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 1. Derived from Issue 1 of the SVID.</p></blockquote><h4><a name="tag_03_772_12"></a>Issue 5</h4><blockquote><p>The last paragraph of the DESCRIPTION was included as an APPLICATION USAGE note in previous issues.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -