зеркало из https://github.com/mozilla/pjs.git
Bugzilla Bug 276587: use stat to implement _MD_access because access is
broken. The patch is contributed by tqh <thesuckiestemail@yahoo.se>. r=wtc
This commit is contained in:
Родитель
f08923d0ba
Коммит
0e71cea939
|
@ -484,31 +484,38 @@ PRInt32
|
|||
_MD_access (const char *name, PRIntn how)
|
||||
{
|
||||
PRInt32 rv, err;
|
||||
int amode;
|
||||
int checkFlags;
|
||||
struct stat buf;
|
||||
|
||||
switch (how) {
|
||||
case PR_ACCESS_WRITE_OK:
|
||||
amode = W_OK;
|
||||
checkFlags = S_IWUSR | S_IWGRP | S_IWOTH;
|
||||
break;
|
||||
|
||||
case PR_ACCESS_READ_OK:
|
||||
amode = R_OK;
|
||||
checkFlags = S_IRUSR | S_IRGRP | S_IROTH;
|
||||
break;
|
||||
|
||||
case PR_ACCESS_EXISTS:
|
||||
amode = F_OK;
|
||||
/* we don't need to examine st_mode. */
|
||||
break;
|
||||
|
||||
default:
|
||||
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
|
||||
rv = -1;
|
||||
goto done;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = stat(name, &buf);
|
||||
if (rv == 0 && how != PR_ACCESS_EXISTS && (!(buf.st_mode & checkFlags))) {
|
||||
PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, 0);
|
||||
return -1;
|
||||
}
|
||||
rv = access(name, amode);
|
||||
|
||||
if (rv < 0) {
|
||||
err = _MD_ERRNO();
|
||||
_PR_MD_MAP_ACCESS_ERROR(err);
|
||||
_PR_MD_MAP_STAT_ERROR(err);
|
||||
}
|
||||
|
||||
done:
|
||||
return(rv);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче