xref: /csrg-svn/usr.bin/f77/libU77/access_.c (revision 47944)
1*47944Sbostic /*-
2*47944Sbostic  * Copyright (c) 1980 The Regents of the University of California.
3*47944Sbostic  * All rights reserved.
42404Sdlw  *
5*47944Sbostic  * %sccs.include.proprietary.c%
623003Skre  */
723003Skre 
8*47944Sbostic #ifndef lint
9*47944Sbostic static char sccsid[] = "@(#)access_.c	5.2 (Berkeley) 04/12/91";
10*47944Sbostic #endif /* not lint */
11*47944Sbostic 
1223003Skre /*
132404Sdlw  * determine accessability of a file
142404Sdlw  *
152404Sdlw  * calling format:
162404Sdlw  *	integer access
172404Sdlw  *	ierror = access(filename, mode)
182404Sdlw  * where:
192404Sdlw  *	ierror will be 0 for successful access; an error number otherwise.
202404Sdlw  *	filename is a character string
212404Sdlw  *	mode is a character string which may include any combination of
222404Sdlw  *	'r', 'w', 'x', ' '. (' ' => test for existence)
232404Sdlw  */
242404Sdlw 
252404Sdlw #include "../libI77/f_errno.h"
2612140Sdlw #include <sys/param.h>
2712140Sdlw #ifndef	MAXPATHLEN
2812140Sdlw #define MAXPATHLEN	128
2912140Sdlw #endif
302404Sdlw 
access_(name,mode,namlen,modlen)312404Sdlw long access_(name, mode, namlen, modlen)
322404Sdlw char *name, *mode;
332404Sdlw long namlen, modlen;
342404Sdlw {
3512140Sdlw 	char buf[MAXPATHLEN];
362404Sdlw 	int m = 0;
372404Sdlw 
382516Sdlw 	if (namlen >= sizeof buf)
392516Sdlw 		return((long)(errno=F_ERARG));
402404Sdlw 	g_char(name, namlen, buf);
412404Sdlw 	if (buf[0] == '\0')
422516Sdlw 		return((long)(errno=ENOENT));
432404Sdlw 	if (access(buf, 0) < 0)
442404Sdlw 		return((long)errno);
452404Sdlw 	while (modlen--) switch(*mode++)
462404Sdlw 	{
472404Sdlw 		case 'x':
482404Sdlw 			m |= 1;
492404Sdlw 			break;
502404Sdlw 
512404Sdlw 		case 'w':
522404Sdlw 			m |= 2;
532404Sdlw 			break;
542404Sdlw 
552404Sdlw 		case 'r':
562404Sdlw 			m |= 4;
572404Sdlw 			break;
582404Sdlw 	}
592404Sdlw 	if (m > 0 && access(buf, m) < 0)
602404Sdlw 		return((long)errno);
612404Sdlw 	return(0L);
622404Sdlw }
63