Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/3d/fstat3d.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1989-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* David Korn <[email protected]> *
19
* Eduardo Krell <[email protected]> *
20
* *
21
***********************************************************************/
22
#pragma noprototyped
23
24
#if defined(__STDPP__directive) && defined(__STDPP__hide)
25
__STDPP__directive pragma pp:hide fstat
26
#else
27
#define fstat ______fstat
28
#endif
29
30
#define _def_syscall_3d 1
31
32
#include "3d.h"
33
34
#undef _def_syscall_3d
35
36
#if defined(__STDPP__directive) && defined(__STDPP__hide)
37
__STDPP__directive pragma pp:nohide fstat
38
#else
39
#undef fstat
40
#endif
41
42
#include "FEATURE/syscall"
43
44
/* the 3 arg _fxstat() disrupts our proto game -- every party needs one */
45
#if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
46
int fstat3d(int fd, struct stat* st)
47
#else
48
#if defined(_FSTAT)
49
int _fstat(fd, st) int fd; struct stat* st; { return fstat(fd, st); }
50
#endif
51
int fstat(fd, st) int fd; struct stat* st;
52
#endif
53
{
54
int oerrno;
55
#if FS
56
Mount_t* mp;
57
58
if (!state.kernel)
59
{
60
if (!fscall(NiL, MSG_fstat, 0, fd, st))
61
return state.ret;
62
mp = monitored();
63
}
64
#endif
65
#ifdef _3D_STAT_VER
66
if (FXSTAT(_3d_ver, fd, st))
67
return -1;
68
#else
69
if (FSTAT(fd, st))
70
return -1;
71
#endif
72
#if _mem_d_type_dirent
73
if (S_ISDIR(st->st_mode))
74
st->st_nlink = _3D_LINK_MAX;
75
#endif
76
if (state.kernel)
77
return 0;
78
#if FS
79
if (mp)
80
fscall(mp, MSG_fstat, 0, fd, st);
81
for (mp = state.global; mp; mp = mp->global)
82
if (fssys(mp, MSG_fstat))
83
fscall(mp, MSG_fstat, 0, fd, st);
84
#endif
85
oerrno = errno;
86
#ifdef _3D_STAT64_VER
87
if (_3d_ver == _3D_STAT64_VER)
88
IVIEW(((struct stat64*)st), getfdview(fd));
89
else
90
#endif
91
IVIEW(st, getfdview(fd));
92
errno = oerrno;
93
return 0;
94
}
95
96
#if defined(_LARGEFILE64_SOURCE) && defined(STAT643D) && !defined(_3D_STAT64_VER)
97
98
int
99
fstat643d(int fd, struct stat64* st)
100
{
101
int oerrno;
102
struct stat ss;
103
#if FS
104
Mount_t* mp;
105
106
if (!state.kernel)
107
{
108
if (!fscall(NiL, MSG_fstat, 0, fd, &ss))
109
return state.ret;
110
mp = monitored();
111
}
112
#endif
113
if (FSTAT64(fd, st))
114
return -1;
115
#if _mem_d_type_dirent
116
if (S_ISDIR(st->st_mode))
117
st->st_nlink = _3D_LINK_MAX;
118
#endif
119
if (state.kernel)
120
return 0;
121
#if FS
122
if (mp)
123
fscall(mp, MSG_fstat, 0, fd, st);
124
for (mp = state.global; mp; mp = mp->global)
125
if (fssys(mp, MSG_fstat))
126
fscall(mp, MSG_fstat, 0, fd, st);
127
#endif
128
oerrno = errno;
129
IVIEW(st, getfdview(fd));
130
errno = oerrno;
131
return 0;
132
}
133
134
#endif
135
136