blob: b8f1e69f4268291ec63c559184c7dc2477a14339 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
\section{\module{tempfile} ---
Generate temporary file names}
\declaremodule{standard}{tempfile}
\modulesynopsis{Generate temporary file names.}
\indexii{temporary}{file name}
\indexii{temporary}{file}
This module generates temporary file names. It is not \UNIX{} specific,
but it may require some help on non-\UNIX{} systems.
Note: the modules does not create temporary files, nor does it
automatically remove them when the current process exits or dies.
The module defines a single user-callable function:
\begin{funcdesc}{mktemp}{}
Return a unique temporary filename. This is an absolute pathname of a
file that does not exist at the time the call is made. No two calls
will return the same filename.
\end{funcdesc}
The module uses two global variables that tell it how to construct a
temporary name. The caller may assign values to them; by default they
are initialized at the first call to \function{mktemp()}.
\begin{datadesc}{tempdir}
When set to a value other than \code{None}, this variable defines the
directory in which filenames returned by \function{mktemp()} reside.
The default is taken from the environment variable \envvar{TMPDIR}; if
this is not set, either \file{/usr/tmp} is used (on \UNIX{}), or the
current working directory (all other systems). No check is made to
see whether its value is valid.
\end{datadesc}
\begin{datadesc}{template}
When set to a value other than \code{None}, this variable defines the
prefix of the final component of the filenames returned by
\function{mktemp()}. A string of decimal digits is added to generate
unique filenames. The default is either \file{@\var{pid}.} where
\var{pid} is the current process ID (on \UNIX{}), or \file{tmp} (all
other systems).
\end{datadesc}
\strong{Warning:} if a \UNIX{} process uses \code{mktemp()}, then
calls \function{fork()} and both parent and child continue to use
\function{mktemp()}, the processes will generate conflicting temporary
names. To resolve this, the child process should assign \code{None} to
\code{template}, to force recomputing the default on the next call
to \function{mktemp()}.
|