Flushes a file to disk using system call 0x68.
#include <dos.h>
#include <errno.h>
unsigned _dos_commit( int handle );
handle | Target file handle |
The _dos_commit function uses system call 0x68 to flush to disk the DOS buffers associated with the file indicated by handle. It also forces an update on the corresponding disk directory and the file allocation table. System call 0x68 ensures that the specified file is flushed directly to disk and not flushed at the operating system's discretion.
The system call used to implement _dos_commit is only available in DOS versions 3.3 and later. Using _dos_commit in earlier versions of DOS results in undefined behavior.
Do not use the DOS interface I/O routines with the console, low-level, or stream I/O routines.
The function returns 0 if successful. Otherwise, it returns the DOS error code and sets errno to EBADF, indicating an invalid file handle.
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
_close, _creat, _dos_creat functions, _dos_open, _dos_read, _dos_write, _dup, _open
/* DCOMMIT.C illustrates DOS file I/O functions including:
* _dos_commit _dos_creatnew _dos_write
*/
#include <dos.h>
#include <errno.h>
#include <conio.h>
void main( void )
{
char saveit[] = "Straight to disk. ",
prompt[] = "File exists, overwrite? [y|n] ",
err[] = "Error occured. ",
newline[] = "\n\r";
int hfile, ch;
unsigned count;
/* Open file and create, overwriting if necessary. */
if( _dos_creatnew( "COMMIT.LOG", _A_NORMAL, &hfile ) != 0 )
{
if( errno == EEXIST )
{
/* Use _dos_write to display prompts. Use bdos to call
* function 1 to get and echo keystroke.
*/
_dos_write( 1, prompt, sizeof( prompt ) - 1, &count );
ch = bdos( 1, 0, 0 ) & 0x00ff;
if( (ch == 'y') || (ch == 'Y') )
_dos_creat( "COMMIT.LOG", _A_NORMAL, &hfile );
_dos_write( 1, newline, sizeof( newline ) - 1, &count );
}
}
/* Write to file; output passes through operating system's buffers. */
if( _dos_write( hfile, saveit, sizeof( saveit ), &count ) != 0 )
{
_dos_write( 1, err, sizeof( err ) - 1, &count );
_dos_write( 1, newline, sizeof( newline ) - 1, &count );
}
/* Write directly to file with no intermediate buffering */
if( _dos_commit( hfile ) != 0 )
{
_dos_write( 1, err, sizeof( err ) - 1, &count );
_dos_write( 1, newline, sizeof( newline ) - 1, &count );
}
/* Close file. */
if( _dos_close( hfile ) != 0 )
{
_dos_write( 1, err, sizeof( err ) - 1, &count );
_dos_write( 1, newline, sizeof( newline ) - 1, &count );
}
}