This is not necessarily the current version of this TIP.
| TIP: | 210 |
| Title: | Add 'tempname' Subcommand to 'file' |
| Version: | $Revision: 1.1 $ |
| Author: | Bob Techentin <techentin dot robert at mayo dot edu> |
| State: | Draft |
| Type: | Project |
| Tcl-Version: | 8.5 |
| Vote: | Pending |
| Created: | Monday, 19 July 2004 |
| Keywords: | Tcl, filename |
Programmers often need to create temporary files. This TIP proposes adding the new subcommand tempname to the file command, simplifying programmer effort in creating a unique temporary file name.
Creating temporary files is a primitive and common enough operation that the ANSI C standard defines several subroutines to assist programmers. The tmpnam() function generates a string that is a valid file name that is not the name of an existing file. The tmpfile() function returns a valid file pointer to a temporary file that is removed automatically when it is closed or at program termination. Both functions are commonly used by programmers, without worrying about the optimal location for temporary files or schemes required to create unique file names.
Tcl has not supported temporary files, so programmers have had to write code to generate unique file names and choose locations like /tmp or c://temp. The fileutil module of tcllib provides a relatively sophisticated implementation of tempfile, but extension writers have not been able to rely on this code. Modules in Iwidgets, the Tcl plugin, tcllib, and tclx all appear to have this sort of code, and not all are correct.
This TIP proposes to extend the file command with one subcommand to generate temporary file names. By extending the core command, application programmers and extension writers will be able to depend on this functionality for their code, without resorting to copying or depending on tcllib.
This TIP proposes the most straight forward extension to the file command, directly exposing the functionality of the ANSI standard tmpnam() function. The new subcommand will be called tempname, adding vowels, but staying true to the ANSI naming convention.
Programmers wishing to have a more sophisticated implementation, such as that found in tcllib, will still be free to use that code.
file tempname
Returns a valid temporary file name that does not yet exist. The function will return a different file name each time it is called.
This document has been placed in the public domain.
This is not necessarily the current version of this TIP.