1 /*-
2 * Copyright (c) 1980 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.proprietary.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)access_.c 5.2 (Berkeley) 04/12/91";
10 #endif /* not lint */
11
12 /*
13 * determine accessability of a file
14 *
15 * calling format:
16 * integer access
17 * ierror = access(filename, mode)
18 * where:
19 * ierror will be 0 for successful access; an error number otherwise.
20 * filename is a character string
21 * mode is a character string which may include any combination of
22 * 'r', 'w', 'x', ' '. (' ' => test for existence)
23 */
24
25 #include "../libI77/f_errno.h"
26 #include <sys/param.h>
27 #ifndef MAXPATHLEN
28 #define MAXPATHLEN 128
29 #endif
30
access_(name,mode,namlen,modlen)31 long access_(name, mode, namlen, modlen)
32 char *name, *mode;
33 long namlen, modlen;
34 {
35 char buf[MAXPATHLEN];
36 int m = 0;
37
38 if (namlen >= sizeof buf)
39 return((long)(errno=F_ERARG));
40 g_char(name, namlen, buf);
41 if (buf[0] == '\0')
42 return((long)(errno=ENOENT));
43 if (access(buf, 0) < 0)
44 return((long)errno);
45 while (modlen--) switch(*mode++)
46 {
47 case 'x':
48 m |= 1;
49 break;
50
51 case 'w':
52 m |= 2;
53 break;
54
55 case 'r':
56 m |= 4;
57 break;
58 }
59 if (m > 0 && access(buf, m) < 0)
60 return((long)errno);
61 return(0L);
62 }
63