mksh/mksh.logging/exec.c
int
search_access(const char *fn, int mode)
{
	struct stat sb;

	if (stat(fn, &sb) < 0)
		/* file does not exist */
		return (ENOENT);
	/* LINTED use of access */
	if (access(fn, mode) < 0) {
		/* file exists, but we can't access it */
		int eno;

		eno = errno;
		return (eno ? eno : EACCES);
	}
	if (mode == X_OK && (!S_ISREG(sb.st_mode) ||
	    !(sb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH))))
		/* access(2) may say root can execute everything */
		return (S_ISDIR(sb.st_mode) ? EISDIR : EACCES);
	return (0);
}
/* check if path is something we want to find */
check if path is something we want to find
check if path is something we want to find
int
search_access(const char *fn, int mode)
{
	struct stat sb;
	if (stat(fn, &sb) < 0)
		return (ENOENT);
	if (access(fn, mode) < 0) {
		int eno;
		eno = errno;
		return (eno ? eno : EACCES);
	}
	if (mode == X_OK && (!S_ISREG(sb.st_mode) ||
	    !(sb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH))))
		return (S_ISDIR(sb.st_mode) ? EISDIR : EACCES);
	return (0);
}
int search_access ( const char * fn , int mode ) { struct stat sb ; if ( stat ( fn , & sb ) < 0 ) return ( ENOENT ) ; if ( access ( fn , mode ) < 0 ) { int eno ; eno = errno ; return ( eno ? eno : EACCES ) ; } if ( mode == X_OK && ( ! S_ISREG ( sb . st_mode ) || ! ( sb . st_mode & ( S_IXUSR | S_IXGRP | S_IXOTH ) ) ) ) return ( S_ISDIR ( sb . st_mode ) ? EISDIR : EACCES ) ; return ( 0 ) ; }
check if path is something we want to find
check if path is something we want to find
/* file does not exist */ /* LINTED use of access */ /* file exists, but we can't access it */ /* access(2) may say root can execute everything */