Index: runtime/bin/file_macos.cc |
diff --git a/runtime/bin/file_macos.cc b/runtime/bin/file_macos.cc |
index 9b7093daff51e3fe6336ad217173c90e1ee9c5e3..44fe08d50fd338a775857094995528450ff0ad1f 100644 |
--- a/runtime/bin/file_macos.cc |
+++ b/runtime/bin/file_macos.cc |
@@ -106,6 +106,13 @@ off_t File::Length() { |
File* File::Open(const char* name, FileOpenMode mode) { |
+ struct stat st; |
+ if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
+ if (!S_ISREG(st.st_mode)) { |
+ errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
+ return false; |
+ } |
+ } |
int flags = O_RDONLY; |
if ((mode & kWrite) != 0) { |
flags = (O_RDWR | O_CREAT); |
@@ -185,6 +192,15 @@ char* File::GetCanonicalPath(const char* pathname) { |
char* File::GetContainingDirectory(char* pathname) { |
+ struct stat st; |
+ if (TEMP_FAILURE_RETRY(stat(pathname, &st)) == 0) { |
+ if (!S_ISREG(st.st_mode)) { |
+ errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
+ return NULL; |
+ } |
+ } else { |
+ return NULL; |
+ } |
char* path = NULL; |
do { |
path = dirname(pathname); |