fsync

Synchronizes the changes to a file.

Library:LibC
Classification:POSIX
Service:File and Directory I/O

Syntax

  #include <unistd.h> 
   
  int fsync (
     int   fildes);
  

Parameters

fildes

(IN) Specifies a file descriptor.

Return Values

If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

4

EBADF

Invalid file descriptor.

9

ENIVAL

I/O synchronization is not supported for this file.

28

EIO

An I/O error occurred while reading or writing to the file system.

63

EINTR

A signal interrupted the operation.

Remarks

The fsync function forces all data associated with the specified file to be transferred to the storage device associated with the specified file. The function does not return until the system has completed that action or until an error is detected. If an error is detected, there is no guarantee that all I/O operations completed.

See Also