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_read() read a file</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _dos_read()             Read a file

 #include   <dos.h>

  unsigned     _dos_read(handle, buffer, count, bytes);
  int handle;  Identifier of file to read
  void far *buffer; Buffer to write to
  unsigned count;   Number of bytes to read
  unsigned *bytes;  Number of bytes actually read

    _dos_read() uses MS-DOS function 3Fh to read 'count' bytes from the
    file identified by 'handle' and copy it to 'buffer'. The number of
    bytes actually read is returned in 'bytes', and may be less than the
    number specified in 'count'.

    Returns:    _dos_read() returns 0 if the file was read 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 read access)

      Notes:    _dos_read() begins reading from the current position of
                the read/write pointer, which can be repositioned using
                lseek(). When finished reading, the pointer is positioned
                at the first character following the last character read.
                If the number of bytes read is 0, _dos_read() tried to
                read from the end of the file.

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

                    Device      Handle
                    -------------------
                    stdin       0
                    stdaux      3

                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 reads 2K bytes from an open file into the memory location
 pointed to by 'buffer'

           #include             <dos.h>

           main()
           {
             int handle;
             char buffer[2048];
             unsigned bytes_read;
             int err_code;
             .
             .  (file is opened for read access)
             .
             err_code = _dos_read(handle, buffer, 2048, &bytes_read);
             if (err_code)
                printf("Only %u bytes read -- error code is %u\n",
                        bytes_read, err_code);
             .
             .  (file is closed)
             .
           }


See Also: _dos_open() _dos_creat() _dos_write()

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