Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>_dos_write() write to a file</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _dos_write()            Write to a file

 #include   <dos.h>

  unsigned     _dos_write(handle, buffer, count, bytes);

  int handle;       Identifier of file to write to
  void far *buffer;      Buffer to write from
  unsigned count;        Number of bytes to write
  unsigned *bytes;       Number of bytes actually written

    _dos_write() uses MS-DOS function 40h to write 'count' bytes from
    memory location 'buffer' to the file identified by 'handle'. The
    number of bytes actually written is returned in 'bytes', and may be
    less than the number specified in 'count'.

    Returns:    _dos_write() returns 0 if the file was written
                successfully. If unsuccessful, it returns the MS-DOS
                error code and sets errno to one of the following
                manifest constants:

                    Constant     Meaning
                    -----------------------------------------
                    EBADF        Invalid file handle

                    EACCES       Access denied (file not open
                                 for write access)

      Notes:    _dos_write() begins writing at the current position of
                the read/write pointer, which can be repositioned using
                lseek(). When finished writing the pointer is positioned
                at the first character following the last character
                written. If 'count' is set to 0 bytes to write, then the
                file is truncated at the current position of the
                read/write pointer.

                Five standard (redirectable) I/O devices have predefined
                handles assigned to them, and four of them can be written
                to without being explicitly opened:

                    Device      Handle
                    -------------------
                    stdout      1
                    stderr      2
                    stdaux      3
                    stdprn      4

                In MS-DOS 3.0 or higher, dosexterr() can be used for
                extended error code information.

   Portability:     MS-DOS only, version 2.0 or higher

------------------------------- Example ---------------------------------

    This program writes text from memory location 'buffer' to the
    standard output,which can be redirected

           #include             <dos.h>

           main()
           {
             char buffer[] = "This is a test of the _dos_write() MSC 5.0
           function";
             unsigned bytes_written;
             int err_code;
             unsigned buf_size = sizeof(buffer);
             .
             .  (file is opened for write access)
             .
             err_code = _dos_write( 1, buffer, buf_size, &bytes_written);
             if (err_code)
                printf("Only %u bytes written -- error code is %u\n",
           bytes_written,
                err_code);
             .
             .  (file is closed)
             .
           }


See Also: _dos_open() _dos_creat() _dos_read()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson