Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added information about using CreateFile in place of fopen_s on Windows.

...

Code Block
bgColor#ccccff
langc
char *file_name;
FILE *fp;

/* Initialize file_name */

errno_t res = fopen_s(&fp, file_name, "wx");
if (res != 0) {
  /* Handle error */
}

On Windows, fopen_s will create the file with security permissions based on the user executing the application.  For more controlled permission schemes, consider using the CreateFile() function, and specifying the SECURITY_ATTRIBUTES parameter.

Noncompliant Code Example (open(), POSIX)

...