📄 tmpnam.3
字号:
.\" Copyright (c) 1988, 1991, 1993.\" The Regents of the University of California. All rights reserved..\".\" This code is derived from software contributed to Berkeley by.\" the American National Standards Committee X3, on Information.\" Processing Systems..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)tmpnam.3 8.2 (Berkeley) 11/17/93.\".Dd November 17, 1993.Dt TMPFILE 3.Os.Sh NAME.Nm tempnam ,.Nm tmpfile ,.Nm tmpnam.Nd temporary file routines.Sh SYNOPSIS.Fd #include <stdio.h>.Ft FILE *.Fn tmpfile void.Ft char *.Fn tmpnam "char *str".Ft char *.Fn tempnam "const char *tmpdir" "const char *prefix".Sh DESCRIPTIONThe.Fn tmpfilefunctionreturns a pointer to a stream associated with a file descriptor returnedby the routine.Xr mkstemp 3 .The created file is unlinked before.Fn tmpfilereturns, causing the file to be automatically deleted when the lastreference to it is closed.The file is opened with the access value.Ql w+ ..PpThe.Fn tmpnamfunctionreturns a pointer to a file name, in the.Dv P_tmpdirdirectory, whichdid not reference an existing file at some indeterminate point in thepast..Dv P_tmpdiris defined in the include file.Aq Pa stdio.h .If the argument.Fa sis.Pf non- Dv NULL ,the file name is copied to the buffer it references.Otherwise, the file name is copied to a static buffer.In either case,.Fn tmpnamreturns a pointer to the file name..PpThe buffer referenced by .Fa sis expected to be at least.Dv L_tmpnambytes in length..Dv L_tmpnamis defined in the include file.Aq Pa stdio.h ..PpThe.Fn tempnamfunctionis similar to.Fn tmpnam ,but provides the ability to specify the directory which willcontain the temporary file and the file name prefix..PpThe environment variable.Ev TMPDIR(if set), the argument.Fa tmpdir(if.Pf non- Dv NULL ) ,the directory.Dv P_tmpdir ,and the directory.Pa /tmpare tried, in the listed order, as directories in which to store thetemporary file..PpThe argument.Fa prefix ,if.Pf non- Dv NULL ,is used to specify a file name prefix, which will be thefirst part of the created file name..Fn Tempnamallocates memory in which to store the file name; the returned pointermay be used as a subsequent argument to.Xr free 3 ..Sh RETURN VALUESThe.Fn tmpfilefunctionreturns a pointer to an open file stream on success, and a.Dv NULLpointeron error..PpThe.Fn tmpnamand.Fn tempfilefunctionsreturn a pointer to a file name on success, and a.Dv NULLpointeron error..Sh ERRORSThe.Fn tmpfilefunctionmay fail and set the global variable.Va errnofor any of the errors specified for the library functions.Xr fdopen 3or.Xr mkstemp 3 ..PpThe.Fn tmpnamfunctionmay fail and set.Va errnofor any of the errors specified for the library function.Xr mktemp 3 ..PpThe.Fn tempnamfunctionmay fail and set.Va errnofor any of the errors specified for the library functions.Xr malloc 3or.Xr mktemp 3 ..Sh SEE ALSO.Xr mkstemp 3 ,.Xr mktemp 3.Sh STANDARDSThe.Fn tmpfileand.Fn tmpnamfunctionsconform to.St -ansiC ..Sh BUGSThese interfaces are provided for System V and.Tn ANSIcompatibility only.The.Xr mkstemp 3interface is strongly preferred..PpThere are four important problems with these interfaces (as well aswith the historic.Xr mktemp 3interface).First, there is an obvious race between file name selection and filecreation and deletion.Second, most historic implementations provide only a limited numberof possible temporary file names (usually 26) before file names willstart being recycled.Third, the System V implementations of these functions (and of.Xr mktemp )use the.Xr access 2function to determine whether or not the temporary file may be created.This has obvious ramifications for setuid or setgid programs, complicatingthe portable use of these interfaces in such programs.Finally, there is no specification of the permissions with which thetemporary files are created..PpThis implementation does not have these flaws, but portable softwarecannot depend on that.In particular, the.Fn tmpfileinterface should not be used in software expected to be used on other systemsif there is any possibility that the user does not wish the temporary file tobe publicly readable and writable.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -