8374945: Avoid fstat in os::open

Reviewed-by: dholmes, jsjolen, redestad
This commit is contained in:
Jonas Norlinder 2026-01-20 11:40:19 +00:00 committed by David Holmes
parent fe102918dd
commit 3cc713fa29

View File

@ -4963,9 +4963,14 @@ int os::open(const char *path, int oflag, int mode) {
oflag |= O_CLOEXEC;
int fd = ::open(path, oflag, mode);
if (fd == -1) return -1;
// No further checking is needed if open() returned an error or
// access mode is not read only.
if (fd == -1 || (oflag & O_ACCMODE) != O_RDONLY) {
return fd;
}
//If the open succeeded, the file might still be a directory
// If the open succeeded and is read only, the file might be a directory
// which the JVM doesn't allow to be read.
{
struct stat buf;
int ret = ::fstat(fd, &buf);