PREV UP NEXT GNU Emacs Lisp Reference Manual

22.8.5: Generating Unique File Names

Some programs need to write temporary files. Here is the usual way to construct a name for such a file:

(make-temp-name (concat "/tmp/" name-of-application))

Here we use the directory `/tmp/' because that is the standard place on Unix for temporary files. The job of make-temp-name is to prevent two different users or two different jobs from trying to use the same name.

Function: make-temp-name string
This function generates string that can be used as a unique name. The name starts with string, and ends with a number that is different in each Emacs job.
(make-temp-name "/tmp/foo")
     => "/tmp/foo021304"

To prevent conflicts among different libraries running in the same Emacs, each Lisp program that uses make-temp-name should have its own string. The number added to the end of the name distinguishes between the same application running in different Emacs jobs.