C language Mkstemp () function: Creating Temporary files
header file:
To define a function:
int mkstemp (char * template);
Function Description: Mkstemp () is used to create a unique temporary file. The last six characters in the file name string referred to in parameter template must be xxxxxx. Mkstemp () Opens the file in both read and write mode and 0600 permissions, and the file is created if the file does not exist. When the file is opened, its file descriptor returns. Returns a read-write file descriptor when the file is opened successfully. Returns null if the file fails to open, and the error code exists in errno.
Error code: EINVAL parameter template string last six words Fu Fei xxxxxx. Eexist cannot establish a temporary file.
Additional Instructions:
The file name string referred to in parameter template must be declared as an array, such as:
Char template[] = "template-xxxxxx";
You must not use the following expressions
Char *template = "template-xxxxxx";
Example
#include <stdlib.h>
Main ()
{
int fd;
Char template[] = "template-xxxxxx";
FD = mkstemp (template);
printf ("template =%s\n", template);
Close (FD);
}
Perform
Template = TEMPLATE-LGZCBO
C language Mktemp () function: produces a unique temporary filename
header file:
To define a function:
char * mktemp (char * template);
Function Description: Mktemp () is used to produce a unique temporary filename. The last six characters in the file name string referred to in parameter template must be xxxxxx. The resulting filename is returned by the string pointer.
Return value: After the file is successfully opened, the file pointer to the stream is returned. Returns null if the file fails to open, and the error code is in errno.
Additional Note: The file name string that the parameter template refers to must be declared as an array, such as:
Char template[] = "template-xxxxxx";
Not available
char * template = "template-xxxxxx";
Example
#include <stdlib.h>
Main ()
{
char template[] = "template-xxxxxx";
Mktemp (template);
printf ("template=%s\n", template);
}