source: rtems/cpukit/libcsupport/src/fstat.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.3 KB
Line 
1/*
2 *  fstat() - POSIX 1003.1b 5.6.2 - Get File Status
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.org/license/LICENSE.
10 */
11
12#if HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <sys/stat.h>
17#include <unistd.h>
18#include <string.h>
19
20#include <rtems/libio_.h>
21#include <rtems/seterr.h>
22
23int fstat(
24  int          fd,
25  struct stat *sbuf
26)
27{
28  rtems_libio_t *iop;
29  int            rv;
30
31  /*
32   *  Check to see if we were passed a valid pointer.
33   */
34  if ( !sbuf )
35    rtems_set_errno_and_return_minus_one( EFAULT );
36
37  /*
38   *  Now process the stat() request.
39   */
40  LIBIO_GET_IOP( fd, iop );
41
42  /*
43   *  Zero out the stat structure so the various support
44   *  versions of stat don't have to.
45   */
46  memset( sbuf, 0, sizeof(struct stat) );
47
48  rv = (*iop->pathinfo.handlers->fstat_h)( &iop->pathinfo, sbuf );
49  rtems_libio_iop_drop( iop );
50  return rv;
51}
52
53/*
54 *  _fstat_r
55 *
56 *  This is the Newlib dependent reentrant version of fstat().
57 */
58
59#if defined(RTEMS_NEWLIB) && !defined(HAVE_FSTAT_R)
60
61#include <reent.h>
62
63int _fstat_r(
64  struct _reent *ptr RTEMS_UNUSED,
65  int            fd,
66  struct stat   *buf
67)
68{
69  return fstat( fd, buf );
70}
71#endif
Note: See TracBrowser for help on using the repository browser.