/*-----------------------------------------------------------------------*
 * filename - dosread.cas
 *
 * function(s)
 *        _dos_read - reads from file (MSC compatible)
 *-----------------------------------------------------------------------*/

/*
 *      C/C++ Run Time Library - Version 5.0
 *
 *      Copyright (c) 1991, 1992 by Borland International
 *      All Rights Reserved.
 *
 */


#pragma inline
#include <asmrules.h>
#include <io.h>
#include <_io.h>

/*-----------------------------------------------------------------------*

Name            _dos_read - reads from file

Usage           unsigned _dos_read(int handle, void far *buf, unsigned nbyte,
                                unsigned *nread);

Prototype in    dos.h

Description     _dos_read is a direct call to the MS-DOS read system call.
                The buffer pointer buf must be a far pointer.  The number
                of bytes requested is nbyte.

                If the read is successful, the number of bytes actually
                read is stored at *nread.  If *nread is 0, an attempt
                was made to read at the end of file.
                No text file translation is performed on the data read.

Return value    success : 0, and *nread is set to no. of bytes read
                else    : the DOS error code, and errno is set to
                          one of the following:

                        EACCESS  Permission denied
                        EBADF    Bad file number

Note            Compatible with Microsoft C.  Not the same as _read().

*------------------------------------------------------------------------*/
unsigned  _dos_read( int fd, void far *buf, unsigned len, unsigned *nread )
{
asm     push    ds
asm     mov     ah,3fh
asm     mov     bx,fd
asm     mov     cx,len
asm     lds     dx, buf
asm     int     21h
asm     pop     ds
asm     jc      _dos_readFailed

asm     LES_    bx, nread
asm     mov     ES_ [bx], ax
        return  (0);

_dos_readFailed:
        return (__DOSerror(_AX));
}
