Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider v2.4 (sch jbop) (X_X)@==(Q_Q)@

Simultaneously opening a file multiple times has implementation-defined behavior. While some platforms may forbid a file simultaneously being opened multiple times, those that allow it may facilitate dangerous race conditions.

...

Noncompliant Code Example

The following non-compliant noncompliant code example logs the program's state at runtime.

Code Block
bgColor#ffcccc
void do_stuff(void) {
  FILE *logfile = fopen("log", "a");
  if (logfile == NULL) {
    /* handle error */
  }

  /* write logs pertaining to do_stuff() */

  /* ... */
}

int main(void) {
  FILE *logfile = fopen("log", "a");
  if (logfile == NULL) {
    /* handle error */
  }

  /* write logs pertaining to main() */

  do_stuff();

  /* ... */
}

...

Code Block
bgColor#ccccff
void do_stuff(FILE *logfile) {
  /* write logs pertaining to do_stuff() */

  /* ... */
}

int main(void) {
  FILE *logfile = fopen("log", "a");
  if (logfile == NULL) {
    /* handle error */
  }

  /* write logs pertaining to main() */

  do_stuff(logfile);

  /* ... */
}

...