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

5
Last change on this file since baef823c was baef823c, checked in by Sebastian Huber <sebastian.huber@…>, on 09/13/17 at 07:22:19

libio: Add hold/drop iop reference

Check iop reference count in close() and return -1 with errno set to
EBUSY in case the file descriptor is still in use.

Update #3132.

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Read From a File
5 *  @ingroup libcsupport
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2011.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/libio_.h>
22#include <rtems/seterr.h>
23
24/**
25 *  POSIX 1003.1b 6.4.1 - Read From a File
26 */
27ssize_t read(
28  int         fd,
29  void       *buffer,
30  size_t      count
31)
32{
33  rtems_libio_t *iop;
34  ssize_t        n;
35
36  rtems_libio_check_buffer( buffer );
37  rtems_libio_check_count( count );
38
39  LIBIO_GET_IOP_WITH_ACCESS( fd, iop, LIBIO_FLAGS_READ, EBADF );
40
41  /*
42   *  Now process the read().
43   */
44  n = (*iop->pathinfo.handlers->read_h)( iop, buffer, count );
45  rtems_libio_iop_drop( iop );
46  return n;
47}
48
49#if defined(RTEMS_NEWLIB) && !defined(HAVE__READ_R)
50
51#include <reent.h>
52
53/**
54 *  This is the Newlib dependent reentrant version of read().
55 */
56ssize_t _read_r(
57  struct _reent *ptr RTEMS_UNUSED,
58  int            fd,
59  void          *buf,
60  size_t         nbytes
61)
62{
63  return read( fd, buf, nbytes );
64}
65#endif
Note: See TracBrowser for help on using the repository browser.