| 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 <time.h> | 9 #include <time.h> |
| 10 #include <sys/resource.h> | 10 #include <sys/resource.h> |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 154 |
| 155 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { | 155 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { |
| 156 int retval = vsnprintf(str, size, format, args); | 156 int retval = vsnprintf(str, size, format, args); |
| 157 if (retval < 0) { | 157 if (retval < 0) { |
| 158 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); | 158 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); |
| 159 } | 159 } |
| 160 return retval; | 160 return retval; |
| 161 } | 161 } |
| 162 | 162 |
| 163 | 163 |
| 164 bool OS::StringToInteger(const char* str, int64_t* value) { | 164 bool OS::StringToInt64(const char* str, int64_t* value) { |
| 165 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); | 165 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); |
| 166 bool negative_value = false; | |
| 167 int32_t base = 10; | 166 int32_t base = 10; |
| 167 char* endptr; |
| 168 int i = 0; |
| 168 if (str[0] == '-') { | 169 if (str[0] == '-') { |
| 169 negative_value = true; | 170 i = 1; |
| 170 str += 1; | |
| 171 } | 171 } |
| 172 if ((str[0] == '0') && (str[1] == 'x' || str[1] == 'X') && (str[2] != '\0')) { | 172 if ((str[i] == '0') && |
| 173 (str[i + 1] == 'x' || str[i + 1] == 'X') && |
| 174 (str[i + 2] != '\0')) { |
| 173 base = 16; | 175 base = 16; |
| 174 } | 176 } |
| 175 errno = 0; | 177 errno = 0; |
| 176 *value = strtoll(str, NULL, base); | 178 *value = strtoll(str, &endptr, base); |
| 177 if (errno == 0) { | 179 return ((errno == 0) && (endptr != str) && (*endptr == 0)); |
| 178 if (negative_value) { | |
| 179 *value = -(*value); | |
| 180 } | |
| 181 return true; | |
| 182 } | |
| 183 return false; | |
| 184 } | 180 } |
| 185 | 181 |
| 186 | 182 |
| 187 void OS::PrintErr(const char* format, ...) { | 183 void OS::PrintErr(const char* format, ...) { |
| 188 va_list args; | 184 va_list args; |
| 189 va_start(args, format); | 185 va_start(args, format); |
| 190 VFPrint(stderr, format, args); | 186 VFPrint(stderr, format, args); |
| 191 va_end(args); | 187 va_end(args); |
| 192 } | 188 } |
| 193 | 189 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 209 void OS::Abort() { | 205 void OS::Abort() { |
| 210 abort(); | 206 abort(); |
| 211 } | 207 } |
| 212 | 208 |
| 213 | 209 |
| 214 void OS::Exit(int code) { | 210 void OS::Exit(int code) { |
| 215 exit(code); | 211 exit(code); |
| 216 } | 212 } |
| 217 | 213 |
| 218 } // namespace dart | 214 } // namespace dart |
| OLD | NEW |