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

Side by Side Diff: runtime/bin/file_android.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
7 7
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
11 #include <fcntl.h> // NOLINT 11 #include <fcntl.h> // NOLINT
12 #include <sys/stat.h> // NOLINT 12 #include <sys/stat.h> // NOLINT
13 #include <sys/types.h> // NOLINT
13 #include <unistd.h> // NOLINT 14 #include <unistd.h> // NOLINT
14 #include <libgen.h> // NOLINT 15 #include <libgen.h> // NOLINT
15 16
16 #include "bin/builtin.h" 17 #include "bin/builtin.h"
17 #include "bin/log.h" 18 #include "bin/log.h"
18 19
19 20
20 namespace dart { 21 namespace dart {
21 namespace bin { 22 namespace bin {
22 23
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); 67 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes));
67 } 68 }
68 69
69 70
70 int64_t File::Write(const void* buffer, int64_t num_bytes) { 71 int64_t File::Write(const void* buffer, int64_t num_bytes) {
71 ASSERT(handle_->fd() >= 0); 72 ASSERT(handle_->fd() >= 0);
72 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); 73 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes));
73 } 74 }
74 75
75 76
76 off_t File::Position() { 77 off64_t File::Position() {
77 ASSERT(handle_->fd() >= 0); 78 ASSERT(handle_->fd() >= 0);
78 return TEMP_FAILURE_RETRY(lseek(handle_->fd(), 0, SEEK_CUR)); 79 return lseek64(handle_->fd(), 0, SEEK_CUR);
79 } 80 }
80 81
81 82
82 bool File::SetPosition(int64_t position) { 83 bool File::SetPosition(off64_t position) {
83 ASSERT(handle_->fd() >= 0); 84 ASSERT(handle_->fd() >= 0);
84 return TEMP_FAILURE_RETRY(lseek(handle_->fd(), position, SEEK_SET) != -1); 85 return lseek64(handle_->fd(), position, SEEK_SET) >= 0;
85 } 86 }
86 87
87 88
88 bool File::Truncate(int64_t length) { 89 bool File::Truncate(off64_t length) {
89 ASSERT(handle_->fd() >= 0); 90 ASSERT(handle_->fd() >= 0);
90 return TEMP_FAILURE_RETRY(ftruncate(handle_->fd(), length) != -1); 91 return TEMP_FAILURE_RETRY(ftruncate64(handle_->fd(), length) != -1);
91 } 92 }
92 93
93 94
94 bool File::Flush() { 95 bool File::Flush() {
95 ASSERT(handle_->fd() >= 0); 96 ASSERT(handle_->fd() >= 0);
96 return TEMP_FAILURE_RETRY(fsync(handle_->fd()) != -1); 97 return TEMP_FAILURE_RETRY(fsync(handle_->fd()) != -1);
97 } 98 }
98 99
99 100
100 off_t File::Length() { 101 off64_t File::Length() {
101 ASSERT(handle_->fd() >= 0); 102 ASSERT(handle_->fd() >= 0);
102 struct stat st; 103 struct stat64 st;
103 if (TEMP_FAILURE_RETRY(fstat(handle_->fd(), &st)) == 0) { 104 if (TEMP_FAILURE_RETRY(fstat64(handle_->fd(), &st)) == 0) {
104 return st.st_size; 105 return st.st_size;
105 } 106 }
106 return -1; 107 return -1;
107 } 108 }
108 109
109 110
110 File* File::Open(const char* name, FileOpenMode mode) { 111 File* File::Open(const char* name, FileOpenMode mode) {
111 // Report errors for non-regular files. 112 // Report errors for non-regular files.
112 struct stat st; 113 struct stat64 st;
113 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { 114 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) {
114 if (!S_ISREG(st.st_mode)) { 115 if (!S_ISREG(st.st_mode)) {
115 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; 116 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT;
116 return NULL; 117 return NULL;
117 } 118 }
118 } 119 }
119 int flags = O_RDONLY; 120 int flags = O_RDONLY;
120 if ((mode & kWrite) != 0) { 121 if ((mode & kWrite) != 0) {
121 flags = (O_RDWR | O_CREAT); 122 flags = (O_RDWR | O_CREAT);
122 } 123 }
123 if ((mode & kTruncate) != 0) { 124 if ((mode & kTruncate) != 0) {
124 flags = flags | O_TRUNC; 125 flags = flags | O_TRUNC;
125 } 126 }
126 flags |= O_CLOEXEC; 127 flags |= O_CLOEXEC;
127 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666)); 128 int fd = TEMP_FAILURE_RETRY(open64(name, flags, 0666));
128 if (fd < 0) { 129 if (fd < 0) {
129 return NULL; 130 return NULL;
130 } 131 }
131 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { 132 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) {
132 int position = TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_END)); 133 int position = lseek64(fd, 0, SEEK_END);
133 if (position < 0) { 134 if (position < 0) {
134 return NULL; 135 return NULL;
135 } 136 }
136 } 137 }
137 return new File(new FileHandle(fd)); 138 return new File(new FileHandle(fd));
138 } 139 }
139 140
140 141
141 File* File::OpenStdio(int fd) { 142 File* File::OpenStdio(int fd) {
142 if (fd < 0 || 2 < fd) return NULL; 143 if (fd < 0 || 2 < fd) return NULL;
143 return new File(new FileHandle(fd)); 144 return new File(new FileHandle(fd));
144 } 145 }
145 146
146 147
147 bool File::Exists(const char* name) { 148 bool File::Exists(const char* name) {
148 struct stat st; 149 struct stat64 st;
149 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { 150 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) {
150 return S_ISREG(st.st_mode); 151 return S_ISREG(st.st_mode);
151 } else { 152 } else {
152 return false; 153 return false;
153 } 154 }
154 } 155 }
155 156
156 157
157 bool File::Create(const char* name) { 158 bool File::Create(const char* name) {
158 int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666)); 159 int fd = TEMP_FAILURE_RETRY(
160 open64(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666));
159 if (fd < 0) { 161 if (fd < 0) {
160 return false; 162 return false;
161 } 163 }
162 return (close(fd) == 0); 164 return (close(fd) == 0);
163 } 165 }
164 166
165 167
166 bool File::CreateLink(const char* name, const char* target) { 168 bool File::CreateLink(const char* name, const char* target) {
167 int status = TEMP_FAILURE_RETRY(symlink(target, name)); 169 int status = TEMP_FAILURE_RETRY(symlink(target, name));
168 return (status == 0); 170 return (status == 0);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return TEMP_FAILURE_RETRY(rename(old_path, new_path)) == 0; 213 return TEMP_FAILURE_RETRY(rename(old_path, new_path)) == 0;
212 } else if (type == kIsDirectory) { 214 } else if (type == kIsDirectory) {
213 errno = EISDIR; 215 errno = EISDIR;
214 } else { 216 } else {
215 errno = EINVAL; 217 errno = EINVAL;
216 } 218 }
217 return false; 219 return false;
218 } 220 }
219 221
220 222
221 off_t File::LengthFromPath(const char* name) { 223 off64_t File::LengthFromPath(const char* name) {
222 struct stat st; 224 struct stat64 st;
223 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { 225 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) {
224 return st.st_size; 226 return st.st_size;
225 } 227 }
226 return -1; 228 return -1;
227 } 229 }
228 230
229 231
230 void File::Stat(const char* name, int64_t* data) { 232 void File::Stat(const char* name, int64_t* data) {
231 struct stat st; 233 struct stat64 st;
232 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { 234 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) {
233 if (S_ISREG(st.st_mode)) { 235 if (S_ISREG(st.st_mode)) {
234 data[kType] = kIsFile; 236 data[kType] = kIsFile;
235 } else if (S_ISDIR(st.st_mode)) { 237 } else if (S_ISDIR(st.st_mode)) {
236 data[kType] = kIsDirectory; 238 data[kType] = kIsDirectory;
237 } else if (S_ISLNK(st.st_mode)) { 239 } else if (S_ISLNK(st.st_mode)) {
238 data[kType] = kIsLink; 240 data[kType] = kIsLink;
239 } else { 241 } else {
240 data[kType] = kDoesNotExist; 242 data[kType] = kDoesNotExist;
241 } 243 }
242 data[kCreatedTime] = st.st_ctime; 244 data[kCreatedTime] = st.st_ctime;
243 data[kModifiedTime] = st.st_mtime; 245 data[kModifiedTime] = st.st_mtime;
244 data[kAccessedTime] = st.st_atime; 246 data[kAccessedTime] = st.st_atime;
245 data[kMode] = st.st_mode; 247 data[kMode] = st.st_mode;
246 data[kSize] = st.st_size; 248 data[kSize] = st.st_size;
247 } else { 249 } else {
248 data[kType] = kDoesNotExist; 250 data[kType] = kDoesNotExist;
249 } 251 }
250 } 252 }
251 253
252 254
253 time_t File::LastModified(const char* name) { 255 time_t File::LastModified(const char* name) {
254 struct stat st; 256 struct stat64 st;
255 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { 257 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) {
256 return st.st_mtime; 258 return st.st_mtime;
257 } 259 }
258 return -1; 260 return -1;
259 } 261 }
260 262
261 263
262 char* File::LinkTarget(const char* pathname) { 264 char* File::LinkTarget(const char* pathname) {
263 struct stat link_stats; 265 struct stat64 link_stats;
264 if (lstat(pathname, &link_stats) != 0) return NULL; 266 if (lstat64(pathname, &link_stats) != 0) return NULL;
265 if (!S_ISLNK(link_stats.st_mode)) { 267 if (!S_ISLNK(link_stats.st_mode)) {
266 errno = ENOENT; 268 errno = ENOENT;
267 return NULL; 269 return NULL;
268 } 270 }
269 size_t target_size = link_stats.st_size; 271 size_t target_size = link_stats.st_size;
270 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1)); 272 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1));
271 size_t read_size = readlink(pathname, target_name, target_size + 1); 273 size_t read_size = readlink(pathname, target_name, target_size + 1);
272 if (read_size != target_size) { 274 if (read_size != target_size) {
273 free(target_name); 275 free(target_name);
274 return NULL; 276 return NULL;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 309 }
308 310
309 311
310 const char* File::StringEscapedPathSeparator() { 312 const char* File::StringEscapedPathSeparator() {
311 return "/"; 313 return "/";
312 } 314 }
313 315
314 316
315 File::StdioHandleType File::GetStdioHandleType(int fd) { 317 File::StdioHandleType File::GetStdioHandleType(int fd) {
316 ASSERT(0 <= fd && fd <= 2); 318 ASSERT(0 <= fd && fd <= 2);
317 struct stat buf; 319 struct stat64 buf;
318 int result = fstat(fd, &buf); 320 int result = fstat64(fd, &buf);
319 if (result == -1) { 321 if (result == -1) {
320 const int kBufferSize = 1024; 322 const int kBufferSize = 1024;
321 char error_message[kBufferSize]; 323 char error_message[kBufferSize];
322 strerror_r(errno, error_message, kBufferSize); 324 strerror_r(errno, error_message, kBufferSize);
323 FATAL2("Failed stat on file descriptor %d: %s", fd, error_message); 325 FATAL2("Failed stat on file descriptor %d: %s", fd, error_message);
324 } 326 }
325 if (S_ISCHR(buf.st_mode)) return kTerminal; 327 if (S_ISCHR(buf.st_mode)) return kTerminal;
326 if (S_ISFIFO(buf.st_mode)) return kPipe; 328 if (S_ISFIFO(buf.st_mode)) return kPipe;
327 if (S_ISSOCK(buf.st_mode)) return kSocket; 329 if (S_ISSOCK(buf.st_mode)) return kSocket;
328 if (S_ISREG(buf.st_mode)) return kFile; 330 if (S_ISREG(buf.st_mode)) return kFile;
329 return kOther; 331 return kOther;
330 } 332 }
331 333
332 334
333 File::Type File::GetType(const char* pathname, bool follow_links) { 335 File::Type File::GetType(const char* pathname, bool follow_links) {
334 struct stat entry_info; 336 struct stat64 entry_info;
335 int stat_success; 337 int stat_success;
336 if (follow_links) { 338 if (follow_links) {
337 stat_success = TEMP_FAILURE_RETRY(stat(pathname, &entry_info)); 339 stat_success = TEMP_FAILURE_RETRY(stat64(pathname, &entry_info));
338 } else { 340 } else {
339 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); 341 stat_success = TEMP_FAILURE_RETRY(lstat64(pathname, &entry_info));
340 } 342 }
341 if (stat_success == -1) return File::kDoesNotExist; 343 if (stat_success == -1) return File::kDoesNotExist;
342 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; 344 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory;
343 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; 345 if (S_ISREG(entry_info.st_mode)) return File::kIsFile;
344 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; 346 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink;
345 return File::kDoesNotExist; 347 return File::kDoesNotExist;
346 } 348 }
347 349
348 350
349 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { 351 File::Identical File::AreIdentical(const char* file_1, const char* file_2) {
350 struct stat file_1_info; 352 struct stat64 file_1_info;
351 struct stat file_2_info; 353 struct stat64 file_2_info;
352 if (TEMP_FAILURE_RETRY(lstat(file_1, &file_1_info)) == -1 || 354 if (TEMP_FAILURE_RETRY(lstat64(file_1, &file_1_info)) == -1 ||
353 TEMP_FAILURE_RETRY(lstat(file_2, &file_2_info)) == -1) { 355 TEMP_FAILURE_RETRY(lstat64(file_2, &file_2_info)) == -1) {
354 return File::kError; 356 return File::kError;
355 } 357 }
356 return (file_1_info.st_ino == file_2_info.st_ino && 358 return (file_1_info.st_ino == file_2_info.st_ino &&
357 file_1_info.st_dev == file_2_info.st_dev) ? 359 file_1_info.st_dev == file_2_info.st_dev) ?
358 File::kIdentical : 360 File::kIdentical :
359 File::kDifferent; 361 File::kDifferent;
360 } 362 }
361 363
362 } // namespace bin 364 } // namespace bin
363 } // namespace dart 365 } // namespace dart
364 366
365 #endif // defined(TARGET_OS_ANDROID) 367 #endif // defined(TARGET_OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698