NaviServer - programmable web server

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

# ns_mktemp(n) 4.99.8 naviserver "NaviServer Built-in Commands"

## Name

ns_mktemp - Make a unique temporary file name

## Table Of Contents

## Synopsis

- ns_mktemp ?template?

## Description

This command is a wrapper around the mktemp(3) function in the C standard library.

Note that some implementations of mktemp are not so safe - it creates predictable/only a small number of variations - please consult your system's man pages if this might be an issue to you. NaviServer could potentially be improved to use mkstemp instead, but that command creates a file as well, so this is not fully compatible.

## COMMANDS

ns_mktemp ?template?

  This command takes a 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 file name. It is commonly used to safely create temporary files.

  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

tmp, tmpfile