NaviServer - programmable web server
4.99  5.0

[ Main Table Of Contents | Table Of Contents | Keyword Index ]

ns_mktemp(n) 4.99.30 naviserver "NaviServer Built-in Commands"

Name

ns_mktemp - Make a unique temporary filename

Table Of Contents

Synopsis

Description

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.

Note that some implementations of mktemp are not safe (creating predictable/only a small number of variations) against attacks and race conditions - please consult your system's man pages if this might be an issue to you. 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.

COMMANDS

ns_mktemp ?template?

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 parameter it behaves like

 ns_mktemp [ns_config ns/parameters tmpdir]/ns-XXXXXX

EXAMPLES

 % ns_mktemp /tmp/aol-XXXXXX
 /tmp/aol-rhaGGx

Keywords

global built-in, tmp, tmpfile