tmpfile_s

From RAD Studio
Jump to: navigation, search

Go Up to stdio.h Index


Header File

stdio.h

Category

Input/output Routines

Prototype

errno_t tmpfile_s(FILE * restrict * restrict streamptr);

Description

Replaces tmpfile adding security enhancements.

tmpfile_s creates a temporary binary file and opens it for update ("wb+"). If you do not change the directory after creating the temporary file, the file is automatically removed when it is closed or when your program terminates. If the program terminates abnormally, the file is not automatically removed. It is your responsability to remove it if necessary.

Return Value

tmpfile_s returns zero if the temporary file was created successfully, otherwise returns the respective error code. Also, if the temporary file was created successfully, streamptr holds the value pointing to the newly created file, otherwise streamptr is set to null.

Example

#include <stdio.h>
#include <process.h>
int main(void)
{
  FILE *tempf;
  if(tmpfile_s(&tempf)){
    printf("Unable to create temporary file\n");
    exit(1);
  }
  else {
    printf("Temporary file created\n");
  }
  return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

+

+

+

+

See Also