Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: runtime/vm/os_macos.cc

Issue 11267051: Updated GetTimeZoneName() to return "" if localtime_r fails or has a NULL for its tm_zone value, li… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review feedback: added parens, comments. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/os_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
22 time_t seconds = static_cast<time_t>(seconds_since_epoch); 22 time_t seconds = static_cast<time_t>(seconds_since_epoch);
23 if (seconds != seconds_since_epoch) return false; 23 if (seconds != seconds_since_epoch) return false;
24 struct tm* error_code = localtime_r(&seconds, tm_result); 24 struct tm* error_code = localtime_r(&seconds, tm_result);
25 return error_code != NULL; 25 return error_code != NULL;
26 } 26 }
27 27
28 28
29 const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) { 29 const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) {
30 tm decomposed; 30 tm decomposed;
31 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); 31 bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
32 ASSERT(succeeded); 32 // If unsuccessful, return an empty string like V8 does.
33 return decomposed.tm_zone; 33 return (succeeded && (decomposed.tm_zone != NULL)) ? decomposed.tm_zone : "";
34 } 34 }
35 35
36 36
37 int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) { 37 int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) {
38 tm decomposed; 38 tm decomposed;
39 bool succeeded = LocalTime(seconds_since_epoch, &decomposed); 39 bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
40 ASSERT(succeeded);
41 // Even if the offset was 24 hours it would still easily fit into 32 bits. 40 // Even if the offset was 24 hours it would still easily fit into 32 bits.
42 return static_cast<int>(decomposed.tm_gmtoff); 41 // If unsuccessful, return zero like V8 does.
42 return succeeded ? static_cast<int>(decomposed.tm_gmtoff) : 0;
43 } 43 }
44 44
45 45
46 int OS::GetLocalTimeZoneAdjustmentInSeconds() { 46 int OS::GetLocalTimeZoneAdjustmentInSeconds() {
47 // TODO(floitsch): avoid excessive calls to tzset? 47 // TODO(floitsch): avoid excessive calls to tzset?
48 tzset(); 48 tzset();
49 // Even if the offset was 24 hours it would still easily fit into 32 bits. 49 // Even if the offset was 24 hours it would still easily fit into 32 bits.
50 // Note that Unix and Dart disagree on the sign. 50 // Note that Unix and Dart disagree on the sign.
51 return static_cast<int>(-timezone); 51 return static_cast<int>(-timezone);
52 } 52 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 void OS::Abort() { 181 void OS::Abort() {
182 abort(); 182 abort();
183 } 183 }
184 184
185 185
186 void OS::Exit(int code) { 186 void OS::Exit(int code) {
187 exit(code); 187 exit(code);
188 } 188 }
189 189
190 } // namespace dart 190 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/os_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698