Subversion Repositories Kolibri OS

Rev

Rev 4872 | Rev 4921 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
/* Reentrant versions of fstat system call.  This implementation just
2
   calls the fstat system call.  */
3
 
4
#include 
5
#include 
6
#include 
7
#include <_syslist.h>
8
#include 
9
#include 
10
 
11
 
12
/* Some targets provides their own versions of these functions.  Those
13
   targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS.  */
14
 
15
#ifdef _REENT_ONLY
16
#ifndef REENTRANT_SYSCALLS_PROVIDED
17
#define REENTRANT_SYSCALLS_PROVIDED
18
#endif
19
#endif
20
 
21
#ifdef REENTRANT_SYSCALLS_PROVIDED
22
 
23
int _dummy_fstat_syscalls = 1;
24
 
25
#else
26
 
27
/* We use the errno variable used by the system dependent layer.  */
28
 
29
/*
30
FUNCTION
31
	<<_fstat_r>>---Reentrant version of fstat
32
 
33
INDEX
34
	_fstat_r
35
 
36
ANSI_SYNOPSIS
37
	#include 
38
	int _fstat_r(struct _reent *<[ptr]>,
39
		     int <[fd]>, struct stat *<[pstat]>);
40
 
41
TRAD_SYNOPSIS
42
	#include 
43
	int _fstat_r(<[ptr]>, <[fd]>, <[pstat]>)
44
	struct _reent *<[ptr]>;
45
	int <[fd]>;
46
	struct stat *<[pstat]>;
47
 
48
DESCRIPTION
49
	This is a reentrant version of <>.  It
50
	takes a pointer to the global data block, which holds
51
	<>.
52
*/
53
 
54
#pragma pack(push, 1)
55
typedef struct
56
{
57
  char sec;
58
  char min;
59
  char hour;
60
  char rsv;
61
}detime_t;
62
 
63
typedef struct
64
{
65
  char  day;
66
  char  month;
67
  short year;
68
}dedate_t;
69
 
70
typedef struct
71
{
72
  unsigned    attr;
73
  unsigned    flags;
74
  union
75
  {
76
     detime_t  ctime;
77
     unsigned  cr_time;
78
  };
79
  union
80
  {
81
     dedate_t  cdate;
82
     unsigned  cr_date;
83
  };
84
  union
85
  {
86
     detime_t  atime;
87
     unsigned  acc_time;
88
  };
89
  union
90
  {
91
     dedate_t  adate;
92
     unsigned  acc_date;
93
  };
94
  union
95
  {
96
     detime_t  mtime;
97
     unsigned  mod_time;
98
  };
99
  union
100
  {
101
     dedate_t  mdate;
102
     unsigned  mod_date;
103
  };
104
  unsigned    size;
105
  unsigned    size_high;
106
} FILEINFO;
107
 
108
#pragma pack(pop)
109
 
110
extern unsigned  __NFiles;
111
 
112
#define __handle_check( __h, __r )                \
113
        if( (__h) < 0  ||  (__h) > __NFiles ) {   \
114
           ptr->_errno =  EBADF ;                 \
115
           return( __r );                         \
116
        }
117
 
118
int
119
_fstat_r (ptr, fd, pstat)
120
     struct _reent *ptr;
121
     int fd;
122
     struct stat *pstat;
123
{
124
    FILEINFO info;
125
    int ret;
126
 
127
    __file_handle *fh;
128
 
129
    __handle_check( fd, -1 );
130
 
131
    if (fd < 3)
132
    {
133
      pstat->st_mode = S_IFCHR;
134
      pstat->st_blksize = 0;
135
      return 0;
136
    }
137
 
138
    fh = (__file_handle*) __getOSHandle( fd );
139
    get_fileinfo(fh->name, &info);
140
 
141
    memset (pstat, 0, sizeof (* pstat));
142
    pstat->st_mode = S_IFREG;
143
    pstat->st_blksize = 4096;
144
    pstat->st_size = info.size;
145
    return 0;
146
}
147
 
148
int
149
_DEFUN (fstat, (fd, pstat),
150
     int fd _AND
151
     struct stat *pstat)
152
{
153
  return _fstat_r (_REENT, fd, pstat);
154
}
155
 
156
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */