ns_mktemp - Make a unique temporary filename
This command is a wrapper around the mktemp(3) function in the C standard library. This function generates a unique temporary filename from an optional template.
In general, the pattern of creating a temporary filename based on its non-occurrence in a directory followed by creating this file is prone to a race condition and can provide security issues. Therefore, the command is deprecated and will issue an entry to the log file unless ?-nocomplain? is used.
In order to create temp files, the Tcl command file tempfile should be used (introduced in Tcl 8.6), which is safe against race conditions. For creating temporary directories, use ns_mkdtemp (introduced in NaviServer 5) or file tempdir in Tcl9.
There are certain situations, where it is not easy to replace ns_mktemp, e.g. in situations, where unique names are passed to external programs. This situation can often be solved by changing the logic by e.g. writing to a temporary file and then pass the name to the external program, or by using other means for creating unique names, such as ns_uuid.
This command generates a unique temporary filename using optionally a template as argument, which is a string whose last six characters must be XXXXXX, and returns a new string where those are replaced with random characters such as to make the string a unique filename. It is commonly used to create temporary filenames.
If this command is called without the optional template parameter, it behaves like
ns_mktemp [ns_config ns/parameters tmpdir]/ns-XXXXXX
% ns_mktemp /tmp/foo-XXXXXX /tmp/foo-rhaGGx
ns_mkdtemp, ns_uuid