Chromium Code Reviews| Index: runtime/bin/file_macos.cc |
| diff --git a/runtime/bin/file_macos.cc b/runtime/bin/file_macos.cc |
| index 6187e946a31e4c9161515f1454c6bf9346286d45..1211fad7c2c3eb783ded4ca6ec96515dc2bc03e7 100644 |
| --- a/runtime/bin/file_macos.cc |
| +++ b/runtime/bin/file_macos.cc |
| @@ -114,7 +114,7 @@ bool File::Flush() { |
| bool File::Lock(File::LockType lock, int64_t start, int64_t end) { |
| ASSERT(handle_->fd() >= 0); |
| - ASSERT(end == -1 || end > start); |
| + ASSERT((end == -1) || (end > start)); |
| struct flock fl; |
| switch (lock) { |
| case File::kLockUnlock: |
| @@ -148,7 +148,13 @@ int64_t File::Length() { |
| } |
| -File* File::Open(const char* name, FileOpenMode mode) { |
| +File* File::FileOpenW(const wchar_t* system_name, FileOpenMode mode) { |
| + UNREACHABLE(); |
| + return NULL; |
| +} |
| + |
| + |
| +File* File::ScopedOpen(const char* name, FileOpenMode mode) { |
| // Report errors for non-regular files. |
| struct stat st; |
| if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
| @@ -186,8 +192,16 @@ File* File::Open(const char* name, FileOpenMode mode) { |
| } |
| +File* File::Open(const char* path, FileOpenMode mode) { |
| + // ScopedOpen doesn't actually need a scope. |
| + return ScopedOpen(path, mode); |
| +} |
| + |
| + |
| File* File::OpenStdio(int fd) { |
| - if (fd < 0 || 2 < fd) return NULL; |
| + if ((fd < 0) || (2 < fd)) { |
| + return NULL; |
| + } |
| return new File(new FileHandle(fd)); |
| } |
| @@ -329,9 +343,11 @@ time_t File::LastModified(const char* name) { |
| } |
| -char* File::LinkTarget(const char* pathname) { |
| +const char* File::LinkTarget(const char* pathname) { |
| struct stat link_stats; |
| - if (lstat(pathname, &link_stats) != 0) return NULL; |
| + if (lstat(pathname, &link_stats) != 0) { |
| + return NULL; |
| + } |
| if (!S_ISLNK(link_stats.st_mode)) { |
| errno = ENOENT; |
| return NULL; |
| @@ -345,10 +361,8 @@ char* File::LinkTarget(const char* pathname) { |
| if (target_size <= 0) { |
| return NULL; |
| } |
| - char* target_name = reinterpret_cast<char*>(malloc(target_size + 1)); |
| - if (target_name == NULL) { |
| - return NULL; |
| - } |
| + char* target_name = DartUtils::ScopedCString(target_size + 1); |
| + ASSERT(target_name != NULL); |
| memmove(target_name, target, target_size); |
| target_name[target_size] = '\0'; |
| return target_name; |
| @@ -360,19 +374,19 @@ bool File::IsAbsolutePath(const char* pathname) { |
| } |
| -char* File::GetCanonicalPath(const char* pathname) { |
| +const char* File::GetCanonicalPath(const char* pathname) { |
| char* abs_path = NULL; |
| if (pathname != NULL) { |
| // On some older MacOs versions the default behaviour of realpath allocating |
| // space for the resolved_path when a NULL is passed in does not seem to |
| - // work, so we explicitly allocate space. The caller is responsible for |
| - // freeing this space as in a regular realpath call. |
| - char* resolved_path = reinterpret_cast<char*>(malloc(PATH_MAX + 1)); |
|
zra
2016/03/11 23:55:50
leaks resolved_path (never gets passed to realpath
|
| + // work, so we explicitly allocate space. |
| + char* resolved_path = DartUtils::ScopedCString(PATH_MAX + 1); |
| ASSERT(resolved_path != NULL); |
| do { |
| - abs_path = realpath(pathname, NULL); |
| - } while (abs_path == NULL && errno == EINTR); |
| - ASSERT(abs_path == NULL || IsAbsolutePath(abs_path)); |
| + abs_path = realpath(pathname, resolved_path); |
| + } while ((abs_path == NULL) && (errno == EINTR)); |
| + ASSERT((abs_path == NULL) || IsAbsolutePath(abs_path)); |
| + ASSERT((abs_path == NULL) || (abs_path == resolved_path)); |
| } |
| return abs_path; |
| } |
| @@ -389,7 +403,7 @@ const char* File::StringEscapedPathSeparator() { |
| File::StdioHandleType File::GetStdioHandleType(int fd) { |
| - ASSERT(0 <= fd && fd <= 2); |
| + ASSERT((0 <= fd) && (fd <= 2)); |
| struct stat buf; |
| int result = fstat(fd, &buf); |
| if (result == -1) { |
| @@ -398,10 +412,18 @@ File::StdioHandleType File::GetStdioHandleType(int fd) { |
| Utils::StrError(errno, error_message, kBufferSize); |
| FATAL2("Failed stat on file descriptor %d: %s", fd, error_message); |
| } |
| - if (S_ISCHR(buf.st_mode)) return kTerminal; |
| - if (S_ISFIFO(buf.st_mode)) return kPipe; |
| - if (S_ISSOCK(buf.st_mode)) return kSocket; |
| - if (S_ISREG(buf.st_mode)) return kFile; |
| + if (S_ISCHR(buf.st_mode)) { |
| + return kTerminal; |
| + } |
| + if (S_ISFIFO(buf.st_mode)) { |
| + return kPipe; |
| + } |
| + if (S_ISSOCK(buf.st_mode)) { |
| + return kSocket; |
| + } |
| + if (S_ISREG(buf.st_mode)) { |
| + return kFile; |
| + } |
| return kOther; |
| } |
| @@ -414,10 +436,18 @@ File::Type File::GetType(const char* pathname, bool follow_links) { |
| } else { |
| stat_success = NO_RETRY_EXPECTED(lstat(pathname, &entry_info)); |
| } |
| - if (stat_success == -1) return File::kDoesNotExist; |
| - if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; |
| - if (S_ISREG(entry_info.st_mode)) return File::kIsFile; |
| - if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; |
| + if (stat_success == -1) { |
| + return File::kDoesNotExist; |
| + } |
| + if (S_ISDIR(entry_info.st_mode)) { |
| + return File::kIsDirectory; |
| + } |
| + if (S_ISREG(entry_info.st_mode)) { |
| + return File::kIsFile; |
| + } |
| + if (S_ISLNK(entry_info.st_mode)) { |
| + return File::kIsLink; |
| + } |
| return File::kDoesNotExist; |
| } |
| @@ -425,12 +455,12 @@ File::Type File::GetType(const char* pathname, bool follow_links) { |
| File::Identical File::AreIdentical(const char* file_1, const char* file_2) { |
| struct stat file_1_info; |
| struct stat file_2_info; |
| - if (NO_RETRY_EXPECTED(lstat(file_1, &file_1_info)) == -1 || |
| - NO_RETRY_EXPECTED(lstat(file_2, &file_2_info)) == -1) { |
| + if ((NO_RETRY_EXPECTED(lstat(file_1, &file_1_info)) == -1) || |
| + (NO_RETRY_EXPECTED(lstat(file_2, &file_2_info)) == -1)) { |
| return File::kError; |
| } |
| - return (file_1_info.st_ino == file_2_info.st_ino && |
| - file_1_info.st_dev == file_2_info.st_dev) ? |
| + return ((file_1_info.st_ino == file_2_info.st_ino) && |
| + (file_1_info.st_dev == file_2_info.st_dev)) ? |
| File::kIdentical : |
| File::kDifferent; |
| } |