All Manuals > LispWorks User Guide and Reference Manual > 38 The HCL Package

NextPrevUpTopContentsIndex

create-temp-file

open-temp-file

Functions
Summary

Creates a "temp file" and returns a pathname or a stream to it.

Package

hcl

Signature

create-temp-file &key file-type directory prefix => pathname

Signature

open-temp-file &key file-type element-type directory prefix delete-when-close external-format => stream

Arguments

file-type

A string or nil.

element-type

A type specifier.

directory

A pathname designator.

prefix

A string or nil.

delete-when-close

A generalized boolean.

external-format

An external file format designator.

Values

pathname

A pathname.

stream

An I/O stream.

Description

The function open-temp-file opens a "temp file". This is a new file in the "temp directory" which is guaranteed to be new. Its name contains a random element. The permissions of the file are read-write for the user only.

file-type is the file type of the name. The default value of file-type is "tmp".

directory, if supplied, is the directory to create the file in. It defaults to the default temp directory, which is what get-temp-directory returns, which defaults to what the Operating System uses as the temp directory.

prefix is used as the first part of the file name. The default prefix is "lwtemp_machinename_pid". More characters are appended to make the name unique and random.

If delete-when-close is non-nil, when the stream stream that is returned is closed, the system tries to delete the file quietly. That is, it tries to avoid giving an error if it fails.

element-type and external-format are interpreted the same way as in open.

The stream that is returned is an I/O stream.

The function create-temp-file creates a new temp file and returns the pathname for it. create-temp-file behaves exactly like open-temp-file, as described above, except that it returns a pathname rather than a stream to the new file.

Notes
  1. pathname can be called to find the pathname that was used in open-temp-file. The file can be guaranteed to be new only if the temp directory is configured correctly.
  2. The default "temp directory" can be found by using get-temp-directory.
  3. When delete-when-close is non-nil, it tries to delete the file when the stream is closed, but that does not necessarily succeed. On Microsoft Windows it certainly fails when the file is still opened (for example, by another stream in the same process or another process)
See also

get-temp-directory
open
set-temp-directory


LispWorks User Guide and Reference Manual - 20 Sep 2017

NextPrevUpTopContentsIndex