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 "vm/os.h" | 5 #include "vm/os.h" |
6 | 6 |
7 #include <time.h> | 7 #include <time.h> |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 | 10 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 179 } |
180 // Make sure to zero-terminate the string if the output was | 180 // Make sure to zero-terminate the string if the output was |
181 // truncated or if there was an error. | 181 // truncated or if there was an error. |
182 if (written >= size) { | 182 if (written >= size) { |
183 str[size - 1] = '\0'; | 183 str[size - 1] = '\0'; |
184 } | 184 } |
185 return written; | 185 return written; |
186 } | 186 } |
187 | 187 |
188 | 188 |
| 189 bool OS::StringToInteger(const char* str, int64_t* value) { |
| 190 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); |
| 191 bool negative_value = false; |
| 192 int32_t base = 10; |
| 193 if (str[0] == '-') { |
| 194 negative_value = true; |
| 195 str += 1; |
| 196 } |
| 197 if ((str[0] == '0') && (str[1] == 'x' || str[1] == 'X') && (str[2] != '\0')) { |
| 198 base = 16; |
| 199 } |
| 200 errno = 0; |
| 201 *value = _strtoi64(str, NULL, base); |
| 202 if (errno == 0) { |
| 203 if (negative_value) { |
| 204 *value = -(*value); |
| 205 } |
| 206 return true; |
| 207 } |
| 208 return false; |
| 209 } |
| 210 |
| 211 |
189 void OS::PrintErr(const char* format, ...) { | 212 void OS::PrintErr(const char* format, ...) { |
190 va_list args; | 213 va_list args; |
191 va_start(args, format); | 214 va_start(args, format); |
192 VFPrint(stderr, format, args); | 215 VFPrint(stderr, format, args); |
193 va_end(args); | 216 va_end(args); |
194 } | 217 } |
195 | 218 |
196 | 219 |
197 void OS::InitOnce() { | 220 void OS::InitOnce() { |
198 // TODO(5411554): For now we check that initonce is called only once, | 221 // TODO(5411554): For now we check that initonce is called only once, |
(...skipping 14 matching lines...) Expand all Loading... |
213 void OS::Abort() { | 236 void OS::Abort() { |
214 abort(); | 237 abort(); |
215 } | 238 } |
216 | 239 |
217 | 240 |
218 void OS::Exit(int code) { | 241 void OS::Exit(int code) { |
219 exit(code); | 242 exit(code); |
220 } | 243 } |
221 | 244 |
222 } // namespace dart | 245 } // namespace dart |
OLD | NEW |