Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Unified Diff: runtime/bin/file_fuchsia.cc

Issue 2168193002: Fuchsia: Build standalone VM. Make it run "Hello, World!". (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/extensions_fuchsia.cc ('k') | runtime/bin/file_system_watcher_fuchsia.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_fuchsia.cc
diff --git a/runtime/bin/file_macos.cc b/runtime/bin/file_fuchsia.cc
similarity index 75%
copy from runtime/bin/file_macos.cc
copy to runtime/bin/file_fuchsia.cc
index a43b14eaada0245797ae855c2abde869b97e682c..fdc26238821b7d017e80de5cb75e070df6947362 100644
--- a/runtime/bin/file_macos.cc
+++ b/runtime/bin/file_fuchsia.cc
@@ -1,25 +1,22 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "platform/globals.h"
-#if defined(TARGET_OS_MACOS)
+#if defined(TARGET_OS_FUCHSIA)
#include "bin/file.h"
-#include <copyfile.h> // NOLINT
#include <errno.h> // NOLINT
#include <fcntl.h> // NOLINT
#include <libgen.h> // NOLINT
-#include <limits.h> // NOLINT
#include <sys/mman.h> // NOLINT
#include <sys/stat.h> // NOLINT
+#include <sys/types.h> // NOLINT
#include <unistd.h> // NOLINT
#include "bin/builtin.h"
-#include "bin/fdutils.h"
#include "bin/log.h"
-
#include "platform/signal_blocker.h"
#include "platform/utils.h"
@@ -52,17 +49,16 @@ void File::Close() {
ASSERT(handle_->fd() >= 0);
if (handle_->fd() == STDOUT_FILENO) {
// If stdout, redirect fd to /dev/null.
- intptr_t null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY));
+ int null_fd = NO_RETRY_EXPECTED(open("/dev/null", O_WRONLY));
ASSERT(null_fd >= 0);
- VOID_TEMP_FAILURE_RETRY(dup2(null_fd, handle_->fd()));
- VOID_TEMP_FAILURE_RETRY(close(null_fd));
+ VOID_NO_RETRY_EXPECTED(dup2(null_fd, handle_->fd()));
+ VOID_NO_RETRY_EXPECTED(close(null_fd));
} else {
- intptr_t err = TEMP_FAILURE_RETRY(close(handle_->fd()));
+ int err = NO_RETRY_EXPECTED(close(handle_->fd()));
if (err != 0) {
const int kBufferSize = 1024;
- char error_message[kBufferSize];
- Utils::StrError(errno, error_message, kBufferSize);
- Log::PrintErr("%s\n", error_message);
+ char error_buf[kBufferSize];
+ Log::PrintErr("%s\n", Utils::StrError(errno, error_buf, kBufferSize));
}
}
handle_->set_fd(kClosedFd);
@@ -80,47 +76,38 @@ bool File::IsClosed() {
void* File::MapExecutable(intptr_t* len) {
- ASSERT(handle_->fd() >= 0);
- intptr_t length = Length();
- void* addr = mmap(0, length,
- PROT_READ | PROT_EXEC, MAP_PRIVATE,
- handle_->fd(), 0);
- if (addr == MAP_FAILED) {
- *len = -1;
- } else {
- *len = length;
- }
- return addr;
+ UNIMPLEMENTED();
+ return NULL;
}
int64_t File::Read(void* buffer, int64_t num_bytes) {
ASSERT(handle_->fd() >= 0);
- return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes));
+ return NO_RETRY_EXPECTED(read(handle_->fd(), buffer, num_bytes));
}
int64_t File::Write(const void* buffer, int64_t num_bytes) {
ASSERT(handle_->fd() >= 0);
- return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes));
+ return NO_RETRY_EXPECTED(write(handle_->fd(), buffer, num_bytes));
}
int64_t File::Position() {
ASSERT(handle_->fd() >= 0);
- return lseek(handle_->fd(), 0, SEEK_CUR);
+ return NO_RETRY_EXPECTED(lseek(handle_->fd(), 0, SEEK_CUR));
}
bool File::SetPosition(int64_t position) {
ASSERT(handle_->fd() >= 0);
- return lseek(handle_->fd(), position, SEEK_SET) >= 0;
+ return NO_RETRY_EXPECTED(lseek(handle_->fd(), position, SEEK_SET)) >= 0;
}
bool File::Truncate(int64_t length) {
ASSERT(handle_->fd() >= 0);
- return TEMP_FAILURE_RETRY(ftruncate(handle_->fd(), length)) != -1;
+ return NO_RETRY_EXPECTED(ftruncate(handle_->fd(), length) != -1);
}
@@ -157,7 +144,7 @@ bool File::Lock(File::LockType lock, int64_t start, int64_t end) {
(lock == File::kLockBlockingExclusive)) {
cmd = F_SETLKW;
}
- return TEMP_FAILURE_RETRY(fcntl(handle_->fd(), cmd, &fl)) != -1;
+ return NO_RETRY_EXPECTED(fcntl(handle_->fd(), cmd, &fl)) != -1;
}
@@ -181,8 +168,7 @@ 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) {
- // Only accept regular files, character devices, and pipes.
- if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode) && !S_ISFIFO(st.st_mode)) {
+ if (!S_ISREG(st.st_mode)) {
errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT;
return NULL;
}
@@ -199,11 +185,11 @@ File* File::ScopedOpen(const char* name, FileOpenMode mode) {
if ((mode & kTruncate) != 0) {
flags = flags | O_TRUNC;
}
- int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666));
+ flags |= O_CLOEXEC;
+ int fd = NO_RETRY_EXPECTED(open(name, flags, 0666));
if (fd < 0) {
return NULL;
}
- FDUtils::SetCloseOnExec(fd);
if ((((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) ||
(((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) {
int64_t position = lseek(fd, 0, SEEK_END);
@@ -237,7 +223,7 @@ bool File::Exists(const char* name) {
bool File::Create(const char* name) {
- int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CREAT, 0666));
+ int fd = NO_RETRY_EXPECTED(open(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666));
if (fd < 0) {
return false;
}
@@ -246,8 +232,7 @@ bool File::Create(const char* name) {
bool File::CreateLink(const char* name, const char* target) {
- int status = NO_RETRY_EXPECTED(symlink(target, name));
- return (status == 0);
+ return NO_RETRY_EXPECTED(symlink(target, name)) == 0;
}
@@ -301,14 +286,7 @@ bool File::RenameLink(const char* old_path, const char* new_path) {
bool File::Copy(const char* old_path, const char* new_path) {
- File::Type type = File::GetType(old_path, true);
- if (type == kIsFile) {
- return copyfile(old_path, new_path, NULL, COPYFILE_ALL) == 0;
- } else if (type == kIsDirectory) {
- errno = EISDIR;
- } else {
- errno = ENOENT;
- }
+ UNIMPLEMENTED();
return false;
}
@@ -322,12 +300,6 @@ int64_t File::LengthFromPath(const char* name) {
}
-static int64_t TimespecToMilliseconds(const struct timespec& t) {
- return static_cast<int64_t>(t.tv_sec) * 1000L +
- static_cast<int64_t>(t.tv_nsec) / 1000000L;
-}
-
-
void File::Stat(const char* name, int64_t* data) {
struct stat st;
if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) {
@@ -340,12 +312,9 @@ void File::Stat(const char* name, int64_t* data) {
} else {
data[kType] = kDoesNotExist;
}
- data[kCreatedTime] = st.st_ctime;
- data[kModifiedTime] = st.st_mtime;
- data[kAccessedTime] = st.st_atime;
- data[kCreatedTime] = TimespecToMilliseconds(st.st_ctimespec);
- data[kModifiedTime] = TimespecToMilliseconds(st.st_mtimespec);
- data[kAccessedTime] = TimespecToMilliseconds(st.st_atimespec);
+ data[kCreatedTime] = static_cast<int64_t>(st.st_ctime) * 1000;
+ data[kModifiedTime] = static_cast<int64_t>(st.st_mtime) * 1000;
+ data[kAccessedTime] = static_cast<int64_t>(st.st_atime) * 1000;
data[kMode] = st.st_mode;
data[kSize] = st.st_size;
} else {
@@ -372,34 +341,26 @@ const char* File::LinkTarget(const char* pathname) {
errno = ENOENT;
return NULL;
}
- // Don't rely on the link_stats.st_size for the size of the link
- // target. The link might have changed before the readlink call.
- const int kBufferSize = 1024;
- char target[kBufferSize];
- size_t target_size = TEMP_FAILURE_RETRY(
- readlink(pathname, target, kBufferSize));
- if (target_size <= 0) {
- return NULL;
- }
+ size_t target_size = link_stats.st_size;
char* target_name = DartUtils::ScopedCString(target_size + 1);
ASSERT(target_name != NULL);
- memmove(target_name, target, target_size);
+ size_t read_size = readlink(pathname, target_name, target_size + 1);
+ if (read_size != target_size) {
+ return NULL;
+ }
target_name[target_size] = '\0';
return target_name;
}
bool File::IsAbsolutePath(const char* pathname) {
- return (pathname != NULL && pathname[0] == '/');
+ return ((pathname != NULL) && (pathname[0] == '/'));
}
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.
char* resolved_path = DartUtils::ScopedCString(PATH_MAX + 1);
ASSERT(resolved_path != NULL);
do {
@@ -488,4 +449,4 @@ File::Identical File::AreIdentical(const char* file_1, const char* file_2) {
} // namespace bin
} // namespace dart
-#endif // defined(TARGET_OS_MACOS)
+#endif // defined(TARGET_OS_FUCHSIA)
« no previous file with comments | « runtime/bin/extensions_fuchsia.cc ('k') | runtime/bin/file_system_watcher_fuchsia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698