tmpnam.3s
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 3S 代码 · 共 131 行
3S
131 行
.\" SCCSID: @(#)tmpnam.3s 8.1 9/11/90.TH tmpnam 3s .SH Nametmpnam, tempnam \- create a name for a temporary file.SH Syntax.B #include <stdio.h>.PP.B char \(**tmpnam (s).br.B char \(**s;.PP.B char \(**tempnam (dir, pfx).br.B char \(**dir, \(**pfx;.SH Description.NXR "tmpnam subroutine".NXR "tempnam subroutine".NXA "tmpnam subroutine" "tmpfile subroutine".NXA "tmpnam subroutine" "mktemp subroutine".NXR "temporary file" "naming"These functions generate file names that can safely be used fora temporary file..PPThe.PN tmpnamsubroutinealways generates a file name using the path-name defined as.PN P_tmpdirin the <stdio.h> header file.If.I s\^is NULL,.PN tmpnamleaves its result in an internal static area and returns a pointerto that area.The next call to.PN tmpnamwill destroy the contents of the area.If.I s\^is not NULL,it is assumed to be the address of an array of at least.PN L_tmpnambytes, where.PN L_tmpnamis a constant defined in <stdio.h>;.PN tmpnamplaces its result in that array and returns.IR s ..PPThe.PN tempnamsubroutine allows the user to control the choice of a directory.The argument.I dir\^points to the path-name of the directory in whichthe file is to be created.If.I dir\^is NULL or points to a string which is not a path-namefor an appropriate directory, the path-name defined as.PN P_tmpdir\^in the <stdio.h> header file is used.If that path-name is not accessible, .PN /tmpwill be used as a last resort.This entire sequence can be up-staged byproviding an environment variable TMPDIRin the user's environment, whose value is a path-name for thedesired temporary-file directory..PPMany applications prefer their temporary files to have certainfavorite initial letter sequences in their names.Use the.B pfx\^argument for this. This argument may be NULLor point to a stringof up to five characters to be used as the first few characters of thetemporary-file name..PPThe.PN tempnamsubroutine uses .MS malloc 3to get space for the constructed file name,and returns a pointer to this area.Thus, any pointer value returned from.PN tempnammay serve as an argument to.I free.For further information, see .MS malloc 3 .If.PN tempnamcannot return the expected result for any reason, that is.PN mallocfailed, or none of the above mentioned attempts to findan appropriate directory was successful, aNULL pointer will be returned..NT "Notes"The.PN tmpnamand.PN tempnamroutines generate a different filename each time they are called..spFiles created using these functions and either.PN fopenor.PN creatare temporary only in the sense that they reside in a directoryintended for temporary use, and their names are unique.It is the user's responsibility to use .MS unlink 2to remove the file when its use is ended..NE.SH RestrictionsIf called more than 17,576 times in a single process,these functions will start recycling previously used names..PPBetween the time a file name is created and the file is opened, itis possible for some other process to create a file with the same name.This can never happen if that other process is usingthese functions or.PN mktemp ,and the file names are chosen so as to render duplication by othermeans unlikely..SH See Alsocreat(2), unlink(2), fopen(3s), malloc(3), mktemp(3), tmpfile(3s)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?