source: rtems/c/src/lib/libc/read.c @ 07a3253d

4.104.114.84.95
Last change on this file since 07a3253d was 07a3253d, checked in by Joel Sherrill <joel.sherrill@…>, on 11/23/98 at 19:07:58

Added base version of file system infrastructure. This includes a major
overhaul of the RTEMS system call interface. This base file system is
the "In-Memory File System" aka IMFS.

The design and implementation was done by the following people:

+ Joel Sherrill (joel@…)
+ Jennifer Averett (jennifer@…)
+ Steve "Mr Mount" Salitasc (salitasc@…)
+ Kerwin Wade (wade@…)

PROBLEMS
========

+ It is VERY likely that merging this will break the UNIX port. This

can/will be fixed.

+ There is likely some reentrancy/mutual exclusion needed.

+ Eventually, there should be a "mini-IMFS" description table to

eliminate links, symlinks, etc to save memory. All you need to
have "classic RTEMS" functionality is technically directories
and device IO. All the rest could be left out to save memory.

  • 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  /*
30   *  If this file descriptor is mapped to an external set of handlers,
31   *  then pass the request on to them.
32   */
33
34  if ( rtems_file_descriptor_type( fd ) ) {
35    rtems_libio_read_t fp;
36
37    fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].read;
38    if ( fp == NULL )
39      set_errno_and_return_minus_one( EBADF );
40
41    return (*fp)( fd, buffer, count );
42  }
43
44  /*
45   *  Now process the read().
46   */
47
48  iop = rtems_libio_iop( fd );
49  rtems_libio_check_fd( fd );
50  rtems_libio_check_buffer( buffer );
51  rtems_libio_check_count( count );
52  rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
53
54  if ( !iop->handlers->read )
55    set_errno_and_return_minus_one( ENOTSUP );
56
57  rc = (*iop->handlers->read)( iop, buffer, count );
58
59  if ( rc > 0 )
60    iop->offset += rc;
61
62  return rc;
63}
64
65/*
66 *  _read_r
67 *
68 *  This is the Newlib dependent reentrant version of read().
69 */
70
71#if defined(RTEMS_NEWLIB)
72
73#include <reent.h>
74
75_ssize_t _read_r(
76  struct _reent *ptr,
77  int            fd,
78  void          *buf,
79  size_t         nbytes
80)
81{
82  return read( fd, buf, nbytes );
83}
84#endif
Note: See TracBrowser for help on using the repository browser.