Borland C++ reference

_write

raw OCR

Writes to a file.

Defined in header <io.h>

Syntax

#include <io.h>
int _write(int handle, void *buf, unsigned len);

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

_write attempts to write len bytes from the buffer pointed to by buf

to the file associated with handle. The maximum that _write can write is 65,534, because 65,535 (0xFFFF) is the same as -1, which is the error return indicator for _write.number of bytes

_wrlte does not translate a Unefeed character (LF) to a CR/LF pair because all 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 files, writing, always proceeds from the current file pointer. On devices, bytes are directly sent to the device.

For files opened with the 0_APPENDoption, the file pointer is

not positioned to EOF by _write before writing the data.

Return value

_write returns the number of bytes written. In case of error, _write returns -1 and sets the global variable errno to one of the following:

EACCESPermission denied
EBADFBad file number

See also

Example

#include <stdio.h>
#include <io.h>
#include <alloc.h>
#include <fcntl.h>
#include <process.h>
#include <sys\stat.h>
int main (void)
{
   void *buf;
   int handle, bytes;
   buf = malice (200);
   /* Create a  file TEST.$$$ in the current directory  and write 2(
      bytes to it.  If TEST.$$$ already exists, overwrite.  */
   if  ((handle = open("TEST.$$$", 0_CREAT  I 0_WRONLY I 0_BINARY,
                        S_IWRITE I S_IREAD)) == -1)

      printf ('Error Opening File\n"
      exit(l);
   }
   if  ((bytes= _write (handle, buf, 200)      -1)
      printf ('Write Failed.\n");
      exit(l),
printf ("_write: %d bytes Vi/ritten.\n",bytes);
return

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.

Extraction notes

  • heading `write` read as `_write`