source: rtems/cpukit/libcsupport/src/read.c @ cca4400

4.104.114.84.9
Last change on this file since cca4400 was cca4400, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 10, 1998 at 11:31:54 PM

Merged Eric Norum's select patch that was based on 4.0 and resolved
all conflicts.

  • Property mode set to 100644
File size: 1.8 KB
Line 
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
17/* XXX newlib has the prototype for this wrong.  It will be a bit painful */
18/* XXX to fix so we are choosing to delay fixing this. */
19
20int read(
21  int         fd,
22  void       *buffer,
23  unsigned32  count
24)
25{
26  int             rc;  /* XXX change to a size_t when prototype is fixed */
27  rtems_libio_t *iop;
28
29  rtems_libio_check_fd( fd );
30  iop = rtems_libio_iop( fd );
31  rtems_libio_check_buffer( buffer );
32  rtems_libio_check_count( count );
33  rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
34
35  /*
36   *  If this file descriptor is mapped to an external set of handlers,
37   *  then pass the request on to them.
38   */ 
39
40  if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
41    rtems_libio_read_t fp;
42
43    fp = rtems_libio_handlers[
44           (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read;
45    if ( fp == NULL )
46      set_errno_and_return_minus_one( EBADF );
47
48    return (*fp)( fd, buffer, count );
49  }
50
51  /*
52   *  Now process the read().
53   */
54
55  if ( !iop->handlers->read )
56    set_errno_and_return_minus_one( ENOTSUP );
57
58  rc = (*iop->handlers->read)( iop, buffer, count );
59
60  if ( rc > 0 )
61    iop->offset += rc;
62
63  return rc;
64}
65
66/*
67 *  _read_r
68 *
69 *  This is the Newlib dependent reentrant version of read().
70 */
71
72#if defined(RTEMS_NEWLIB)
73
74#include <reent.h>
75
76_ssize_t _read_r(
77  struct _reent *ptr,
78  int            fd,
79  void          *buf,
80  size_t         nbytes
81)
82{
83  return read( fd, buf, nbytes );
84}
85#endif
Note: See TracBrowser for help on using the repository browser.