Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added compliant solution to the tmpnam example.

...

In this compliant solution, mkostemp is used instead.

Code Block
bgColor#ccccFF
langc
 static const char temp_file_template[] = TEMP_DIR DIR_SEPARATOR "xyzzy_XXXXXX";
char file_name[sizeof(temp_file_template)];
FILE *fp;
int fd;

strcpy_s(file_name, sizeof(temp_file_template), temp_file_template);
fd = mkostemp(file_name, O_RDWR | O_CREAT | O_TRUNC);
if (fd == -1) {
  /* Handle error */
}

fp = fdopen(fd, "wb+");
if (fp == NULL) {
   /* Handle error */
}

Noncompliant Code Example

...