blob: 02e73e1e6e1f9e0585d003959fcd343c1a3d3eae [file] [log] [blame]
Guido van Rossumeee94981991-11-12 15:38:08 +00001# Temporary file name allocation
2
3import posix
4import path
5
6
7# Changeable parameters (by clients!)...
8# XXX Should the environment variable $TMPDIR override tempdir?
9
10tempdir = '/usr/tmp'
11template = '@'
12
13
14# Kludge to hold mutable state
15
16class Struct(): pass
17G = Struct()
18G.i = 0
19
20
21# User-callable function
22# XXX Should this have a parameter, like C's mktemp()?
23# XXX Should we instead use the model of Standard C's tempnam()?
24# XXX By all means, avoid a mess with four different functions like C...
25
26def mktemp():
27 while 1:
28 G.i = G.i+1
29 file = tempdir +'/'+ template + `posix.getpid()` +'.'+ `G.i`
30 if not path.exists(file):
31 break
32 return file