Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <io.h>
    int read( int handle, void *buffer, unsigned len );

Description:
    The read function reads data at the operating system level.  The number
    of bytes transmitted is given by len and the data is transmitted
    starting at the address specified by buffer.

    The handle value is returned by the  open function.  The access mode
    must have included either O_RDONLY or O_RDWR when the  open function was
    invoked.  The data is read starting at the current file position for the
    file in question.  This file position can be determined with the  tell
    function and can be set with the  lseek function.

    When O_BINARY is included in the access mode, the data is transmitted
    unchanged.  When O_TEXT is included in the access mode, the data is
    transmitted with the extra carriage return character removed before each
    linefeed character encountered in the original data.

Returns:
    The read function returns the number of bytes of data transmitted from
    the file to the buffer (this does not include any carriage-return
    characters that were removed during the transmission).  Normally, this
    is the number given by the len argument.  When the end of the file is
    encountered before the read completes, the return value will be less
    than the number of bytes requested.

    A value of -1 is returned when an input/output error is detected.  When
    an error has occurred,  errno contains a value indicating the type of
    error that has been detected.

See Also:
    close, creat, fread, open, write

Example:
    #include <stdio.h>
    #include <fcntl.h>
    #include <io.h>

    void main()
      {
        int  handle;
        int  size_read;
        char buffer[80];

        /* open a file for input              */
        handle = open( "file", O_RDONLY | O_TEXT );
        if( handle != -1 ) {

          /* read the text                      */
          size_read = read( handle, buffer,
                            sizeof( buffer ) );

          /* test for error                     */
          if( size_read == -1 ) {
              printf( "Error reading file\n" );
          }

          /* close the file                     */
          close( handle );
        }
      }

Classification:
    POSIX 1003.1

Systems:
    All

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