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