fix a bug where `which' doesn't check whether the file passed as an argument

is a regular file, patch by Arthur Othieno
This commit is contained in:
Glenn L McGrath 2003-10-29 04:50:35 +00:00
parent 6530f0d3a1
commit 984b45142a

View File

@ -30,7 +30,9 @@ static int file_exists(char *file)
{
struct stat filestat;
if (stat(file, &filestat) == 0 && filestat.st_mode & S_IXUSR)
if (stat(file, &filestat) == 0 &&
S_ISREG(filestat.st_mode) &&
filestat.st_mode & S_IXUSR)
return 1;
else
return 0;