Writes a buffer to a file, using system call 0x40.
#include <dos.h>
unsigned _dos_write( int handle, void __far *buffer, unsigned count,
unsigned *numwrt );
handle | File to write to | |
buffer | Buffer to write from | |
count | Number of bytes to write | |
numwrt | Number of bytes actually written |
The _dos_write routine uses system call 0x40 to write data to the file that handle references; count bytes of data from the buffer to which buffer points are written to the file. The integer pointed to by numwrt will be the number of bytes actually written, which may be less than the number requested.
Do not use the DOS interface routines with the console, low-level, or stream I/O routines.
If successful, the function returns 0. Otherwise, it returns the DOS error code and sets errno to one of the following manifest constants:
Constant | Meaning |
EACCES | Access denied (handle references a file not open for write access) |
EBADF | Invalid file handle |
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
_dos_close, _dos_open, _dos_read, _write
/* DWRITE.C: This program uses DOS I/O functions to write to a file. */
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
void main( void )
{
char out_buffer[] = "Hello";
int fh;
unsigned n_written;
/* Open file with _dos_creat function */
if( _dos_creat( "data", _A_NORMAL, &fh ) == 0 )
{
/* Write data with _dos_write function */
_dos_write( fh, out_buffer, 5, &n_written );
printf( "Number of characters written: %d\n", n_written );
_dos_close( fh );
printf( "Contents of file are:\n" );
system( "type data" );
}
}
Number of characters written: 5
Contents of file are:
Hello