| OLD | NEW |
| 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 <libgen.h> // NOLINT |
| 13 #include <sys/sendfile.h> // NOLINT |
| 12 #include <sys/stat.h> // NOLINT | 14 #include <sys/stat.h> // NOLINT |
| 13 #include <sys/types.h> // NOLINT | 15 #include <sys/types.h> // NOLINT |
| 14 #include <sys/sendfile.h> // NOLINT | |
| 15 #include <unistd.h> // NOLINT | 16 #include <unistd.h> // NOLINT |
| 16 #include <libgen.h> // NOLINT | |
| 17 | 17 |
| 18 #include "bin/builtin.h" | 18 #include "bin/builtin.h" |
| 19 #include "bin/log.h" | 19 #include "bin/log.h" |
| 20 | 20 |
| 21 #include "platform/signal_blocker.h" | 21 #include "platform/signal_blocker.h" |
| 22 #include "platform/utils.h" | 22 #include "platform/utils.h" |
| 23 | 23 |
| 24 | |
| 25 namespace dart { | 24 namespace dart { |
| 26 namespace bin { | 25 namespace bin { |
| 27 | 26 |
| 28 class FileHandle { | 27 class FileHandle { |
| 29 public: | 28 public: |
| 30 explicit FileHandle(int fd) : fd_(fd) { } | 29 explicit FileHandle(int fd) : fd_(fd) { } |
| 31 ~FileHandle() { } | 30 ~FileHandle() { } |
| 32 int fd() const { return fd_; } | 31 int fd() const { return fd_; } |
| 33 void set_fd(int fd) { fd_ = fd; } | 32 void set_fd(int fd) { fd_ = fd; } |
| 34 | 33 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 106 |
| 108 | 107 |
| 109 bool File::Flush() { | 108 bool File::Flush() { |
| 110 ASSERT(handle_->fd() >= 0); | 109 ASSERT(handle_->fd() >= 0); |
| 111 return NO_RETRY_EXPECTED(fsync(handle_->fd()) != -1); | 110 return NO_RETRY_EXPECTED(fsync(handle_->fd()) != -1); |
| 112 } | 111 } |
| 113 | 112 |
| 114 | 113 |
| 115 bool File::Lock(File::LockType lock, int64_t start, int64_t end) { | 114 bool File::Lock(File::LockType lock, int64_t start, int64_t end) { |
| 116 ASSERT(handle_->fd() >= 0); | 115 ASSERT(handle_->fd() >= 0); |
| 117 ASSERT(end == -1 || end > start); | 116 ASSERT((end == -1) || (end > start)); |
| 118 struct flock fl; | 117 struct flock fl; |
| 119 switch (lock) { | 118 switch (lock) { |
| 120 case File::kLockUnlock: | 119 case File::kLockUnlock: |
| 121 fl.l_type = F_UNLCK; | 120 fl.l_type = F_UNLCK; |
| 122 break; | 121 break; |
| 123 case File::kLockShared: | 122 case File::kLockShared: |
| 124 fl.l_type = F_RDLCK; | 123 fl.l_type = F_RDLCK; |
| 125 break; | 124 break; |
| 126 case File::kLockExclusive: | 125 case File::kLockExclusive: |
| 127 fl.l_type = F_WRLCK; | 126 fl.l_type = F_WRLCK; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 size_t read_size = readlink(pathname, target_name, target_size + 1); | 391 size_t read_size = readlink(pathname, target_name, target_size + 1); |
| 393 if (read_size != target_size) { | 392 if (read_size != target_size) { |
| 394 return NULL; | 393 return NULL; |
| 395 } | 394 } |
| 396 target_name[target_size] = '\0'; | 395 target_name[target_size] = '\0'; |
| 397 return target_name; | 396 return target_name; |
| 398 } | 397 } |
| 399 | 398 |
| 400 | 399 |
| 401 bool File::IsAbsolutePath(const char* pathname) { | 400 bool File::IsAbsolutePath(const char* pathname) { |
| 402 return (pathname != NULL && pathname[0] == '/'); | 401 return ((pathname != NULL) && (pathname[0] == '/')); |
| 403 } | 402 } |
| 404 | 403 |
| 405 | 404 |
| 406 const char* File::GetCanonicalPath(const char* pathname) { | 405 const char* File::GetCanonicalPath(const char* pathname) { |
| 407 char* abs_path = NULL; | 406 char* abs_path = NULL; |
| 408 if (pathname != NULL) { | 407 if (pathname != NULL) { |
| 409 char* resolved_path = DartUtils::ScopedCString(PATH_MAX + 1); | 408 char* resolved_path = DartUtils::ScopedCString(PATH_MAX + 1); |
| 410 ASSERT(resolved_path != NULL); | 409 ASSERT(resolved_path != NULL); |
| 411 do { | 410 do { |
| 412 abs_path = realpath(pathname, resolved_path); | 411 abs_path = realpath(pathname, resolved_path); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 return ((file_1_info.st_ino == file_2_info.st_ino) && | 487 return ((file_1_info.st_ino == file_2_info.st_ino) && |
| 489 (file_1_info.st_dev == file_2_info.st_dev)) ? | 488 (file_1_info.st_dev == file_2_info.st_dev)) ? |
| 490 File::kIdentical : | 489 File::kIdentical : |
| 491 File::kDifferent; | 490 File::kDifferent; |
| 492 } | 491 } |
| 493 | 492 |
| 494 } // namespace bin | 493 } // namespace bin |
| 495 } // namespace dart | 494 } // namespace dart |
| 496 | 495 |
| 497 #endif // defined(TARGET_OS_ANDROID) | 496 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |