Flushes a file directly to disk.
#include <io.h> | Required only for function declarations | |
#include <errno.h> |
int _commit( int handle );
handle | Handle referring to open file |
The _commit function forces the operating system to write the file associated with handle to disk. This call ensures that the specified file is flushed immediately—not at the operating system's discretion.
The _commit function returns 0 if the file was successfully flushed to disk. A return value of –1 indicates an error, and errno is set to EBADF, indicating an invalid file-handle argument.
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
/* COMMIT.C illustrates low-level file I/O functions including:
*
* _close _commit memset _open _write
*
* This is example code, to keep the code simple and readable
* return values are not checked.
*/
#include <io.h>
#include <stdio.h>
#include <fcntl.h>
#define MAXBUF 32
int log_receivable( int );
void main( void )
{
int fhandle;
fhandle = _open( "TRANSACT.LOG", _O_APPEND | _O_CREAT |
_O_BINARY | _O_RDWR );
log_receivable( fhandle );
_close( fhandle );
}
int log_receivable( int fhandle )
{
/* The log_receivable function prompts for a name and a monetary amount
* and places both values into a buffer (buf). The _write function
* writes the values to the operating system and the _commit function
* ensures that they are written to a disk file.
*/
int i;
char buf[MAXBUF];
memset( buf, '\0', MAXBUF );
/* Begin Transaction. */
printf( "Enter name: " );
gets( buf );
for( i = 1; buf[i] != '\0'; i++ );
/* Write the value as a '\0' terminated string. */
_write( fhandle, buf, i+1 );
printf( "\n" );
memset( buf, '\0', MAXBUF );
printf( "Enter amount: $" );
gets( buf );
for( i = 1; buf[i] != '\0'; i++ );
/* Write the value as a '\0' terminated string. */
_write( fhandle, buf, i+1 );
printf( "\n" );
return _commit( fhandle );
/* The _commit function ensures that two important pieces of data are
* safely written to disk. The return value of the _commit function
* is returned to the calling function.
*/
}