Reads data from a file, using system call 0x3F.
#include <dos.h>
unsigned _dos_read( int handle, void __far *buffer, unsigned count,
unsigned *numread );
handle | File to read | |
buffer | Buffer to write to | |
count | Number of bytes to read | |
numread | Number of bytes actually read |
The _dos_read routine uses system call 0x3F to read count bytes of data from the file specified by handle. The routine then copies the data to the buffer pointed to by buffer. The integer pointed to by numread will show the number of bytes actually read, which may be less than the number requested in count. If the number of bytes actually read is 0, it means the routine tried to read at end-of-file.
Do not use the DOS interface I/O routines in conjunction 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 constants:
Constant | Meaning |
EACCES | Access denied (handle is not open for read access) |
EBADF | File handle is invalid |
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
_dos_close, _dos_open, _dos_write, _read
/* DREAD.C: This program uses the DOS I/O operations to read the contents
* of a file.
*/
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
void main( void )
{
int fh;
char buffer[50];
unsigned number_read;
/* Open file with _dos_open function */
if( _dos_open( "dread.c", _O_RDONLY, &fh ) != 0 )
perror( "Open failed on input file\n" );
else
printf( "Open succeeded on input file\n" );
/* Read data with _dos_read function */
_dos_read( fh, buffer, 50, &number_read );
printf( "First 40 characters are: %.40s\n\n", buffer );
/* Close file with _dos_close function */
_dos_close( fh );
}
Open succeeded on input file
First 40 characters are: /* DREAD.C: This program uses the DOS I/