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

Side by Side Diff: runtime/bin/file_android.cc

Issue 76413003: Undo some of the large-file changes on Android, as only some of them are implemented. (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
« no previous file with comments | « runtime/bin/directory_android.cc ('k') | runtime/bin/socket_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 82
83 bool File::SetPosition(off64_t position) { 83 bool File::SetPosition(off64_t position) {
84 ASSERT(handle_->fd() >= 0); 84 ASSERT(handle_->fd() >= 0);
85 return lseek64(handle_->fd(), position, SEEK_SET) >= 0; 85 return lseek64(handle_->fd(), position, SEEK_SET) >= 0;
86 } 86 }
87 87
88 88
89 bool File::Truncate(off64_t length) { 89 bool File::Truncate(off64_t length) {
90 ASSERT(handle_->fd() >= 0); 90 ASSERT(handle_->fd() >= 0);
91 return TEMP_FAILURE_RETRY(ftruncate64(handle_->fd(), length) != -1); 91 return TEMP_FAILURE_RETRY(ftruncate(handle_->fd(), length) != -1);
92 } 92 }
93 93
94 94
95 bool File::Flush() { 95 bool File::Flush() {
96 ASSERT(handle_->fd() >= 0); 96 ASSERT(handle_->fd() >= 0);
97 return TEMP_FAILURE_RETRY(fsync(handle_->fd()) != -1); 97 return TEMP_FAILURE_RETRY(fsync(handle_->fd()) != -1);
98 } 98 }
99 99
100 100
101 off64_t File::Length() { 101 off64_t File::Length() {
102 ASSERT(handle_->fd() >= 0); 102 ASSERT(handle_->fd() >= 0);
103 struct stat64 st; 103 struct stat st;
104 if (TEMP_FAILURE_RETRY(fstat64(handle_->fd(), &st)) == 0) { 104 if (TEMP_FAILURE_RETRY(fstat(handle_->fd(), &st)) == 0) {
105 return st.st_size; 105 return st.st_size;
106 } 106 }
107 return -1; 107 return -1;
108 } 108 }
109 109
110 110
111 File* File::Open(const char* name, FileOpenMode mode) { 111 File* File::Open(const char* name, FileOpenMode mode) {
112 // Report errors for non-regular files. 112 // Report errors for non-regular files.
113 struct stat64 st; 113 struct stat st;
114 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) { 114 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
115 if (!S_ISREG(st.st_mode)) { 115 if (!S_ISREG(st.st_mode)) {
116 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; 116 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT;
117 return NULL; 117 return NULL;
118 } 118 }
119 } 119 }
120 int flags = O_RDONLY; 120 int flags = O_RDONLY;
121 if ((mode & kWrite) != 0) { 121 if ((mode & kWrite) != 0) {
122 flags = (O_RDWR | O_CREAT); 122 flags = (O_RDWR | O_CREAT);
123 } 123 }
124 if ((mode & kTruncate) != 0) { 124 if ((mode & kTruncate) != 0) {
125 flags = flags | O_TRUNC; 125 flags = flags | O_TRUNC;
126 } 126 }
127 flags |= O_CLOEXEC; 127 flags |= O_CLOEXEC;
128 int fd = TEMP_FAILURE_RETRY(open64(name, flags, 0666)); 128 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666));
129 if (fd < 0) { 129 if (fd < 0) {
130 return NULL; 130 return NULL;
131 } 131 }
132 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { 132 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) {
133 off64_t position = lseek64(fd, 0, SEEK_END); 133 off64_t position = lseek64(fd, 0, SEEK_END);
134 if (position < 0) { 134 if (position < 0) {
135 return NULL; 135 return NULL;
136 } 136 }
137 } 137 }
138 return new File(new FileHandle(fd)); 138 return new File(new FileHandle(fd));
139 } 139 }
140 140
141 141
142 File* File::OpenStdio(int fd) { 142 File* File::OpenStdio(int fd) {
143 if (fd < 0 || 2 < fd) return NULL; 143 if (fd < 0 || 2 < fd) return NULL;
144 return new File(new FileHandle(fd)); 144 return new File(new FileHandle(fd));
145 } 145 }
146 146
147 147
148 bool File::Exists(const char* name) { 148 bool File::Exists(const char* name) {
149 struct stat64 st; 149 struct stat st;
150 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) { 150 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
151 return S_ISREG(st.st_mode); 151 return S_ISREG(st.st_mode);
152 } else { 152 } else {
153 return false; 153 return false;
154 } 154 }
155 } 155 }
156 156
157 157
158 bool File::Create(const char* name) { 158 bool File::Create(const char* name) {
159 int fd = TEMP_FAILURE_RETRY( 159 int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666));
160 open64(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666));
161 if (fd < 0) { 160 if (fd < 0) {
162 return false; 161 return false;
163 } 162 }
164 return (close(fd) == 0); 163 return (close(fd) == 0);
165 } 164 }
166 165
167 166
168 bool File::CreateLink(const char* name, const char* target) { 167 bool File::CreateLink(const char* name, const char* target) {
169 int status = TEMP_FAILURE_RETRY(symlink(target, name)); 168 int status = TEMP_FAILURE_RETRY(symlink(target, name));
170 return (status == 0); 169 return (status == 0);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } else if (type == kIsDirectory) { 213 } else if (type == kIsDirectory) {
215 errno = EISDIR; 214 errno = EISDIR;
216 } else { 215 } else {
217 errno = EINVAL; 216 errno = EINVAL;
218 } 217 }
219 return false; 218 return false;
220 } 219 }
221 220
222 221
223 off64_t File::LengthFromPath(const char* name) { 222 off64_t File::LengthFromPath(const char* name) {
224 struct stat64 st; 223 struct stat st;
225 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) { 224 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
226 return st.st_size; 225 return st.st_size;
227 } 226 }
228 return -1; 227 return -1;
229 } 228 }
230 229
231 230
232 void File::Stat(const char* name, int64_t* data) { 231 void File::Stat(const char* name, int64_t* data) {
233 struct stat64 st; 232 struct stat st;
234 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) { 233 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
235 if (S_ISREG(st.st_mode)) { 234 if (S_ISREG(st.st_mode)) {
236 data[kType] = kIsFile; 235 data[kType] = kIsFile;
237 } else if (S_ISDIR(st.st_mode)) { 236 } else if (S_ISDIR(st.st_mode)) {
238 data[kType] = kIsDirectory; 237 data[kType] = kIsDirectory;
239 } else if (S_ISLNK(st.st_mode)) { 238 } else if (S_ISLNK(st.st_mode)) {
240 data[kType] = kIsLink; 239 data[kType] = kIsLink;
241 } else { 240 } else {
242 data[kType] = kDoesNotExist; 241 data[kType] = kDoesNotExist;
243 } 242 }
244 data[kCreatedTime] = st.st_ctime; 243 data[kCreatedTime] = st.st_ctime;
245 data[kModifiedTime] = st.st_mtime; 244 data[kModifiedTime] = st.st_mtime;
246 data[kAccessedTime] = st.st_atime; 245 data[kAccessedTime] = st.st_atime;
247 data[kMode] = st.st_mode; 246 data[kMode] = st.st_mode;
248 data[kSize] = st.st_size; 247 data[kSize] = st.st_size;
249 } else { 248 } else {
250 data[kType] = kDoesNotExist; 249 data[kType] = kDoesNotExist;
251 } 250 }
252 } 251 }
253 252
254 253
255 time_t File::LastModified(const char* name) { 254 time_t File::LastModified(const char* name) {
256 struct stat64 st; 255 struct stat st;
257 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) { 256 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
258 return st.st_mtime; 257 return st.st_mtime;
259 } 258 }
260 return -1; 259 return -1;
261 } 260 }
262 261
263 262
264 char* File::LinkTarget(const char* pathname) { 263 char* File::LinkTarget(const char* pathname) {
265 struct stat64 link_stats; 264 struct stat link_stats;
266 if (lstat64(pathname, &link_stats) != 0) return NULL; 265 if (lstat(pathname, &link_stats) != 0) return NULL;
267 if (!S_ISLNK(link_stats.st_mode)) { 266 if (!S_ISLNK(link_stats.st_mode)) {
268 errno = ENOENT; 267 errno = ENOENT;
269 return NULL; 268 return NULL;
270 } 269 }
271 size_t target_size = link_stats.st_size; 270 size_t target_size = link_stats.st_size;
272 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1)); 271 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1));
273 size_t read_size = readlink(pathname, target_name, target_size + 1); 272 size_t read_size = readlink(pathname, target_name, target_size + 1);
274 if (read_size != target_size) { 273 if (read_size != target_size) {
275 free(target_name); 274 free(target_name);
276 return NULL; 275 return NULL;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 308 }
310 309
311 310
312 const char* File::StringEscapedPathSeparator() { 311 const char* File::StringEscapedPathSeparator() {
313 return "/"; 312 return "/";
314 } 313 }
315 314
316 315
317 File::StdioHandleType File::GetStdioHandleType(int fd) { 316 File::StdioHandleType File::GetStdioHandleType(int fd) {
318 ASSERT(0 <= fd && fd <= 2); 317 ASSERT(0 <= fd && fd <= 2);
319 struct stat64 buf; 318 struct stat buf;
320 int result = fstat64(fd, &buf); 319 int result = fstat(fd, &buf);
321 if (result == -1) { 320 if (result == -1) {
322 const int kBufferSize = 1024; 321 const int kBufferSize = 1024;
323 char error_message[kBufferSize]; 322 char error_message[kBufferSize];
324 strerror_r(errno, error_message, kBufferSize); 323 strerror_r(errno, error_message, kBufferSize);
325 FATAL2("Failed stat on file descriptor %d: %s", fd, error_message); 324 FATAL2("Failed stat on file descriptor %d: %s", fd, error_message);
326 } 325 }
327 if (S_ISCHR(buf.st_mode)) return kTerminal; 326 if (S_ISCHR(buf.st_mode)) return kTerminal;
328 if (S_ISFIFO(buf.st_mode)) return kPipe; 327 if (S_ISFIFO(buf.st_mode)) return kPipe;
329 if (S_ISSOCK(buf.st_mode)) return kSocket; 328 if (S_ISSOCK(buf.st_mode)) return kSocket;
330 if (S_ISREG(buf.st_mode)) return kFile; 329 if (S_ISREG(buf.st_mode)) return kFile;
331 return kOther; 330 return kOther;
332 } 331 }
333 332
334 333
335 File::Type File::GetType(const char* pathname, bool follow_links) { 334 File::Type File::GetType(const char* pathname, bool follow_links) {
336 struct stat64 entry_info; 335 struct stat entry_info;
337 int stat_success; 336 int stat_success;
338 if (follow_links) { 337 if (follow_links) {
339 stat_success = TEMP_FAILURE_RETRY(stat64(pathname, &entry_info)); 338 stat_success = TEMP_FAILURE_RETRY(stat(pathname, &entry_info));
340 } else { 339 } else {
341 stat_success = TEMP_FAILURE_RETRY(lstat64(pathname, &entry_info)); 340 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info));
342 } 341 }
343 if (stat_success == -1) return File::kDoesNotExist; 342 if (stat_success == -1) return File::kDoesNotExist;
344 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; 343 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory;
345 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; 344 if (S_ISREG(entry_info.st_mode)) return File::kIsFile;
346 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; 345 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink;
347 return File::kDoesNotExist; 346 return File::kDoesNotExist;
348 } 347 }
349 348
350 349
351 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { 350 File::Identical File::AreIdentical(const char* file_1, const char* file_2) {
352 struct stat64 file_1_info; 351 struct stat file_1_info;
353 struct stat64 file_2_info; 352 struct stat file_2_info;
354 if (TEMP_FAILURE_RETRY(lstat64(file_1, &file_1_info)) == -1 || 353 if (TEMP_FAILURE_RETRY(lstat(file_1, &file_1_info)) == -1 ||
355 TEMP_FAILURE_RETRY(lstat64(file_2, &file_2_info)) == -1) { 354 TEMP_FAILURE_RETRY(lstat(file_2, &file_2_info)) == -1) {
356 return File::kError; 355 return File::kError;
357 } 356 }
358 return (file_1_info.st_ino == file_2_info.st_ino && 357 return (file_1_info.st_ino == file_2_info.st_ino &&
359 file_1_info.st_dev == file_2_info.st_dev) ? 358 file_1_info.st_dev == file_2_info.st_dev) ?
360 File::kIdentical : 359 File::kIdentical :
361 File::kDifferent; 360 File::kDifferent;
362 } 361 }
363 362
364 } // namespace bin 363 } // namespace bin
365 } // namespace dart 364 } // namespace dart
366 365
367 #endif // defined(TARGET_OS_ANDROID) 366 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/bin/directory_android.cc ('k') | runtime/bin/socket_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698