[07a3253d] | 1 | /* |
---|
| 2 | * read() - POSIX 1003.1b 6.4.1 - Read From a File |
---|
| 3 | * |
---|
| 4 | * COPYRIGHT (c) 1989-1998. |
---|
| 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * Copyright assigned to U.S. Government, 1994. |
---|
| 7 | * |
---|
| 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in the file LICENSE in this distribution or at |
---|
| 10 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #include "libio_.h" |
---|
| 16 | |
---|
[e22d644] | 17 | ssize_t read( |
---|
[07a3253d] | 18 | int fd, |
---|
| 19 | void *buffer, |
---|
[e22d644] | 20 | size_t count |
---|
[07a3253d] | 21 | ) |
---|
| 22 | { |
---|
| 23 | int rc; /* XXX change to a size_t when prototype is fixed */ |
---|
| 24 | rtems_libio_t *iop; |
---|
| 25 | |
---|
[cca4400] | 26 | rtems_libio_check_fd( fd ); |
---|
| 27 | iop = rtems_libio_iop( fd ); |
---|
| 28 | rtems_libio_check_buffer( buffer ); |
---|
| 29 | rtems_libio_check_count( count ); |
---|
| 30 | rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ ); |
---|
| 31 | |
---|
[07a3253d] | 32 | /* |
---|
| 33 | * If this file descriptor is mapped to an external set of handlers, |
---|
| 34 | * then pass the request on to them. |
---|
| 35 | */ |
---|
| 36 | |
---|
[cca4400] | 37 | if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { |
---|
[07a3253d] | 38 | rtems_libio_read_t fp; |
---|
| 39 | |
---|
[cca4400] | 40 | fp = rtems_libio_handlers[ |
---|
| 41 | (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read; |
---|
[07a3253d] | 42 | if ( fp == NULL ) |
---|
| 43 | set_errno_and_return_minus_one( EBADF ); |
---|
| 44 | |
---|
| 45 | return (*fp)( fd, buffer, count ); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | /* |
---|
| 49 | * Now process the read(). |
---|
| 50 | */ |
---|
| 51 | |
---|
| 52 | if ( !iop->handlers->read ) |
---|
| 53 | set_errno_and_return_minus_one( ENOTSUP ); |
---|
| 54 | |
---|
| 55 | rc = (*iop->handlers->read)( iop, buffer, count ); |
---|
| 56 | |
---|
| 57 | if ( rc > 0 ) |
---|
| 58 | iop->offset += rc; |
---|
| 59 | |
---|
| 60 | return rc; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /* |
---|
| 64 | * _read_r |
---|
| 65 | * |
---|
| 66 | * This is the Newlib dependent reentrant version of read(). |
---|
| 67 | */ |
---|
| 68 | |
---|
| 69 | #if defined(RTEMS_NEWLIB) |
---|
| 70 | |
---|
| 71 | #include <reent.h> |
---|
| 72 | |
---|
| 73 | _ssize_t _read_r( |
---|
| 74 | struct _reent *ptr, |
---|
| 75 | int fd, |
---|
| 76 | void *buf, |
---|
| 77 | size_t nbytes |
---|
| 78 | ) |
---|
| 79 | { |
---|
| 80 | return read( fd, buf, nbytes ); |
---|
| 81 | } |
---|
| 82 | #endif |
---|