The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

fsync - synchronise changes to a file

 SYNOPSIS



#include <unistd.h>

int fsync(int fildes);

 DESCRIPTION

The fsync() function can be used by an application to indicate that all data for the open file description named by fildes is to be transferred to the storage device associated with the file described by fildes in an implementation-dependent manner. The fsync() function does not return until the system has completed that action or until an error is detected.

The fsync() function forces all currently queued I/O operations associated with the file indicated by file descriptor fildes to the synchronised I/O completion state. All I/O operations are completed as defined for synchronised I/O file integrity completion.

 RETURN VALUE

Upon successful completion, fsync() returns 0. Otherwise, -1 is returned and errno is set to indicate the error. If the fsync() function fails, outstanding I/O operations are not guaranteed to have been completed.

 ERRORS

The fsync() function will fail if:
[EBADF]
The fildes argument is not a valid descriptor.
[EINTR]
The fsync() function was interrupted by a signal.
[EINVAL]
The fildes argument does not refer to a file on which this operation is possible.
[EIO]
An I/O error occurred while reading from or writing to the file system.

In the event that any of the queued I/O operations fail, fsync() returns the error conditions defined for read() and write().

 EXAMPLES

None.

 APPLICATION USAGE

The fsync() function should be used by programs which require modifications to a file to be completed before continuing; for example, a program which contains a simple transaction facility might use it to ensure that all modifications to a file or files caused by a transaction are recorded.

 FUTURE DIRECTIONS

None.

 SEE ALSO

sync(), <unistd.h>.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]