[07a3253d] | 1 | /* |
---|
| 2 | * stat() - POSIX 1003.1b 5.6.2 - Get File Status |
---|
| 3 | * |
---|
[933388ae] | 4 | * Reused from lstat(). |
---|
| 5 | * |
---|
[08311cc3] | 6 | * COPYRIGHT (c) 1989-1999. |
---|
[07a3253d] | 7 | * On-Line Applications Research Corporation (OAR). |
---|
| 8 | * |
---|
| 9 | * The license and distribution terms for this file may be |
---|
| 10 | * found in the file LICENSE in this distribution or at |
---|
| 11 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 12 | * |
---|
| 13 | * $Id$ |
---|
| 14 | */ |
---|
| 15 | |
---|
[9c49db4] | 16 | #if HAVE_CONFIG_H |
---|
| 17 | #include "config.h" |
---|
| 18 | #endif |
---|
| 19 | |
---|
[933388ae] | 20 | /* |
---|
| 21 | * lstat() and stat() share the same implementation with a minor |
---|
| 22 | * difference on how links are evaluated. |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #ifndef _STAT_NAME |
---|
| 26 | #define _STAT_NAME stat |
---|
| 27 | #define _STAT_R_NAME _stat_r |
---|
| 28 | #define _STAT_FOLLOW_LINKS TRUE |
---|
| 29 | #endif |
---|
| 30 | |
---|
| 31 | |
---|
[07a3253d] | 32 | #include <rtems.h> |
---|
| 33 | |
---|
| 34 | #if !defined(RTEMS_UNIX) |
---|
| 35 | |
---|
| 36 | #include <rtems/libio.h> |
---|
| 37 | #include <sys/types.h> |
---|
| 38 | #include <sys/stat.h> |
---|
| 39 | #include <unistd.h> |
---|
| 40 | #include <fcntl.h> |
---|
| 41 | #include <errno.h> |
---|
[29fd4e38] | 42 | #include <string.h> |
---|
[07a3253d] | 43 | |
---|
[3ba74c73] | 44 | #include <rtems/libio_.h> |
---|
[a02224e] | 45 | #include <rtems/seterr.h> |
---|
[07a3253d] | 46 | |
---|
[933388ae] | 47 | int _STAT_NAME( |
---|
[07a3253d] | 48 | const char *path, |
---|
| 49 | struct stat *buf |
---|
| 50 | ) |
---|
| 51 | { |
---|
| 52 | int status; |
---|
| 53 | rtems_filesystem_location_info_t loc; |
---|
| 54 | |
---|
| 55 | /* |
---|
| 56 | * Check to see if we were passed a valid pointer. |
---|
| 57 | */ |
---|
| 58 | |
---|
| 59 | if ( !buf ) |
---|
[a02224e] | 60 | rtems_set_errno_and_return_minus_one( EFAULT ); |
---|
[07a3253d] | 61 | |
---|
[933388ae] | 62 | status = rtems_filesystem_evaluate_path( path, 0, &loc, _STAT_FOLLOW_LINKS ); |
---|
[07a3253d] | 63 | if ( status != 0 ) |
---|
| 64 | return -1; |
---|
| 65 | |
---|
[9c3fa30] | 66 | if ( !loc.handlers->fstat_h ){ |
---|
[dd0f326] | 67 | rtems_filesystem_freenode( &loc ); |
---|
[a02224e] | 68 | rtems_set_errno_and_return_minus_one( ENOTSUP ); |
---|
[d71fcab] | 69 | } |
---|
[07a3253d] | 70 | |
---|
| 71 | /* |
---|
| 72 | * Zero out the stat structure so the various support |
---|
| 73 | * versions of stat don't have to. |
---|
| 74 | */ |
---|
| 75 | |
---|
| 76 | memset( buf, 0, sizeof(struct stat) ); |
---|
| 77 | |
---|
[9c3fa30] | 78 | status = (*loc.handlers->fstat_h)( &loc, buf ); |
---|
[d71fcab] | 79 | |
---|
[dd0f326] | 80 | rtems_filesystem_freenode( &loc ); |
---|
[d71fcab] | 81 | |
---|
| 82 | return status; |
---|
[07a3253d] | 83 | } |
---|
| 84 | #endif |
---|
| 85 | |
---|
| 86 | /* |
---|
[933388ae] | 87 | * _stat_r, _lstat_r |
---|
[07a3253d] | 88 | * |
---|
[933388ae] | 89 | * This is the Newlib dependent reentrant version of stat() and lstat(). |
---|
[07a3253d] | 90 | */ |
---|
| 91 | |
---|
| 92 | #if defined(RTEMS_NEWLIB) |
---|
| 93 | |
---|
| 94 | #include <reent.h> |
---|
| 95 | |
---|
[933388ae] | 96 | int _STAT_R_NAME( |
---|
[07a3253d] | 97 | struct _reent *ptr, |
---|
| 98 | const char *path, |
---|
| 99 | struct stat *buf |
---|
| 100 | ) |
---|
| 101 | { |
---|
[933388ae] | 102 | return _STAT_NAME( path, buf ); |
---|
[07a3253d] | 103 | } |
---|
| 104 | #endif |
---|