mktemp()

Создать уникальный временный файл

Прототип:

#include <stdlib.h>
char * mktemp( char *template );

Аргументы:

template
A template for the filename that you want to use. This template can be any file name with some number of Xs appended to it, for example /tmp/temp.XXXX.

Библиотека:

libc

Описание:

The mktemp() function takes the given file name template and overwrites a portion of it to create a filename. This file 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 mktemp() can return depends on the number of Xs provided; if you specify six Xs, mktemp() tests roughly 26⁶ combinations.

The mkstemp() function (unlike this function) creates the template file, mode 0600 (i.e. read-write for the owner), returning a file descriptor opened for reading and writing. This avoids the race between testing for a file's existence and opening it for use.

Возвращаемое значение:

NULL
Возникла ошибка. Код ошибки записан в errno.
≠NULL
Указатель на шаблон.

Коды ошибок:

ENOTDIR
The pathname portion of the template isn't an existing directory.

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

Классификация:

POSIX 1003.1 XSI

Точка остановки потока
Да
Обработчик прерываний
Нет
Обработчик сигналов
Да
В потоке
Да

Предостережения:

In general, avoid using mktemp(), because a hostile process can exploit a race condition in the time between the generation of a temporary filename by mktemp() and the invoker's use of the temporary name. Use mkstemp() instead.

This function can create only 26 unique file names per thread for each unique template.

Тематические ссылки:

chmod(). getpid(). mkstemp(), open() stat(). tmpfile(), tmpnam()




Предыдущий раздел: Описание API системной библиотеки