Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 time_t seconds = static_cast<time_t>(seconds_since_epoch); | 21 time_t seconds = static_cast<time_t>(seconds_since_epoch); |
| 22 if (seconds != seconds_since_epoch) return false; | 22 if (seconds != seconds_since_epoch) return false; |
| 23 struct tm* error_code = localtime_r(&seconds, tm_result); | 23 struct tm* error_code = localtime_r(&seconds, tm_result); |
| 24 return error_code != NULL; | 24 return error_code != NULL; |
| 25 } | 25 } |
| 26 | 26 |
| 27 | 27 |
| 28 const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) { | 28 const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) { |
| 29 tm decomposed; | 29 tm decomposed; |
| 30 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); | 30 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); |
| 31 ASSERT(succeeded); | 31 // If unsuccessful, return an empty string like V8 does. |
| 32 return decomposed.tm_zone; | 32 return succeeded && decomposed.tm_zone != NULL ? decomposed.tm_zone : ""; |
|
siva
2012/10/25 23:31:40
suggest parens for better readability
return (succ
Tom Ball
2012/10/25 23:38:11
Done.
| |
| 33 } | 33 } |
| 34 | 34 |
| 35 | 35 |
| 36 int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) { | 36 int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) { |
| 37 tm decomposed; | 37 tm decomposed; |
| 38 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); | 38 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); |
| 39 ASSERT(succeeded); | |
| 40 // Even if the offset was 24 hours it would still easily fit into 32 bits. | 39 // Even if the offset was 24 hours it would still easily fit into 32 bits. |
|
siva
2012/10/25 23:31:40
Do we need to add the same comment here regarding
Tom Ball
2012/10/25 23:38:11
Done.
| |
| 41 return static_cast<int>(decomposed.tm_gmtoff); | 40 return succeeded ? static_cast<int>(decomposed.tm_gmtoff) : 0; |
| 42 } | 41 } |
| 43 | 42 |
| 44 | 43 |
| 45 int OS::GetLocalTimeZoneAdjustmentInSeconds() { | 44 int OS::GetLocalTimeZoneAdjustmentInSeconds() { |
| 46 // TODO(floitsch): avoid excessive calls to tzset? | 45 // TODO(floitsch): avoid excessive calls to tzset? |
| 47 tzset(); | 46 tzset(); |
| 48 // Even if the offset was 24 hours it would still easily fit into 32 bits. | 47 // Even if the offset was 24 hours it would still easily fit into 32 bits. |
| 49 // Note that Unix and Dart disagree on the sign. | 48 // Note that Unix and Dart disagree on the sign. |
| 50 return static_cast<int>(-timezone); | 49 return static_cast<int>(-timezone); |
| 51 } | 50 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 void OS::Abort() { | 205 void OS::Abort() { |
| 207 abort(); | 206 abort(); |
| 208 } | 207 } |
| 209 | 208 |
| 210 | 209 |
| 211 void OS::Exit(int code) { | 210 void OS::Exit(int code) { |
| 212 exit(code); | 211 exit(code); |
| 213 } | 212 } |
| 214 | 213 |
| 215 } // namespace dart | 214 } // namespace dart |
| OLD | NEW |