Manual Pages for UNIX Darwin command on man tempnam
MyWebUniversity

Manual Pages for UNIX Darwin command on man tempnam

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

NAME

tteemmppnnaamm, ttmmppffiillee, ttmmppnnaamm - temporary file routines

LLIIBBRRAARRYY

Standard C Library (libc, -lc)

SYNOPSIS

##iinncclluuddee <>

FILE * ttmmppffiillee(void); char * ttmmppnnaamm(char *str); char * tteemmppnnaamm(const char *tmpdir, const char *prefix);

DESCRIPTION

The ttmmppffiillee() function returns a pointer to a stream associated with a file descriptor returned by the routine mkstemp(3). The created file is unlinked before ttmmppffiillee() 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+'. The file is created in the directory determined by the environment variable TMPDIR if set. The default location if TMPDIR is not set is /tmp. The ttmmppnnaamm() function returns a pointer to a file name, in the Ptmpdir directory, which did not reference an existing file at some indeterminate point in the past. Ptmpdir is defined in the include file .

If the argument 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, ttmmppnnaamm() returns a pointer to the file name. The buffer referenced by str is expected to be at least Ltmpnam bytes in length. Ltmpnam is defined in the include file . The tteemmppnnaamm() function is similar to ttmmppnnaamm(), but provides the ability to specify the directory which will contain the temporary file and the file name prefix. The environment variable TMPDIR (if set), the argument tmpdir (if

non-NULL), the directory Ptmpdir, and the directory /tmp are tried, in

the listed order, as directories in which to store the temporary file.

The argument prefix, if non-NULL, is used to specify a file name prefix,

which will be the first part of the created file name. The tteemmppnnaamm() 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 ttmmppffiillee() function returns a pointer to an open file stream on suc-

cess, and a NULL pointer on error. The ttmmppnnaamm() and tteemmppffiillee() functions return a pointer to a file name on success, and a NULL pointer on error. EERRRROORRSS The ttmmppffiillee() 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 ttmmppnnaamm() function may fail and set errno for any of the errors speci-

fied for the library function mktemp(3).

The tteemmppnnaamm() function may fail and set errno for any of the errors spec-

ified for the library functions malloc(3) or mktemp(3). SSEECCUURRIITTYY CCOONNSSIIDDEERRAATTIIOONNSS The ttmmppnnaamm() and tteemmppnnaamm() 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.) CCOOMMPPAATTIIBBIILLIITTYY 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 ttmmppffiillee() 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.

SEE ALSO

mkstemp(3), mktemp(3) STANDARDS The ttmmppffiillee() and ttmmppnnaamm() functions conform to ISO/IEC 9899:1990 (``ISO C90''). BSD November 17, 1993 BSD




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™