mkdtemp()

Make a unique temporary directory name

Synopsis:

#include <stdlib.h>

char* mkdtemp( char* template );

Arguments:

template
A template for the directory name that you want to use. This template can be any name with at least six X characters appended to it, for example /tmp/dirXXXXXX.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The mkdtemp() function takes the given template and overwrites a portion of it to create a directory name, and then creates the directory with mode 0700 (i.e., read-write-execute for the owner). The name is unique and suitable for use by the application. The trailing Xs are replaced with the current process number and/or a unique letter combination. The number of unique file names mkdtemp() can return depends on the number of Xs provided; it tries at least 231 combinations before giving up.

Returns:

A pointer to the template, or NULL on failure (errno is set).

Errors:

EINVAL
The template doesn't include at least six X wildcard characters.
EEXIST
All the names tried already exist. Consider adding more wildcard characters to the template.

This function may also set errno to any value specified by mkdir().

Classification:

POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

Contributing author:

OpenBSD