home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / DOSWRITE.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  2.1 KB  |  68 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - doswrite.cas
  3.  *
  4.  * function(s)
  5.  *        _dos_write - writes data to file (MSC compatible)
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1991, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <asmrules.h>
  19. #include <io.h>
  20. #include <_io.h>
  21.  
  22. /*-----------------------------------------------------------------------*
  23.  
  24. Name            _dos_write - writes data to file
  25.  
  26. Usage           unsigned _dos_write(int handle, void far *buf, unsigned nbyte,
  27.                                 unsigned *nwrite);
  28.  
  29. Prototype in    dos.h
  30.  
  31. Description     _dos_write is a direct call to the MS-DOS write system call.
  32.                 The buffer pointer buf must be a far pointer.  The number
  33.                 of bytes requested is nbyte.
  34.  
  35.                 If the write is successful, the number of bytes actually
  36.                 written is stored at *nwrite, which may be less than
  37.                 the number of bytes requested.
  38.                 No text file translation is performed on the data.
  39.  
  40. Return value    success : 0, and *nwrite is set to no. of bytes written
  41.                 else    : the DOS error code, and errno is set to
  42.                           one of the following:
  43.  
  44.                         EACCESS  Permission denied
  45.                         EBADF    Bad file number
  46.  
  47. Note            Compatible with Microsoft C.  Not the same as _write().
  48.  
  49. *------------------------------------------------------------------------*/
  50. unsigned  _dos_write( int fd, void far *buf, unsigned len, unsigned *nwrite )
  51. {
  52. asm     push    ds
  53. asm     mov     ah,40h
  54. asm     mov     bx,fd
  55. asm     mov     cx,len
  56. asm     lds     dx, buf
  57. asm     int     21h
  58. asm     pop     ds
  59. asm     jc      _dos_writeFailed
  60.  
  61. asm     LES_    bx, nwrite
  62. asm     mov     ES_ [bx], ax
  63.         return  (0);
  64.  
  65. _dos_writeFailed:
  66.         return (__DOSerror(_AX));
  67. }
  68.