Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

tempfile(1) [suse man page]

TEMPFILE(1)						      General Commands Manual						       TEMPFILE(1)

NAME
tempfile - create a temporary file in a safe manner SYNOPSIS
tempfile [-d DIR] [-p STRING] [-s STRING] [-m MODE] [-n FILE] [--directory=DIR] [--prefix=STRING] [--suffix=STRING] [--mode=MODE] [--name=FILE] [--help] [--version] DESCRIPTION
tempfile creates a temporary file in a safe manner. It uses tempnam(3) to choose the name and opens it with O_RDWR | O_CREAT | O_EXCL. The filename is printed on standard output. See tempnam(3) for the actual steps involved in directory selection. The directory in which to create the file might be searched for in this order (but refer to tempnam(3) for authoritative answers): a) In case the environment variable TMPDIR exists and contains the name of an appropriate directory, that is used. b) Otherwise, if the --directory argument is specified and appropriate, it is used. c) Otherwise, P_tmpdir (as defined in <stdio.h>) is used when appropriate. d) Finally an implementation-defined directory (/tmp) may be used. OPTIONS
-d, --directory DIR Place the file in DIR. -m, --mode MODE Open the file with MODE instead of 0600. -n, --name FILE Use FILE for the name instead of tempnam(3). The options -d, -p, and -s are ignored if this option is given. -p, --prefix STRING Use up to five letters of STRING to generate the name. -s, --suffix STRING Generate the file with STRING as the suffix. --help Print a usage message on standard output and exit successfully. --version Print version information on standard output and exit successfully. RETURN VALUES
An exit status of 0 means the temporary file was created successfully. Any other exit status indicates an error. BUGS
Exclusive creation is not guaranteed when creating files on NFS partitions. tempfile cannot make temporary directories. tempfile is dep- recated; you should use mktemp(1) instead. EXAMPLE
#!/bin/sh #[...] t=$(tempfile) || exit trap "rm -f -- '$t'" EXIT #[...] rm -f -- "$t" trap - EXIT exit SEE ALSO
tempnam(3), mktemp(1) Debian 27 Jun 2012 TEMPFILE(1)

Check Out this Related Man Page

TMPFILE(3)						   BSD Library Functions Manual 						TMPFILE(3)

NAME
tempnam, tmpfile, tmpnam -- temporary file routines LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <stdio.h> FILE * tmpfile(void); char * tmpnam(char *s); char * tempnam(const char *dir, const char *pfx); DESCRIPTION
The tmpfile() function returns a pointer to a stream associated with a file descriptor returned by the routine mkstemp(3). The created file is unlinked before 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 'w+'. If the environment variable TMPDIR is defined, the file is created in the specified directory. The default location, if TMPDIR is not set, is /tmp. The tmpnam() function returns a pointer to a file name, in the P_tmpdir directory, which did not reference an existing file at some indeter- minate point in the past. P_tmpdir is defined in the include file <stdio.h>. If the argument s 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, tmpnam() returns a pointer to the file name. The buffer referenced by s is expected to be at least L_tmpnam bytes in length. L_tmpnam is defined in the include file <stdio.h>. The tempnam() function is similar to tmpnam(), but provides the ability to specify the directory which will contain the temporary file and the file name prefix. The argument dir (if non-NULL), the directory P_tmpdir, the environment variable TMPDIR (if set), the directory /tmp and finally, the current directory, are tried, in the listed order, as directories in which to store the temporary file. The argument pfx, if non-NULL, is used to specify a file name prefix, which will be the first part of the created file name. The tempnam() function allocates memory in which to store the file name; the returned pointer may be used as a subsequent argument to free(3). RETURN VALUES
The tmpfile() function returns a pointer to an open file stream on success, and a NULL pointer on error. The tmpnam() and tempfile() functions return a pointer to a file name on success, and a NULL pointer on error. ENVIRONMENT
TMPDIR [tempnam() only] If set, the directory in which the temporary file is stored. TMPDIR is ignored for processes for which issetugid(2) is true. COMPATIBILITY
These interfaces are provided from System V and ANSI compatibility only. Most historic implementations of these functions provide only a limited number of possible temporary file names (usually 26) before file names will start being recycled. System V implementations of these functions (and of mktemp(3)) use the access(2) system call 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. The 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. ERRORS
The tmpfile() function may fail and set the global variable errno for any of the errors specified for the library functions fdopen(3) or mkstemp(3). The tmpnam() function may fail and set errno for any of the errors specified for the library function mktemp(3). The tempnam() function may fail and set errno for any of the errors specified for the library functions malloc(3) or mktemp(3). SECURITY CONSIDERATIONS
The tmpnam() and tempnam() functions are susceptible to a race condition occurring between the selection of the file name and the creation of the file, which allows malicious users to potentially overwrite arbitrary files in the system, depending on the level of privilege of the running program. Additionally, there is no means by which file permissions may be specified. It is strongly suggested that mkstemp(3) be used in place of these functions. (See the FSA.) LEGACY DESCRIPTION
In legacy mode, the order directories are tried by the tempnam() function is different; the environment variable TMPDIR (if defined) is used first. SEE ALSO
mkstemp(3), mktemp(3) STANDARDS
The tmpfile() and tmpnam() functions conform to ISO/IEC 9899:1990 (``ISO C90''). BSD
November 12, 2008 BSD
Man Page