home *** CD-ROM | disk | FTP | other *** search
- /*-----------------------------------------------------------------------*
- * filename - writea.cas
- *
- * function(s)
- * _write - write to a file (untranslated)
- *-----------------------------------------------------------------------*/
-
- /*[]------------------------------------------------------------[]*/
- /*| |*/
- /*| Turbo C Run Time Library - Version 3.0 |*/
- /*| |*/
- /*| |*/
- /*| Copyright (c) 1987,1988,1990 by Borland International |*/
- /*| All Rights Reserved. |*/
- /*| |*/
- /*[]------------------------------------------------------------[]*/
-
- #pragma inline
- #include <asmrules.h>
- #include <io.h>
- #include <fcntl.h>
- #include <_io.h>
-
- /*-----------------------------------------------------------------------*
-
- Name _write - writes to a file
-
- Usage int _write(int handle, void *buf, unsigned nbyte);
-
- Prototype in io.h
-
- Description Both write and _write are functions that write a
- buffer of data to the file or device named by the given
- handle.
-
- handle is a file handle obtained from a creat, open, dup,
- dup2, or fcntl call.
-
- These functions attempt to write nbyte bytes from the buffer
- pointed to by buf to the file associated with handle. Except
- when write is used to write to a text file, the number of
- bytes written to the file will be no more than the number
- requested.
-
- On text files, when write sees a linefeed (LF) character, it
- outputs a CR-LF pair. _write does no such translation, since
- all of its files are binary files.
-
- If the number of bytes actually written is less than that
- requested, the condition should be considered an error and
- probably indicates a full disk.
-
- For disk or diskette files, writing always proceeds from the
- current file pointer (see lseek). For devices, bytes are directly
- sent to the device.
-
- For files opened with the O_APPEND option, the file pointer is
- positioned to EOF by write (but not by _write) before writing
- the data.
-
- Return value The number of bytes written are returned by both
- functions. A write to a text file does not count generated
- carriage returns. In case of error, each function returns -1
- and sets the global variable errno to one of the following:
-
- EACCES Permission denied
- EBADF Bad file number
-
-
- *------------------------------------------------------------------------*/
- int _CType _write(int fd, void *buf, unsigned len)
- {
- if (_openfd[fd] & O_APPEND)
- lseek (fd, 0L, SEEK_END);
-
- pushDS_
- asm mov ah,40h
- asm mov bx,fd
- asm mov cx,len
- asm LDS_ dx, buf
- asm int 21h
- popDS_
- asm jc _writeFailed
- asm push ax
-
- _openfd [fd] |= O_CHANGED;
-
- asm pop ax
- return _AX;
-
- _writeFailed:
-
- return __IOerror (_AX);
- }
-