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 <sys/stat.h> // NOLINT | 12 #include <sys/stat.h> // NOLINT |
13 #include <sys/types.h> // NOLINT | 13 #include <sys/types.h> // NOLINT |
14 #include <sys/sendfile.h> // NOLINT | 14 #include <sys/sendfile.h> // NOLINT |
15 #include <unistd.h> // NOLINT | 15 #include <unistd.h> // NOLINT |
16 #include <libgen.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 | 23 |
23 | 24 |
24 namespace dart { | 25 namespace dart { |
25 namespace bin { | 26 namespace bin { |
26 | 27 |
27 class FileHandle { | 28 class FileHandle { |
28 public: | 29 public: |
29 explicit FileHandle(int fd) : fd_(fd) { } | 30 explicit FileHandle(int fd) : fd_(fd) { } |
30 ~FileHandle() { } | 31 ~FileHandle() { } |
31 int fd() const { return fd_; } | 32 int fd() const { return fd_; } |
(...skipping 18 matching lines...) Expand all Loading... |
50 // If stdout, redirect fd to /dev/null. | 51 // If stdout, redirect fd to /dev/null. |
51 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); | 52 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); |
52 ASSERT(null_fd >= 0); | 53 ASSERT(null_fd >= 0); |
53 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, handle_->fd())); | 54 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, handle_->fd())); |
54 VOID_TEMP_FAILURE_RETRY(close(null_fd)); | 55 VOID_TEMP_FAILURE_RETRY(close(null_fd)); |
55 } else { | 56 } else { |
56 int err = TEMP_FAILURE_RETRY(close(handle_->fd())); | 57 int err = TEMP_FAILURE_RETRY(close(handle_->fd())); |
57 if (err != 0) { | 58 if (err != 0) { |
58 const int kBufferSize = 1024; | 59 const int kBufferSize = 1024; |
59 char error_message[kBufferSize]; | 60 char error_message[kBufferSize]; |
60 strerror_r(errno, error_message, kBufferSize); | 61 Utils::StrError(errno, error_message, kBufferSize); |
61 Log::PrintErr("%s\n", error_message); | 62 Log::PrintErr("%s\n", error_message); |
62 } | 63 } |
63 } | 64 } |
64 handle_->set_fd(kClosedFd); | 65 handle_->set_fd(kClosedFd); |
65 } | 66 } |
66 | 67 |
67 | 68 |
68 intptr_t File::GetFD() { | 69 intptr_t File::GetFD() { |
69 return handle_->fd(); | 70 return handle_->fd(); |
70 } | 71 } |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 } | 416 } |
416 | 417 |
417 | 418 |
418 File::StdioHandleType File::GetStdioHandleType(int fd) { | 419 File::StdioHandleType File::GetStdioHandleType(int fd) { |
419 ASSERT(0 <= fd && fd <= 2); | 420 ASSERT(0 <= fd && fd <= 2); |
420 struct stat buf; | 421 struct stat buf; |
421 int result = fstat(fd, &buf); | 422 int result = fstat(fd, &buf); |
422 if (result == -1) { | 423 if (result == -1) { |
423 const int kBufferSize = 1024; | 424 const int kBufferSize = 1024; |
424 char error_message[kBufferSize]; | 425 char error_message[kBufferSize]; |
425 strerror_r(errno, error_message, kBufferSize); | 426 Utils::StrError(errno, error_message, kBufferSize); |
426 FATAL2("Failed stat on file descriptor %d: %s", fd, error_message); | 427 FATAL2("Failed stat on file descriptor %d: %s", fd, error_message); |
427 } | 428 } |
428 if (S_ISCHR(buf.st_mode)) return kTerminal; | 429 if (S_ISCHR(buf.st_mode)) return kTerminal; |
429 if (S_ISFIFO(buf.st_mode)) return kPipe; | 430 if (S_ISFIFO(buf.st_mode)) return kPipe; |
430 if (S_ISSOCK(buf.st_mode)) return kSocket; | 431 if (S_ISSOCK(buf.st_mode)) return kSocket; |
431 if (S_ISREG(buf.st_mode)) return kFile; | 432 if (S_ISREG(buf.st_mode)) return kFile; |
432 return kOther; | 433 return kOther; |
433 } | 434 } |
434 | 435 |
435 | 436 |
(...skipping 23 matching lines...) Expand all Loading... |
459 return (file_1_info.st_ino == file_2_info.st_ino && | 460 return (file_1_info.st_ino == file_2_info.st_ino && |
460 file_1_info.st_dev == file_2_info.st_dev) ? | 461 file_1_info.st_dev == file_2_info.st_dev) ? |
461 File::kIdentical : | 462 File::kIdentical : |
462 File::kDifferent; | 463 File::kDifferent; |
463 } | 464 } |
464 | 465 |
465 } // namespace bin | 466 } // namespace bin |
466 } // namespace dart | 467 } // namespace dart |
467 | 468 |
468 #endif // defined(TARGET_OS_ANDROID) | 469 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |