Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

When two or more users or a group of users have write permission to a directory, the potential for deception is far greater than it is for shared access to a few files. Consequently, temporary files in shared directories must be

  1. created unpredictable file names,
  2. created with unique and unpredictable file namesnames,
  3. opened only if the file doesn't already exist (atomic open),
  4. opened with exclusive access,
  5. opened with appropriate permissions, and
  6. removed before the program exits, andopened with appropriate permissions.

The following table lists common temporary file functions and their respective conformance to these criteria:

Conformance of File Functions to Criteria for Temporary Files

 

tmpnam
(C)

tmpnam_s
(ISO/IEC TR 24731-1Annex K)

tmpfile
(C)

tmpfile_s
(ISO/IEC TR 24731-1Annex K)

mktemp
(POSIX)

mkstemp
(POSIX)

Unpredictable Name

not portably

yes

not portably

yes

not portably

not portably

Unique Name

yes

yes

yes

yes

yes

yes

Atomic open

no

no

yes

yes

no

yes

Exclusive Access

possible

possible

no

if supported by OS

possible

if supported by OS

Appropriate Permissions

possible

possible

no

if supported by OS

possible

not portably

File Removed

no

no

yes*

yes*

no

no

...