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::Strtoll(const char* str, int64_t* value) { | |
165 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); | |
166 bool negative_value = false; | |
167 int32_t base = 10; | |
168 if (str[0] == '-') { | |
169 negative_value = true; | |
170 str += 1; | |
171 } | |
172 if ((strlen(str) > 2) && (str[0] == '0') && | |
sra1
2012/07/11 21:46:43
strlen scan not necessary since the conditions gua
siva
2012/07/12 18:28:23
Done.
| |
173 (str[1] == 'x' || str[1] == 'X')) { | |
174 base = 16; | |
175 } | |
176 errno = 0; | |
177 *value = strtoll(str, NULL, base); | |
sra1
2012/07/11 21:46:43
You should pass in &endptr and verify endptr != st
siva
2012/07/12 18:28:23
I am not sure I understand the value of this addit
sra1
2012/07/12 20:12:15
You don't get ERANGE or EINVAL for trailing junk.
siva
2012/07/16 19:45:47
Good point, I have addressed this in a different C
| |
178 if (errno == 0) { | |
179 if (negative_value) { | |
180 *value = -(*value); | |
181 } | |
182 return true; | |
183 } | |
184 return false; | |
185 } | |
186 | |
187 | |
164 void OS::PrintErr(const char* format, ...) { | 188 void OS::PrintErr(const char* format, ...) { |
165 va_list args; | 189 va_list args; |
166 va_start(args, format); | 190 va_start(args, format); |
167 VFPrint(stderr, format, args); | 191 VFPrint(stderr, format, args); |
168 va_end(args); | 192 va_end(args); |
169 } | 193 } |
170 | 194 |
171 | 195 |
172 void OS::InitOnce() { | 196 void OS::InitOnce() { |
173 // TODO(5411554): For now we check that initonce is called only once, | 197 // TODO(5411554): For now we check that initonce is called only once, |
(...skipping 12 matching lines...) Expand all Loading... | |
186 void OS::Abort() { | 210 void OS::Abort() { |
187 abort(); | 211 abort(); |
188 } | 212 } |
189 | 213 |
190 | 214 |
191 void OS::Exit(int code) { | 215 void OS::Exit(int code) { |
192 exit(code); | 216 exit(code); |
193 } | 217 } |
194 | 218 |
195 } // namespace dart | 219 } // namespace dart |
OLD | NEW |