Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/mkstemp.html
2024-02-19 00:21:47 -05:00

140 lines
4.6 KiB
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 The Open Group, All Rights Reserved -->
<title>mkstemp</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="mkstemp"></a> <a name="tag_03_374"></a><!-- mkstemp -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_374_01"></a>NAME</h4>
<blockquote>mkstemp - make a unique filename</blockquote>
<h4><a name="tag_03_374_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 &lt;<a href="../basedefs/stdlib.h.html">stdlib.h</a>&gt;<br>
<br>
int mkstemp(char *</tt><i>template</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_374_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>mkstemp</i>() function shall replace the contents of the string pointed to by <i>template</i> by a unique filename, and
return a file descriptor for the file open for reading and writing. The function thus prevents any possible race condition between
testing whether the file exists and opening it for use. The string in <i>template</i> should look like a filename with six trailing
<tt>'X'</tt> s; <i>mkstemp</i>() replaces each <tt>'X'</tt> with a character from the portable filename character set. The
characters are chosen such that the resulting name does not duplicate the name of an existing file at the time of a call to
<i>mkstemp</i>().</p>
</blockquote>
<h4><a name="tag_03_374_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>mkstemp</i>() shall return an open file descriptor. Otherwise, -1 shall be returned if no
suitable file could be created.</p>
</blockquote>
<h4><a name="tag_03_374_05"></a>ERRORS</h4>
<blockquote>
<p>No errors are defined.</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_374_06"></a>EXAMPLES</h4>
<blockquote>
<h5><a name="tag_03_374_06_01"></a>Generating a Filename</h5>
<p>The following example creates a file with a 10-character name beginning with the characters <tt>"file"</tt> and opens the file
for reading and writing. The value returned as the value of <i>fd</i> is a file descriptor that identifies the file.</p>
<pre>
<tt>#include &lt;stdlib.h&gt;
...
char template[] = "/tmp/fileXXXXXX";
int fd;
<br>
fd = mkstemp(template);
</tt>
</pre>
</blockquote>
<h4><a name="tag_03_374_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>It is possible to run out of letters.</p>
<p>The <i>mkstemp</i>() function need not check to determine whether the filename part of <i>template</i> exceeds the maximum
allowable filename length.</p>
</blockquote>
<h4><a name="tag_03_374_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_374_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_374_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="getpid.html"><i>getpid</i>()</a> , <a href="open.html"><i>open</i>()</a> , <a href="tmpfile.html"><i>tmpfile</i>()</a>
, <a href="tmpnam.html"><i>tmpnam</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/stdlib.h.html"><i>&lt;stdlib.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_374_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 4, Version 2.</p>
</blockquote>
<h4><a name="tag_03_374_12"></a>Issue 5</h4>
<blockquote>
<p>Moved from X/OPEN UNIX extension to BASE.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; 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>