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 <errno.h> | 7 #include <errno.h> |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <mach/mach.h> | 9 #include <mach/mach.h> |
10 #include <mach/clock.h> | 10 #include <mach/clock.h> |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { | 130 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { |
131 int retval = vsnprintf(str, size, format, args); | 131 int retval = vsnprintf(str, size, format, args); |
132 if (retval < 0) { | 132 if (retval < 0) { |
133 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); | 133 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); |
134 } | 134 } |
135 return retval; | 135 return retval; |
136 } | 136 } |
137 | 137 |
138 | 138 |
| 139 bool OS::StringToInteger(const char* str, int64_t* value) { |
| 140 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); |
| 141 bool negative_value = false; |
| 142 int32_t base = 10; |
| 143 if (str[0] == '-') { |
| 144 negative_value = true; |
| 145 str += 1; |
| 146 } |
| 147 if ((str[0] == '0') && (str[1] == 'x' || str[1] == 'X') && (str[2] != '\0')) { |
| 148 base = 16; |
| 149 } |
| 150 errno = 0; |
| 151 *value = strtoll(str, NULL, base); |
| 152 if (errno == 0) { |
| 153 if (negative_value) { |
| 154 *value = -(*value); |
| 155 } |
| 156 return true; |
| 157 } |
| 158 return false; |
| 159 } |
| 160 |
| 161 |
139 void OS::PrintErr(const char* format, ...) { | 162 void OS::PrintErr(const char* format, ...) { |
140 va_list args; | 163 va_list args; |
141 va_start(args, format); | 164 va_start(args, format); |
142 VFPrint(stderr, format, args); | 165 VFPrint(stderr, format, args); |
143 va_end(args); | 166 va_end(args); |
144 } | 167 } |
145 | 168 |
146 | 169 |
147 void OS::InitOnce() { | 170 void OS::InitOnce() { |
148 // TODO(5411554): For now we check that initonce is called only once, | 171 // TODO(5411554): For now we check that initonce is called only once, |
(...skipping 12 matching lines...) Expand all Loading... |
161 void OS::Abort() { | 184 void OS::Abort() { |
162 abort(); | 185 abort(); |
163 } | 186 } |
164 | 187 |
165 | 188 |
166 void OS::Exit(int code) { | 189 void OS::Exit(int code) { |
167 exit(code); | 190 exit(code); |
168 } | 191 } |
169 | 192 |
170 } // namespace dart | 193 } // namespace dart |
OLD | NEW |