Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <io.h>
    int fsync( int fd );

Description:
    The fsync function writes to disk all the currently queued data for the
    open file specified by fd.  All necessary file system information
    required to retrieve the data is also written to disk.  The file access
    times are also updated.

    The fsync function is used when you wish to ensure that both the file
    data and file system information required to recover the complete file
    have been written to the disk.

    The fsync function does not return until the transfer is completed.

Returns:
    The fsync function returns zero if successful.  Otherwise, it returns -1
    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:
    When an error has occurred,  errno contains a value indicating the type
    of error that has been detected.

    Constant     Meaning

EBADF
    The fd argument is not a valid file handle.

EINVAL
    Synchronized i/o is not supported for this file.

EIO
    A physical I/O error occurred (e.g., a bad block).  The precise meaning
    is device dependent.

ENOSYS
    The fsync function is not supported.


Example:
    /*
     *      Write a file and make sure it is on disk.
     */
    #include <fcntl.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <io.h>

    char buf[512];

    void main()
    {
        int handle;
        int i;

        handle = creat( "file", S_IWRITE | S_IREAD );
        if( handle == -1 ) {
          perror( "Error creating file" );
          exit( EXIT_FAILURE );
        }

        for( i = 0; i < 255; ++i ) {
          memset( buf, i, sizeof( buf ) );
          if( write( handle, buf, sizeof(buf) ) != sizeof(buf) ) {
            perror( "Error writing file" );
            exit( EXIT_FAILURE );
          }
        }

        if( fsync( handle ) == -1 ) {
          perror( "Error sync'ing file" );
          exit( EXIT_FAILURE );
        }

        close( handle );
        exit( EXIT_SUCCESS );
    }

Classification:
    POSIX 1003.4

Systems:
    All, Netware

See Also:
    fstat, open, stat, write

See Also: write

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson