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(HOST_OS_ANDROID) | 6 #if defined(HOST_OS_ANDROID) |
7 | 7 |
8 #include <errno.h> // NOLINT | 8 #include <errno.h> // NOLINT |
9 #include <netdb.h> // NOLINT | 9 #include <netdb.h> // NOLINT |
10 #include <sys/time.h> // NOLINT | 10 #include <sys/time.h> // NOLINT |
11 #include <time.h> // NOLINT | 11 #include <time.h> // NOLINT |
12 | 12 |
13 #include "bin/utils.h" | 13 #include "bin/utils.h" |
14 #include "platform/assert.h" | 14 #include "platform/assert.h" |
15 #include "platform/utils.h" | 15 #include "platform/utils.h" |
16 | 16 |
17 namespace dart { | 17 namespace dart { |
18 namespace bin { | 18 namespace bin { |
19 | 19 |
20 OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) { | 20 OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) { |
21 set_sub_system(kSystem); | 21 set_sub_system(kSystem); |
22 set_code(errno); | 22 set_code(errno); |
23 const int kBufferSize = 1024; | 23 const int kBufferSize = 1024; |
24 char error_message[kBufferSize]; | 24 char error_message[kBufferSize]; |
25 Utils::StrError(errno, error_message, kBufferSize); | 25 Utils::StrError(errno, error_message, kBufferSize); |
26 SetMessage(error_message); | 26 SetMessage(error_message); |
27 } | 27 } |
28 | 28 |
29 | |
30 void OSError::SetCodeAndMessage(SubSystem sub_system, int code) { | 29 void OSError::SetCodeAndMessage(SubSystem sub_system, int code) { |
31 set_sub_system(sub_system); | 30 set_sub_system(sub_system); |
32 set_code(code); | 31 set_code(code); |
33 if (sub_system == kSystem) { | 32 if (sub_system == kSystem) { |
34 const int kBufferSize = 1024; | 33 const int kBufferSize = 1024; |
35 char error_message[kBufferSize]; | 34 char error_message[kBufferSize]; |
36 Utils::StrError(code, error_message, kBufferSize); | 35 Utils::StrError(code, error_message, kBufferSize); |
37 SetMessage(error_message); | 36 SetMessage(error_message); |
38 } else if (sub_system == kGetAddressInfo) { | 37 } else if (sub_system == kGetAddressInfo) { |
39 SetMessage(gai_strerror(code)); | 38 SetMessage(gai_strerror(code)); |
40 } else { | 39 } else { |
41 UNREACHABLE(); | 40 UNREACHABLE(); |
42 } | 41 } |
43 } | 42 } |
44 | 43 |
45 | |
46 const char* StringUtils::ConsoleStringToUtf8(const char* str, | 44 const char* StringUtils::ConsoleStringToUtf8(const char* str, |
47 intptr_t len, | 45 intptr_t len, |
48 intptr_t* result_len) { | 46 intptr_t* result_len) { |
49 UNIMPLEMENTED(); | 47 UNIMPLEMENTED(); |
50 return NULL; | 48 return NULL; |
51 } | 49 } |
52 | 50 |
53 | |
54 const char* StringUtils::Utf8ToConsoleString(const char* utf8, | 51 const char* StringUtils::Utf8ToConsoleString(const char* utf8, |
55 intptr_t len, | 52 intptr_t len, |
56 intptr_t* result_len) { | 53 intptr_t* result_len) { |
57 UNIMPLEMENTED(); | 54 UNIMPLEMENTED(); |
58 return NULL; | 55 return NULL; |
59 } | 56 } |
60 | 57 |
61 | |
62 char* StringUtils::ConsoleStringToUtf8(char* str, | 58 char* StringUtils::ConsoleStringToUtf8(char* str, |
63 intptr_t len, | 59 intptr_t len, |
64 intptr_t* result_len) { | 60 intptr_t* result_len) { |
65 UNIMPLEMENTED(); | 61 UNIMPLEMENTED(); |
66 return NULL; | 62 return NULL; |
67 } | 63 } |
68 | 64 |
69 | |
70 char* StringUtils::Utf8ToConsoleString(char* utf8, | 65 char* StringUtils::Utf8ToConsoleString(char* utf8, |
71 intptr_t len, | 66 intptr_t len, |
72 intptr_t* result_len) { | 67 intptr_t* result_len) { |
73 UNIMPLEMENTED(); | 68 UNIMPLEMENTED(); |
74 return NULL; | 69 return NULL; |
75 } | 70 } |
76 | 71 |
77 | |
78 char* StringUtils::StrNDup(const char* s, intptr_t n) { | 72 char* StringUtils::StrNDup(const char* s, intptr_t n) { |
79 return strndup(s, n); | 73 return strndup(s, n); |
80 } | 74 } |
81 | 75 |
82 | |
83 bool ShellUtils::GetUtf8Argv(int argc, char** argv) { | 76 bool ShellUtils::GetUtf8Argv(int argc, char** argv) { |
84 return false; | 77 return false; |
85 } | 78 } |
86 | 79 |
87 | |
88 void TimerUtils::InitOnce() {} | 80 void TimerUtils::InitOnce() {} |
89 | 81 |
90 | |
91 int64_t TimerUtils::GetCurrentMonotonicMillis() { | 82 int64_t TimerUtils::GetCurrentMonotonicMillis() { |
92 return GetCurrentMonotonicMicros() / 1000; | 83 return GetCurrentMonotonicMicros() / 1000; |
93 } | 84 } |
94 | 85 |
95 | |
96 int64_t TimerUtils::GetCurrentMonotonicMicros() { | 86 int64_t TimerUtils::GetCurrentMonotonicMicros() { |
97 struct timespec ts; | 87 struct timespec ts; |
98 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { | 88 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { |
99 UNREACHABLE(); | 89 UNREACHABLE(); |
100 return 0; | 90 return 0; |
101 } | 91 } |
102 // Convert to microseconds. | 92 // Convert to microseconds. |
103 int64_t result = ts.tv_sec; | 93 int64_t result = ts.tv_sec; |
104 result *= kMicrosecondsPerSecond; | 94 result *= kMicrosecondsPerSecond; |
105 result += (ts.tv_nsec / kNanosecondsPerMicrosecond); | 95 result += (ts.tv_nsec / kNanosecondsPerMicrosecond); |
106 return result; | 96 return result; |
107 } | 97 } |
108 | 98 |
109 | |
110 void TimerUtils::Sleep(int64_t millis) { | 99 void TimerUtils::Sleep(int64_t millis) { |
111 struct timespec req; // requested. | 100 struct timespec req; // requested. |
112 struct timespec rem; // remainder. | 101 struct timespec rem; // remainder. |
113 int64_t micros = millis * kMicrosecondsPerMillisecond; | 102 int64_t micros = millis * kMicrosecondsPerMillisecond; |
114 int64_t seconds = micros / kMicrosecondsPerSecond; | 103 int64_t seconds = micros / kMicrosecondsPerSecond; |
115 micros = micros - seconds * kMicrosecondsPerSecond; | 104 micros = micros - seconds * kMicrosecondsPerSecond; |
116 int64_t nanos = micros * kNanosecondsPerMicrosecond; | 105 int64_t nanos = micros * kNanosecondsPerMicrosecond; |
117 req.tv_sec = seconds; | 106 req.tv_sec = seconds; |
118 req.tv_nsec = nanos; | 107 req.tv_nsec = nanos; |
119 while (true) { | 108 while (true) { |
120 int r = nanosleep(&req, &rem); | 109 int r = nanosleep(&req, &rem); |
121 if (r == 0) { | 110 if (r == 0) { |
122 break; | 111 break; |
123 } | 112 } |
124 // We should only ever see an interrupt error. | 113 // We should only ever see an interrupt error. |
125 ASSERT(errno == EINTR); | 114 ASSERT(errno == EINTR); |
126 // Copy remainder into requested and repeat. | 115 // Copy remainder into requested and repeat. |
127 req = rem; | 116 req = rem; |
128 } | 117 } |
129 } | 118 } |
130 | 119 |
131 } // namespace bin | 120 } // namespace bin |
132 } // namespace dart | 121 } // namespace dart |
133 | 122 |
134 #endif // defined(HOST_OS_ANDROID) | 123 #endif // defined(HOST_OS_ANDROID) |
OLD | NEW |