mkstemp()

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

Прототип:

#include <stdlib.h>
int mkstemp( 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 mkstemp() 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 mkstemp() can return depends on the number of Xs provided; if you specify six Xs, mkstemp() tests roughly 26⁶ combinations.

The mkstemp() function (unlike mktemp()) 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.

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

Дескриптор временного файла. Если возникла ошибка функция возвращает -1, код ошибки записывается в errno.

Коды ошибок:

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

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

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

POSIX 1003.1 XSI

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

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

It's possible to run out of letters. The mkstemp() function doesn't check to determine whether the file name part of template exceeds the maximum allowable filename length.

For portability with X/Open standards prior to XPG4v2, use tmpfile() instead.

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

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




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