Commit | Line | Data |
---|---|---|
39a6d231 | 1 | /* |
31a3832d | 2 | char id_access[] = "@(#)access_.c 1.2"; |
39a6d231 DW |
3 | * |
4 | * determine accessability of a file | |
5 | * | |
6 | * calling format: | |
7 | * integer access | |
8 | * ierror = access(filename, mode) | |
9 | * where: | |
10 | * ierror will be 0 for successful access; an error number otherwise. | |
11 | * filename is a character string | |
12 | * mode is a character string which may include any combination of | |
13 | * 'r', 'w', 'x', ' '. (' ' => test for existence) | |
14 | */ | |
15 | ||
16 | #include "../libI77/f_errno.h" | |
17 | ||
18 | long access_(name, mode, namlen, modlen) | |
19 | char *name, *mode; | |
20 | long namlen, modlen; | |
21 | { | |
22 | char buf[128]; | |
23 | int m = 0; | |
24 | ||
31a3832d DW |
25 | if (namlen >= sizeof buf) |
26 | return((long)(errno=F_ERARG)); | |
39a6d231 DW |
27 | g_char(name, namlen, buf); |
28 | if (buf[0] == '\0') | |
31a3832d | 29 | return((long)(errno=ENOENT)); |
39a6d231 DW |
30 | if (access(buf, 0) < 0) |
31 | return((long)errno); | |
32 | while (modlen--) switch(*mode++) | |
33 | { | |
34 | case 'x': | |
35 | m |= 1; | |
36 | break; | |
37 | ||
38 | case 'w': | |
39 | m |= 2; | |
40 | break; | |
41 | ||
42 | case 'r': | |
43 | m |= 4; | |
44 | break; | |
45 | } | |
46 | if (m > 0 && access(buf, m) < 0) | |
47 | return((long)errno); | |
48 | return(0L); | |
49 | } |