| 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) { | 139 bool OS::StringToInt64(const char* str, int64_t* value) { |
| 140 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); | 140 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); |
| 141 bool negative_value = false; | |
| 142 int32_t base = 10; | 141 int32_t base = 10; |
| 142 char* endptr; |
| 143 int i = 0; |
| 143 if (str[0] == '-') { | 144 if (str[0] == '-') { |
| 144 negative_value = true; | 145 i = 1; |
| 145 str += 1; | |
| 146 } | 146 } |
| 147 if ((str[0] == '0') && (str[1] == 'x' || str[1] == 'X') && (str[2] != '\0')) { | 147 if ((str[i] == '0') && |
| 148 (str[i + 1] == 'x' || str[i + 1] == 'X') && |
| 149 (str[i + 2] != '\0')) { |
| 148 base = 16; | 150 base = 16; |
| 149 } | 151 } |
| 150 errno = 0; | 152 errno = 0; |
| 151 *value = strtoll(str, NULL, base); | 153 *value = strtoll(str, &endptr, base); |
| 152 if (errno == 0) { | 154 return ((errno == 0) && (endptr != str) && (*endptr == 0)); |
| 153 if (negative_value) { | |
| 154 *value = -(*value); | |
| 155 } | |
| 156 return true; | |
| 157 } | |
| 158 return false; | |
| 159 } | 155 } |
| 160 | 156 |
| 161 | 157 |
| 162 void OS::PrintErr(const char* format, ...) { | 158 void OS::PrintErr(const char* format, ...) { |
| 163 va_list args; | 159 va_list args; |
| 164 va_start(args, format); | 160 va_start(args, format); |
| 165 VFPrint(stderr, format, args); | 161 VFPrint(stderr, format, args); |
| 166 va_end(args); | 162 va_end(args); |
| 167 } | 163 } |
| 168 | 164 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 184 void OS::Abort() { | 180 void OS::Abort() { |
| 185 abort(); | 181 abort(); |
| 186 } | 182 } |
| 187 | 183 |
| 188 | 184 |
| 189 void OS::Exit(int code) { | 185 void OS::Exit(int code) { |
| 190 exit(code); | 186 exit(code); |
| 191 } | 187 } |
| 192 | 188 |
| 193 } // namespace dart | 189 } // namespace dart |
| OLD | NEW |