


      READ(2)                     (UNIX 5.0)                    READ(2)



      NAME
           read - read from file

      SYNTAX
           int read (fildes, buf, nbyte)
           int fildes;
           char *buf;
           unsigned nbyte;

      DESCRIPTION
           Fildes is a file descriptor obtained from a creat, open,
           dup, or fcntl system call.

           Read attempts to read nbyte bytes from the file associated
           with fildes into the buffer pointed to by buf.

           On devices capable of seeking, the read starts at a position
           in the file given by the file pointer associated with
           fildes.  Upon return from read, the file pointer is
           incremented by the number of bytes actually read.

           Devices that are incapable of seeking always read from the
           current position.  The value of a file pointer associated
           with such a file is undefined.

           Upon successful completion, read returns the number of bytes
           actually read and placed in the buffer; this number may be
           less than nbyte if the file is associated with a
           communication line (see ioctl(2) and termio(7)), or if the
           number of bytes left in the file is less than nbyte bytes.
           A value of 0 is returned when an end-of-file has been
           reached.

           When attempting to read a file associated with a tty that
           has no data currently available:

                If O_NDELAY is set, the read will return a 0.

                If O_NDELAY is clear, the read will block until data
                becomes available.

           When attempting to read from a regular file with mandatory
           file/record locking set, see chmod(2), and there is blocking
           (i.e. owned by another process) write lock on the segment of
           the file to be read:

                If O_NDELAY is set, the read will return a -1 and set
                errno to EAGAIN.

                If O_NDELAY is clear, the read will sleep until the
                blocking record lock is removed.




      Page 1                                         (73 A2 02MTA REV1)






      READ(2)                     (UNIX 5.0)                    READ(2)



           Read will fail if one or more of the following are true:

                Fildes is not a valid file descriptor open for reading.
                [EBADF]

                Buf points outside the allocated address space.
                [EFAULT]

                A signal was caught during the read system call.
                [EINTR]

                Mandatory file/record locking was set, O_NDELAY was
                set, and there was a blocking record lock.  [EAGAIN]

                The system record lock table was full, so the read
                could not go to sleep until the blocking record lock
                was removed.  [ENOLCK]

                The read was going to go to sleep and cause a deadlock
                situation to occur.  [EDEADLK]

      RETURN VALUE
           Upon successful completion a non-negative integer is
           returned indicating the number of bytes actually read.
           Otherwise, a -1 is returned and errno is set to indicate the
           error.

      SEE ALSO
           chmod(2), creat(2), dup(2), fcntl(2), ioctl(2), open(2),
           termio(7).

























      Page 2                                         (73 A2 02MTA REV1)



