source: rtems/c/src/lib/libc/stat.c @ 458bd34

4.104.114.84.95
Last change on this file since 458bd34 was dd0f326, checked in by Joel Sherrill <joel.sherrill@…>, on 10/12/99 at 19:10:46

Added rtems_filesystem_freenode() macro and added calls at appropriate
places to make sure memory allocated for filesystem specifif nodes
gets freed.

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