mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-09-11 14:54:54 +00:00
211 lines
5.9 KiB
Groff
211 lines
5.9 KiB
Groff
.\" Copyright (c) 1988, 1991 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.
|
|
.\"
|
|
.\" from: @(#)tmpnam.3 5.14 (Berkeley) 6/29/91
|
|
.\" tmpnam.3,v 1.2 1993/08/01 07:44:48 mycroft Exp
|
|
.\"
|
|
.TH TMPFILE 3 "26 November 1995" GNO "Library Routines"
|
|
.SH NAME
|
|
.BR tempnam ,
|
|
.BR tmpfile ,
|
|
.BR tmpnam
|
|
\- temporary file routines
|
|
.SH SYNOPSIS
|
|
#include <stdio.h>
|
|
.sp 1
|
|
FILE *
|
|
\fBtmpfile\fR(void);
|
|
.br
|
|
char *
|
|
\fBtmpnam\fR(char *\fIstr\fR);
|
|
.br
|
|
char *
|
|
\fBtempnam\fR(const char *\fItmpdir\fR, const char *\fIprefix\fR);
|
|
.SH DESCRIPTION
|
|
The
|
|
.B tmpfile
|
|
function
|
|
returns a pointer to a stream associated with a file descriptor returned
|
|
by the routine
|
|
.BR mkstemp (3).
|
|
The created file is unlinked before
|
|
.B tmpfile
|
|
returns, causing the file to be automatically deleted when the last
|
|
reference to it is closed.
|
|
The file is opened with the access value
|
|
.BR w+b .
|
|
.LP
|
|
The
|
|
.B tmpnam
|
|
function
|
|
returns a pointer to a file name, in the
|
|
.B P_tmpdir
|
|
directory, which
|
|
did not reference an existing file at some indeterminate point in the
|
|
past.
|
|
.B P_tmpdir
|
|
is defined in the include file
|
|
.BR stdio.h .
|
|
If the argument
|
|
.I str
|
|
is non-NULL,
|
|
the file name is copied to the buffer it references.
|
|
Otherwise, the file name is copied to a static buffer.
|
|
In either case,
|
|
.B tmpnam
|
|
returns a pointer to the file name.
|
|
.LP
|
|
The buffer referenced by
|
|
.I str
|
|
is expected to be at least
|
|
.B L_tmpnam
|
|
bytes in length.
|
|
.B L_tmpnam
|
|
is defined in the include file
|
|
.BR stdio.h .
|
|
.LP
|
|
The
|
|
.B tempnam
|
|
function
|
|
is similar to
|
|
.BR tmpnam ,
|
|
but provides the ability to specify the directory which will
|
|
contain the temporary file and the file name prefix.
|
|
.LP
|
|
The environment variable
|
|
.B TMPDIR
|
|
(if set), the argument
|
|
.I dir
|
|
(if non-NULL), the directory
|
|
.BR P_tmpdir ,
|
|
and the directory
|
|
.B /tmp
|
|
are tried, in the listed order, as directories in which to store the
|
|
temporary file.
|
|
.LP
|
|
The argument
|
|
.IR prefix ,
|
|
if non-NULL,
|
|
is used to specify a file name prefix, which will be the
|
|
first part of the created file name.
|
|
.B Tempnam
|
|
allocates memory in which to store the file name; the returned pointer
|
|
may be used as a subsequent argument to
|
|
.BR free (3).
|
|
.SH RETURN VALUES
|
|
The
|
|
.B tmpfile
|
|
function
|
|
returns a pointer to an open file stream on success, and a
|
|
NULL pointer on error.
|
|
.LP
|
|
The
|
|
.B tmpnam
|
|
and
|
|
.B tempfile
|
|
functions
|
|
return a pointer to a file name on success, and a
|
|
NULL pointer on error.
|
|
.SH ERRORS
|
|
The
|
|
.B tmpfile
|
|
function
|
|
may fail and set the global variable
|
|
.B errno
|
|
for any of the errors specified for the library functions
|
|
.BR fdopen (3)
|
|
or
|
|
.BR mkstemp (3).
|
|
.LP
|
|
The
|
|
.B tmpnam
|
|
function
|
|
may fail and set
|
|
.B errno
|
|
for any of the errors specified for the library function
|
|
.BR mktemp (3).
|
|
.LP
|
|
The
|
|
.B tempnam
|
|
function
|
|
may fail and set
|
|
.B errno
|
|
for any of the errors specified for the library functions
|
|
.BR malloc (3)
|
|
or
|
|
.B mktemp (3).
|
|
.SH SEE ALSO
|
|
.BR mkstemp (3),
|
|
.BR mktemp (3)
|
|
.SH STANDARDS
|
|
The
|
|
.B tmpfile
|
|
and
|
|
.B tmpnam
|
|
functions conform to ANSI C.
|
|
.SH BUGS
|
|
These interfaces are provided for System V and ANSI
|
|
compatibility only.
|
|
The
|
|
.BR mkstemp (3)
|
|
interface is strongly preferred.
|
|
.LP
|
|
There are four important problems with these interfaces (as well as
|
|
with the historic
|
|
.BR mktemp (3)
|
|
interface).
|
|
First, there is an obvious race between file name selection and file
|
|
creation and deletion.
|
|
Second, most historic implementations provide only a limited number
|
|
of possible temporary file names (usually 26) before file names will
|
|
start being recycled.
|
|
Third, the System V implementations of these functions (and of
|
|
.BR mktemp )
|
|
use the
|
|
.BR access (2)
|
|
function to determine whether or not the temporary file may be created.
|
|
This has obvious ramifications for setuid or setgid programs, complicating
|
|
the portable use of these interfaces in such programs.
|
|
Finally, there is no specification of the permissions with which the
|
|
temporary files are created.
|
|
.LP
|
|
This implementation does not have these flaws, but portable software
|
|
cannot depend on that.
|
|
In particular, the
|
|
.BR tmpfile
|
|
interface should not be used in software expected to be used on other systems
|
|
if there is any possibility that the user does not wish the temporary file to
|
|
be publicly readable and writable.
|