Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed unnecessary call to close in Compliant Solution (POSIX write).

...

Code Block
bgColor#ccccff
langc
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

void open_some_file(const char *file) {
  int fd = open(file, O_CREAT | O_EXCL | O_WRONLY);
  if (-1 != fd) {
    FILE *f = fdopen(fd, "w");
    if (NULL != f) {
      /* Write to file */

       ifif (fclose(f) == EOF) {
        /* Handle error */
      }
    }
    if (close(fd) == -1) {else
      /* Handle error */
    }close(fd);
  }
}

Noncompliant Code Example (POSIX read)

...