.\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl) .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .TH TEMPNAM 3 "14 June 1999" "" "Linux Programmer's Manual" .SH NAME tempnam \- create a name for a temporary file .SH SYNOPSIS .nf .B #include .sp .BI "char *tempnam(const char *" dir ", const char *" pfx ); .fi .SH DESCRIPTION The .B tempnam() function returns a pointer to a string that is a valid filename, and such that a file with this name did not exist when .B tempnam() checked. The filename suffix of the pathname generated will start with .I pfx in case .I pfx is a non-NULL string of at most five bytes. The directory prefix part of the pathname generated is required to be `appropriate' (often that at least implies writable). Attempts to find an appropriate directory go through the following steps: (i) In case the environment variable TMPDIR exists and contains the name of an appropriate directory, that is used. (ii) Otherwise, if the .I dir argument is non-NULL and appropriate, it is used. (iii) Otherwise, P_tmpdir (as defined in .IR ) is used when appropriate. (iv) Finally an implementation-defined directory may be used. .SH "RETURN VALUE" The .B tempnam() function returns a pointer to a unique temporary filename, or NULL if a unique name cannot be generated. .SH ERRORS .TP .B ENOMEM Allocation of storage failed. .LP .SH NOTES SUSv2 does not mention the use of TMPDIR; glibc will use it only when the program is not suid. SVID2 specifies that the directory used under (iv) is .IR /tmp . SVID2 specifies that the string returned by .B tempnam() was allocated using .BR malloc (3) and hence can be freed by .BR free (3). .LP The .B tempnam() function generates a different string each time it is called, up to TMP_MAX (defined in .IR ) times. If it is called more than TMP_MAX times, the behaviour is implementation defined. .LP In case the .I pfx argument has length larger than five, glibc will use the first five bytes. Upon failure to find a unique name, glibc will return EEXIST. .SH BUGS The precise meaning of `appropriate' is undefined; it is unspecified how accessibility of a directory is determined. Never use this function. Use .BR mkstemp (3) instead. .SH "CONFORMING TO" SVID 2, BSD 4.3 .SH "SEE ALSO" .BR mktemp (3), .BR mkstemp (3), .BR tmpfile (3), .BR tmpnam (3)