1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * fstat() - POSIX 1003.1b 5.6.2 - Get File Status |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-1999. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions |
---|
11 | * are met: |
---|
12 | * 1. Redistributions of source code must retain the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer. |
---|
14 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
15 | * notice, this list of conditions and the following disclaimer in the |
---|
16 | * documentation and/or other materials provided with the distribution. |
---|
17 | * |
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
28 | * POSSIBILITY OF SUCH DAMAGE. |
---|
29 | */ |
---|
30 | |
---|
31 | #ifdef HAVE_CONFIG_H |
---|
32 | #include "config.h" |
---|
33 | #endif |
---|
34 | |
---|
35 | #include <sys/stat.h> |
---|
36 | #include <unistd.h> |
---|
37 | #include <string.h> |
---|
38 | |
---|
39 | #include <rtems/libio_.h> |
---|
40 | #include <rtems/seterr.h> |
---|
41 | |
---|
42 | int fstat( |
---|
43 | int fd, |
---|
44 | struct stat *sbuf |
---|
45 | ) |
---|
46 | { |
---|
47 | rtems_libio_t *iop; |
---|
48 | int rv; |
---|
49 | |
---|
50 | /* |
---|
51 | * Check to see if we were passed a valid pointer. |
---|
52 | */ |
---|
53 | if ( !sbuf ) |
---|
54 | rtems_set_errno_and_return_minus_one( EFAULT ); |
---|
55 | |
---|
56 | /* |
---|
57 | * Now process the stat() request. |
---|
58 | */ |
---|
59 | LIBIO_GET_IOP( fd, iop ); |
---|
60 | |
---|
61 | /* |
---|
62 | * Zero out the stat structure so the various support |
---|
63 | * versions of stat don't have to. |
---|
64 | */ |
---|
65 | memset( sbuf, 0, sizeof(struct stat) ); |
---|
66 | |
---|
67 | rv = (*iop->pathinfo.handlers->fstat_h)( &iop->pathinfo, sbuf ); |
---|
68 | rtems_libio_iop_drop( iop ); |
---|
69 | return rv; |
---|
70 | } |
---|
71 | |
---|
72 | /* |
---|
73 | * _fstat_r |
---|
74 | * |
---|
75 | * This is the Newlib dependent reentrant version of fstat(). |
---|
76 | */ |
---|
77 | |
---|
78 | #if defined(RTEMS_NEWLIB) && !defined(HAVE_FSTAT_R) |
---|
79 | |
---|
80 | #include <reent.h> |
---|
81 | |
---|
82 | int _fstat_r( |
---|
83 | struct _reent *ptr RTEMS_UNUSED, |
---|
84 | int fd, |
---|
85 | struct stat *buf |
---|
86 | ) |
---|
87 | { |
---|
88 | return fstat( fd, buf ); |
---|
89 | } |
---|
90 | #endif |
---|