271 lines
5.6 KiB
HTML
271 lines
5.6 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of TMPNAM</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>TMPNAM</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
tmpnam, tmpnam_r - create a name for a temporary file
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>></B>
|
|
|
|
<B>char *tmpnam(char *</B><I>s</I><B>);</B>
|
|
<B>char *tmpnam_r(char *</B><I>s</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
<B>tmpnam_r</B>()
|
|
|
|
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
<DL COMPACT>
|
|
<DT id="2">Since glibc 2.19:<DD>
|
|
_DEFAULT_SOURCE
|
|
<DT id="3">Up to and including glibc 2.19:<DD>
|
|
_BSD_SOURCE || _SVID_SOURCE
|
|
</DL>
|
|
</DL>
|
|
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>Note:</B>
|
|
|
|
avoid using these functions; use
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mkstemp">mkstemp</A></B>(3)
|
|
|
|
or
|
|
<B><A HREF="/cgi-bin/man/man2html?3+tmpfile">tmpfile</A></B>(3)
|
|
|
|
instead.
|
|
<P>
|
|
|
|
The
|
|
<B>tmpnam</B>()
|
|
|
|
function returns a pointer to a string that is a valid filename,
|
|
and such that a file with this name did not exist at some point
|
|
in time, so that naive programmers may think it
|
|
a suitable name for a temporary file.
|
|
If the argument
|
|
<I>s</I>
|
|
|
|
is NULL, this name is generated in an internal static buffer
|
|
and may be overwritten by the next call to
|
|
<B>tmpnam</B>().
|
|
|
|
If
|
|
<I>s</I>
|
|
|
|
is not NULL, the name is copied to the character array (of length
|
|
at least
|
|
<I>L_tmpnam</I>)
|
|
|
|
pointed to by
|
|
<I>s</I>
|
|
|
|
and the value
|
|
<I>s</I>
|
|
|
|
is returned in case of success.
|
|
<P>
|
|
|
|
The created pathname has a directory prefix
|
|
<I>P_tmpdir</I>.
|
|
|
|
(Both
|
|
<I>L_tmpnam</I>
|
|
|
|
and
|
|
<I>P_tmpdir</I>
|
|
|
|
are defined in
|
|
<I><<A HREF="file:///usr/include/stdio.h">stdio.h</A>></I>,
|
|
|
|
just like the
|
|
<B>TMP_MAX</B>
|
|
|
|
mentioned below.)
|
|
<P>
|
|
|
|
The
|
|
<B>tmpnam_r</B>()
|
|
|
|
function performs the same task as
|
|
<B>tmpnam</B>(),
|
|
|
|
but returns NULL (to indicate an error) if
|
|
<I>s</I>
|
|
|
|
is NULL.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
These functions return a pointer to a unique temporary
|
|
filename, or NULL if a unique name cannot be generated.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
No errors are defined.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>tmpnam</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Unsafe race:tmpnam/!s<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>tmpnam_r</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
<B>tmpnam</B>():
|
|
|
|
SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
|
|
POSIX.1-2008 marks
|
|
<B>tmpnam</B>()
|
|
|
|
as obsolete.
|
|
<P>
|
|
|
|
<B>tmpnam_r</B>()
|
|
|
|
is a nonstandard extension that is also available
|
|
|
|
on a few other systems.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The
|
|
<B>tmpnam</B>()
|
|
|
|
function generates a different string each time it is called,
|
|
up to
|
|
<B>TMP_MAX</B>
|
|
|
|
times.
|
|
If it is called more than
|
|
<B>TMP_MAX</B>
|
|
|
|
times,
|
|
the behavior is implementation defined.
|
|
<P>
|
|
|
|
Although these functions generate names that are difficult to guess,
|
|
it is nevertheless possible that between the time that
|
|
the pathname is returned and the time that the program opens it,
|
|
another program might create that pathname using
|
|
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2),
|
|
|
|
or create it as a symbolic link.
|
|
This can lead to security holes.
|
|
To avoid such possibilities, use the
|
|
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2)
|
|
|
|
<B>O_EXCL</B>
|
|
|
|
flag to open the pathname.
|
|
Or better yet, use
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mkstemp">mkstemp</A></B>(3)
|
|
|
|
or
|
|
<B><A HREF="/cgi-bin/man/man2html?3+tmpfile">tmpfile</A></B>(3).
|
|
|
|
<P>
|
|
|
|
Portable applications that use threads cannot call
|
|
<B>tmpnam</B>()
|
|
|
|
with a NULL argument if either
|
|
<B>_POSIX_THREADS</B>
|
|
|
|
or
|
|
<B>_POSIX_THREAD_SAFE_FUNCTIONS</B>
|
|
|
|
is defined.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
Never use these functions.
|
|
Use
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mkstemp">mkstemp</A></B>(3)
|
|
|
|
or
|
|
<B><A HREF="/cgi-bin/man/man2html?3+tmpfile">tmpfile</A></B>(3)
|
|
|
|
instead.
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mkstemp">mkstemp</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mktemp">mktemp</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+tempnam">tempnam</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+tmpfile">tmpfile</A></B>(3)
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="4"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="7"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="8"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="9"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="10"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="11"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DT id="12"><A HREF="#lbAJ">BUGS</A><DD>
|
|
<DT id="13"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="14"><A HREF="#lbAL">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:58 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|