C language new temporary file and temporary file name method _c language

Source: Internet
Author: User

C language Mkstemp () function: Creating Temporary files
header file:

#include <stdlib.h>

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:

#include <stdlib.h>

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);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.