Versions Compared

Key

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

Receiving input from a stream directly following an output to that stream (or vice versa) without an intervening call to fflush(), fseek(), fsetpos(), or rewind() results in undefined behavior. Therefore, Consequently a call to one of these functions is necessary in between input and output to the same update stream.

Non-Compliant Code Example

...

Code Block
bgColor#ffcccc
/* somelocation deviceto usedbe forread bothor inputwritten andto output */
const char *filename = "/dev/device2";

FILE *file = fopen(filename, "rb+");
if (file == NULL) {
  /* handle error */
}

/* write to file stream */
/* read response from file stream */
fclose(file);

...

Code Block
bgColor#ccccff
/*location someto devicebe usedread foror both input and outputwritten to */
const char *filename = "/dev/device2";

FILE *file = fopen(filename, "rb+");
if (file == NULL) {
  /* handle error */
]

/* write to file stream */
fflush(file);
/* read response from file stream */
fclose(file);

...