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 <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Eduardo Krell <ekrell@adexus.cl>                   *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma noprototyped
23 
24 #include "3d.h"
25 
26 /* the 3 arg _xstat() disrupts our proto game -- every party needs one */
27 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
stat3d(const char * path,struct stat * st)28 int stat3d(const char* path, struct stat* st)
29 #else
30 #if defined(_STAT)
31 int _stat(path, st) char* path; struct stat* st; { return stat(path, st); }
32 #endif
33 int stat(path, st) char* path; struct stat* st;
34 #endif
35 {
36 	register char*	sp;
37 #if FS
38 	Mount_t*	mp;
39 #endif
40 #ifdef _3D_STAT_VER
41 	struct stat*	so;
42 	struct stat	sc;
43 #endif
44 
45 #ifdef _3D_STAT_VER
46 	if (_3d_ver != _3D_STAT_VER)
47 	{
48 		so = st;
49 		st = &sc;
50 	}
51 #endif
52 #if FS
53 	if (!fscall(NiL, MSG_stat, 0, path, st))
54 		return state.ret;
55 	mp = monitored();
56 #endif
57 	if (!(sp = pathreal(path, 0, st)))
58 		return -1;
59 	if (S_ISLNK(st->st_mode))
60 	{
61 #ifdef _3D_STAT_VER
62 		if (st == &sc)
63 			st = so;
64 		if (XSTAT(_3d_ver, sp, st))
65 			return -1;
66 #ifdef _3D_STAT64_VER
67 		if (_3d_ver == _3D_STAT64_VER)
68 			IVIEW(((struct stat64*)st), state.path.level);
69 		else
70 #endif
71 #else
72 		if (STAT(sp, st))
73 			return -1;
74 #endif
75 		IVIEW(st, state.path.level);
76 	}
77 #if FS
78 	if (mp)
79 		fscall(mp, MSG_stat, 0, state.path.name, st);
80 	for (mp = state.global; mp; mp = mp->global)
81 		if (fssys(mp, MSG_stat))
82 			fscall(mp, MSG_stat, 0, state.path.name, st);
83 #endif
84 #ifdef _3D_STAT_VER
85 	if (st == &sc)
86 	{
87 		st = so;
88 		if (XSTAT(_3d_ver, sp, st))
89 			return -1;
90 #ifdef _3D_STAT64_VER
91 		if (_3d_ver == _3D_STAT64_VER)
92 			IVIEW(((struct stat64*)st), state.path.level);
93 		else
94 #endif
95 		IVIEW(st, state.path.level);
96 	}
97 #endif
98 #if _mem_d_type_dirent
99 	if (S_ISDIR(st->st_mode))
100 		st->st_nlink = _3D_LINK_MAX;
101 #endif
102 	return 0;
103 }
104 
105 #if defined(_LARGEFILE64_SOURCE) && defined(STAT643D) && !defined(_3D_STAT64_VER)
106 
107 int
stat643d(const char * path,struct stat64 * st)108 stat643d(const char* path, struct stat64* st)
109 {
110 	register char*	sp;
111 	struct stat	ss;
112 #if FS
113 	Mount_t*	mp;
114 
115 	if (!fscall(NiL, MSG_stat, 0, path, &ss))
116 		return state.ret;
117 	mp = monitored();
118 #endif
119 	if (!(sp = pathreal(path, 0, &ss)))
120 		return -1;
121 	if (STAT64(sp, st))
122 		return -1;
123 	IVIEW(st, state.path.level);
124 #if FS
125 	if (mp)
126 		fscall(mp, MSG_stat, 0, state.path.name, &ss);
127 	for (mp = state.global; mp; mp = mp->global)
128 		if (fssys(mp, MSG_stat))
129 			fscall(mp, MSG_stat, 0, state.path.name, &ss);
130 #endif
131 #if _mem_d_type_dirent
132 	if (S_ISDIR(st->st_mode))
133 		st->st_nlink = _3D_LINK_MAX;
134 #endif
135 	return 0;
136 }
137 
138 #endif
139