FAT | RFS | XFS

fflush()

PROTOTYPE

#include <stdio.h>

int fflush(FILE *file);

DESCRIPTION

fflush() writes a volume’s buffered changes, both user data and metadata, to the underlying storage media. It doesn’t return until after the changes are saved.

If file is the handle of an open file, all buffered data on the volume holding that file is flushed. Any byte stored on the file’s control block by ungetc() is dropped. If file equals NULL, every volume holding buffered data is flushed, including stdout and stderr.

If successful, fflush() returns 0. Otherwise, it sets errno and returns EOF.

ERROR CODES

EBADF file is neither NULL nor the handle of an open file.
EROFS The volume is read-only.

EXAMPLE

  /*-----------------------------------------------------------------*/
  /* Flush buffered data to the storage media.                       */
  /*-----------------------------------------------------------------*/
  if (fflush(file))
    return -1;