Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

/* initializeInitialize file_name */

fp = fopen(file_name, "w");
if (!fp) {
  /* Handle error */
}

...

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

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

...

Code Block
bgColor#ccccff
langc
char *file_name;

/* initializeInitialize file_name */

FILE *fp = fopen(file_name, "wx");
if (!fp) {
  /* Handle error */
}

...

Code Block
bgColor#ccccff
langc
char *file_name;
int new_file_mode;

/* initializeInitialize file_name and new_file_mode */

int fd = open(file_name, O_CREAT | O_EXCL | O_WRONLY, new_file_mode);
if (fd == -1) {
  /* Handle error */
}

...

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

/* initializeInitialize file_name and new_file_mode */

fd = open(file_name, O_CREAT | O_EXCL | O_WRONLY, new_file_mode);
if (fd == -1) {
  /* Handle error */
}

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

...