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

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

Issue 1800863002: Cleanup in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Windows fixes Created 4 years, 9 months 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
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/fdutils.h"
9
8 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
9 #include <fcntl.h> // NOLINT 11 #include <fcntl.h> // NOLINT
12 #include <sys/ioctl.h> // NOLINT
10 #include <unistd.h> // NOLINT 13 #include <unistd.h> // NOLINT
11 #include <sys/ioctl.h> // NOLINT
12 14
13 #include "bin/fdutils.h"
14 #include "platform/signal_blocker.h" 15 #include "platform/signal_blocker.h"
15 16
16
17 namespace dart { 17 namespace dart {
18 namespace bin { 18 namespace bin {
19 19
20 bool FDUtils::SetCloseOnExec(intptr_t fd) { 20 bool FDUtils::SetCloseOnExec(intptr_t fd) {
21 intptr_t status; 21 intptr_t status;
22 status = NO_RETRY_EXPECTED(fcntl(fd, F_GETFD)); 22 status = NO_RETRY_EXPECTED(fcntl(fd, F_GETFD));
23 if (status < 0) { 23 if (status < 0) {
24 return false; 24 return false;
25 } 25 }
26 status |= FD_CLOEXEC; 26 status |= FD_CLOEXEC;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return true; 65 return true;
66 } 66 }
67 67
68 68
69 intptr_t FDUtils::AvailableBytes(intptr_t fd) { 69 intptr_t FDUtils::AvailableBytes(intptr_t fd) {
70 int available; // ioctl for FIONREAD expects an 'int*' argument. 70 int available; // ioctl for FIONREAD expects an 'int*' argument.
71 int result = NO_RETRY_EXPECTED(ioctl(fd, FIONREAD, &available)); 71 int result = NO_RETRY_EXPECTED(ioctl(fd, FIONREAD, &available));
72 if (result < 0) { 72 if (result < 0) {
73 return result; 73 return result;
74 } 74 }
75 #ifdef DEBUG
76 ASSERT(available >= 0); 75 ASSERT(available >= 0);
77 #endif
78 return static_cast<intptr_t>(available); 76 return static_cast<intptr_t>(available);
79 } 77 }
80 78
81 79
82 ssize_t FDUtils::ReadFromBlocking(int fd, void* buffer, size_t count) { 80 ssize_t FDUtils::ReadFromBlocking(int fd, void* buffer, size_t count) {
83 #ifdef DEBUG 81 #ifdef DEBUG
84 bool is_blocking = false; 82 bool is_blocking = false;
85 ASSERT(FDUtils::IsBlocking(fd, &is_blocking)); 83 ASSERT(FDUtils::IsBlocking(fd, &is_blocking));
86 ASSERT(is_blocking); 84 ASSERT(is_blocking);
87 #endif 85 #endif
88 size_t remaining = count; 86 size_t remaining = count;
89 char* buffer_pos = reinterpret_cast<char*>(buffer); 87 char* buffer_pos = reinterpret_cast<char*>(buffer);
90 while (remaining > 0) { 88 while (remaining > 0) {
91 ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd, buffer_pos, remaining)); 89 ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd, buffer_pos, remaining));
92 if (bytes_read == 0) { 90 if (bytes_read == 0) {
93 return count - remaining; 91 return count - remaining;
94 } else if (bytes_read == -1) { 92 } else if (bytes_read == -1) {
95 ASSERT(EAGAIN == EWOULDBLOCK); 93 ASSERT(EAGAIN == EWOULDBLOCK);
96 // Error code EWOULDBLOCK should only happen for non blocking 94 // Error code EWOULDBLOCK should only happen for non blocking
97 // file descriptors. 95 // file descriptors.
98 ASSERT(errno != EWOULDBLOCK); 96 ASSERT(errno != EWOULDBLOCK);
99 return -1; 97 return -1;
100 } else { 98 } else {
101 ASSERT((bytes_read > 0)); 99 ASSERT(bytes_read > 0);
102 remaining -= bytes_read; 100 remaining -= bytes_read;
103 buffer_pos += bytes_read; 101 buffer_pos += bytes_read;
104 } 102 }
105 } 103 }
106 return count; 104 return count;
107 } 105 }
108 106
109 107
110 ssize_t FDUtils::WriteToBlocking(int fd, const void* buffer, size_t count) { 108 ssize_t FDUtils::WriteToBlocking(int fd, const void* buffer, size_t count) {
111 #ifdef DEBUG 109 #ifdef DEBUG
(...skipping 20 matching lines...) Expand all
132 buffer_pos += bytes_written; 130 buffer_pos += bytes_written;
133 } 131 }
134 } 132 }
135 return count; 133 return count;
136 } 134 }
137 135
138 } // namespace bin 136 } // namespace bin
139 } // namespace dart 137 } // namespace dart
140 138
141 #endif // defined(TARGET_OS_ANDROID) 139 #endif // defined(TARGET_OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698