Revision: 8611
Author:   [email protected]
Date:     Mon Jul 11 08:30:24 2011
Log: second attempt at correcting fopen (hangs when trying to read from a dir)

Review URL: http://codereview.chromium.org/7334010
http://code.google.com/p/v8/source/detail?r=8611

Modified:
 /branches/bleeding_edge/src/platform-posix.cc

=======================================
--- /branches/bleeding_edge/src/platform-posix.cc       Mon Jul 11 07:08:27 2011
+++ /branches/bleeding_edge/src/platform-posix.cc       Mon Jul 11 08:30:24 2011
@@ -37,6 +37,7 @@
 #include <sys/resource.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#include <sys/stat.h>

 #include <arpa/inet.h>
 #include <netinet/in.h>
@@ -130,7 +131,14 @@
 //

 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;
 }


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to