From 216a3935c9490ae60f7f80f7dd32c2422e06a72c Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Mon, 11 Jul 2011 15:30:24 +0000 Subject: [PATCH] second attempt at correcting fopen (hangs when trying to read from a dir) Review URL: http://codereview.chromium.org/7334010 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8611 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/platform-posix.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/platform-posix.cc b/src/platform-posix.cc index 83f6c81..7082589 100644 --- a/src/platform-posix.cc +++ b/src/platform-posix.cc @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -130,7 +131,14 @@ int OS::GetLastError() { // FILE* OS::FOpen(const char* path, const char* mode) { - return fopen(path, mode); + FILE* file = fopen(path, mode); + if (file == NULL) return NULL; + struct stat file_stat; + if (fstat(fileno(file), &file_stat) != 0) return NULL; + bool is_regular_file = ((file_stat.st_mode & S_IFREG) != 0); + if (is_regular_file) return file; + fclose(file); + return NULL; } -- 2.7.4