xref: /csrg-svn/usr.bin/f77/libU77/access_.c (revision 12140)
12404Sdlw /*
2*12140Sdlw char id_access[] = "@(#)access_.c	1.3";
32404Sdlw  *
42404Sdlw  * determine accessability of a file
52404Sdlw  *
62404Sdlw  * calling format:
72404Sdlw  *	integer access
82404Sdlw  *	ierror = access(filename, mode)
92404Sdlw  * where:
102404Sdlw  *	ierror will be 0 for successful access; an error number otherwise.
112404Sdlw  *	filename is a character string
122404Sdlw  *	mode is a character string which may include any combination of
132404Sdlw  *	'r', 'w', 'x', ' '. (' ' => test for existence)
142404Sdlw  */
152404Sdlw 
162404Sdlw #include "../libI77/f_errno.h"
17*12140Sdlw #include <sys/param.h>
18*12140Sdlw #ifndef	MAXPATHLEN
19*12140Sdlw #define MAXPATHLEN	128
20*12140Sdlw #endif
212404Sdlw 
222404Sdlw long access_(name, mode, namlen, modlen)
232404Sdlw char *name, *mode;
242404Sdlw long namlen, modlen;
252404Sdlw {
26*12140Sdlw 	char buf[MAXPATHLEN];
272404Sdlw 	int m = 0;
282404Sdlw 
292516Sdlw 	if (namlen >= sizeof buf)
302516Sdlw 		return((long)(errno=F_ERARG));
312404Sdlw 	g_char(name, namlen, buf);
322404Sdlw 	if (buf[0] == '\0')
332516Sdlw 		return((long)(errno=ENOENT));
342404Sdlw 	if (access(buf, 0) < 0)
352404Sdlw 		return((long)errno);
362404Sdlw 	while (modlen--) switch(*mode++)
372404Sdlw 	{
382404Sdlw 		case 'x':
392404Sdlw 			m |= 1;
402404Sdlw 			break;
412404Sdlw 
422404Sdlw 		case 'w':
432404Sdlw 			m |= 2;
442404Sdlw 			break;
452404Sdlw 
462404Sdlw 		case 'r':
472404Sdlw 			m |= 4;
482404Sdlw 			break;
492404Sdlw 	}
502404Sdlw 	if (m > 0 && access(buf, m) < 0)
512404Sdlw 		return((long)errno);
522404Sdlw 	return(0L);
532404Sdlw }
54