Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/3d/access3d.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 prototyped
23
24
#include "3d.h"
25
26
int
27
access3d(const char* path, int mode)
28
{
29
register char* sp;
30
mode_t test;
31
struct stat st;
32
33
#if FS
34
if (!fscall(NiL, MSG_stat, 0, path, &st))
35
{
36
if (state.ret) return(-1);
37
sp = 0;
38
}
39
else
40
#endif
41
if (!(sp = pathreal(path, 0, &st)))
42
return(-1);
43
44
/*
45
* handle some frequent cases separately
46
*/
47
48
switch (mode)
49
{
50
case F_OK:
51
return(0);
52
case R_OK:
53
if ((st.st_mode&(S_IRUSR|S_IRGRP|S_IROTH)) == (S_IRUSR|S_IRGRP|S_IROTH))
54
return(0);
55
break;
56
case W_OK:
57
if (state.path.level && (st.st_mode&(S_IWUSR|S_IWGRP|S_IWOTH)) && !ACCESS(sp, R_OK))
58
return(0);
59
break;
60
case X_OK:
61
if ((st.st_mode&(S_IXUSR|S_IXGRP|S_IXOTH)) == (S_IXUSR|S_IXGRP|S_IXOTH))
62
return(0);
63
break;
64
}
65
#if FS
66
if (sp)
67
#endif
68
return(ACCESS(sp, mode));
69
#if FS
70
71
/*
72
* simulate access()
73
*/
74
75
if (mode & (R_OK|W_OK|X_OK))
76
{
77
test = 0;
78
if (st.st_uid == state.uid)
79
{
80
if (mode & R_OK) test |= S_IRUSR;
81
if (mode & W_OK) test |= S_IWUSR;
82
if (mode & X_OK) test |= S_IXUSR;
83
}
84
else if (st.st_gid == state.gid)
85
{
86
if (mode & R_OK) test |= S_IRGRP;
87
if (mode & W_OK) test |= S_IWGRP;
88
if (mode & X_OK) test |= S_IXGRP;
89
}
90
else
91
{
92
if (mode & R_OK) test |= S_IROTH;
93
if (mode & W_OK) test |= S_IWOTH;
94
if (mode & X_OK) test |= S_IXOTH;
95
}
96
if ((st.st_mode & test) != test)
97
{
98
errno = EACCES;
99
return(-1);
100
}
101
}
102
return(0);
103
#endif
104
}
105
106