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

Unified Diff: runtime/bin/file_linux.cc

Issue 63363010: Add support for working with large files, in dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
Index: runtime/bin/file_linux.cc
diff --git a/runtime/bin/file_linux.cc b/runtime/bin/file_linux.cc
index 1e9b49e73dbf9e8f792f9d791550ea38271c92b8..f5db4e579e1aaefcaa584cfec91b0296d0b7e67f 100644
--- a/runtime/bin/file_linux.cc
+++ b/runtime/bin/file_linux.cc
@@ -10,6 +10,7 @@
#include <errno.h> // NOLINT
#include <fcntl.h> // NOLINT
#include <sys/stat.h> // NOLINT
+#include <sys/types.h> // NOLINT
#include <unistd.h> // NOLINT
#include <libgen.h> // NOLINT
@@ -72,21 +73,21 @@ int64_t File::Write(const void* buffer, int64_t num_bytes) {
}
-off_t File::Position() {
+off64_t File::Position() {
ASSERT(handle_->fd() >= 0);
- return TEMP_FAILURE_RETRY(lseek(handle_->fd(), 0, SEEK_CUR));
+ return lseek64(handle_->fd(), 0, SEEK_CUR);
}
-bool File::SetPosition(int64_t position) {
+bool File::SetPosition(off64_t position) {
ASSERT(handle_->fd() >= 0);
- return TEMP_FAILURE_RETRY(lseek(handle_->fd(), position, SEEK_SET) != -1);
+ return lseek64(handle_->fd(), position, SEEK_SET) >= 0;
}
-bool File::Truncate(int64_t length) {
+bool File::Truncate(off64_t length) {
ASSERT(handle_->fd() >= 0);
- return TEMP_FAILURE_RETRY(ftruncate(handle_->fd(), length) != -1);
+ return TEMP_FAILURE_RETRY(ftruncate64(handle_->fd(), length) != -1);
}
@@ -96,10 +97,10 @@ bool File::Flush() {
}
-off_t File::Length() {
+off64_t File::Length() {
ASSERT(handle_->fd() >= 0);
- struct stat st;
- if (TEMP_FAILURE_RETRY(fstat(handle_->fd(), &st)) == 0) {
+ struct stat64 st;
+ if (TEMP_FAILURE_RETRY(fstat64(handle_->fd(), &st)) == 0) {
return st.st_size;
}
return -1;
@@ -108,8 +109,8 @@ off_t File::Length() {
File* File::Open(const char* name, FileOpenMode mode) {
// Report errors for non-regular files.
- struct stat st;
- if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
+ struct stat64 st;
+ if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) {
// Only accept regular files and character devices.
if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) {
errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT;
@@ -124,12 +125,12 @@ File* File::Open(const char* name, FileOpenMode mode) {
flags = flags | O_TRUNC;
}
flags |= O_CLOEXEC;
- int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666));
+ int fd = TEMP_FAILURE_RETRY(open64(name, flags, 0666));
if (fd < 0) {
return NULL;
}
if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) {
- int position = TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_END));
+ off64_t position = lseek64(fd, 0, SEEK_END);
if (position < 0) {
return NULL;
}
@@ -145,8 +146,8 @@ File* File::OpenStdio(int fd) {
bool File::Exists(const char* name) {
- struct stat st;
- if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
+ struct stat64 st;
+ if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) {
return S_ISREG(st.st_mode);
} else {
return false;
@@ -155,7 +156,8 @@ bool File::Exists(const char* name) {
bool File::Create(const char* name) {
- int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666));
+ int fd = TEMP_FAILURE_RETRY(
+ open64(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666));
if (fd < 0) {
return false;
}
@@ -218,9 +220,9 @@ bool File::RenameLink(const char* old_path, const char* new_path) {
}
-off_t File::LengthFromPath(const char* name) {
- struct stat st;
- if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
+off64_t File::LengthFromPath(const char* name) {
+ struct stat64 st;
+ if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) {
return st.st_size;
}
return -1;
@@ -228,8 +230,8 @@ off_t File::LengthFromPath(const char* name) {
void File::Stat(const char* name, int64_t* data) {
- struct stat st;
- if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
+ struct stat64 st;
+ if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) {
if (S_ISREG(st.st_mode)) {
data[kType] = kIsFile;
} else if (S_ISDIR(st.st_mode)) {
@@ -251,8 +253,8 @@ void File::Stat(const char* name, int64_t* data) {
time_t File::LastModified(const char* name) {
- struct stat st;
- if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
+ struct stat64 st;
+ if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) {
return st.st_mtime;
}
return -1;
@@ -260,8 +262,8 @@ time_t File::LastModified(const char* name) {
char* File::LinkTarget(const char* pathname) {
- struct stat link_stats;
- if (lstat(pathname, &link_stats) != 0) return NULL;
+ struct stat64 link_stats;
+ if (lstat64(pathname, &link_stats) != 0) return NULL;
if (!S_ISLNK(link_stats.st_mode)) {
errno = ENOENT;
return NULL;
@@ -307,8 +309,8 @@ const char* File::StringEscapedPathSeparator() {
File::StdioHandleType File::GetStdioHandleType(int fd) {
ASSERT(0 <= fd && fd <= 2);
- struct stat buf;
- int result = fstat(fd, &buf);
+ struct stat64 buf;
+ int result = fstat64(fd, &buf);
if (result == -1) {
const int kBufferSize = 1024;
char error_buf[kBufferSize];
@@ -324,12 +326,12 @@ File::StdioHandleType File::GetStdioHandleType(int fd) {
File::Type File::GetType(const char* pathname, bool follow_links) {
- struct stat entry_info;
+ struct stat64 entry_info;
int stat_success;
if (follow_links) {
- stat_success = TEMP_FAILURE_RETRY(stat(pathname, &entry_info));
+ stat_success = TEMP_FAILURE_RETRY(stat64(pathname, &entry_info));
} else {
- stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info));
+ stat_success = TEMP_FAILURE_RETRY(lstat64(pathname, &entry_info));
}
if (stat_success == -1) return File::kDoesNotExist;
if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory;
@@ -340,10 +342,10 @@ 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 (TEMP_FAILURE_RETRY(lstat(file_1, &file_1_info)) == -1 ||
- TEMP_FAILURE_RETRY(lstat(file_2, &file_2_info)) == -1) {
+ struct stat64 file_1_info;
+ struct stat64 file_2_info;
+ if (TEMP_FAILURE_RETRY(lstat64(file_1, &file_1_info)) == -1 ||
+ TEMP_FAILURE_RETRY(lstat64(file_2, &file_2_info)) == -1) {
return File::kError;
}
return (file_1_info.st_ino == file_2_info.st_ino &&

Powered by Google App Engine
This is Rietveld 408576698