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

Side by Side Diff: runtime/vm/os_android.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 | « no previous file | runtime/vm/os_linux.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 <time.h> 9 #include <time.h>
10 #include <sys/resource.h> 10 #include <sys/resource.h>
(...skipping 10 matching lines...) Expand all
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 : "";
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.
41 return static_cast<int>(decomposed.tm_gmtoff); 40 // If unsuccessful, return zero like V8 does.
41 return succeeded ? static_cast<int>(decomposed.tm_gmtoff) : 0;
42 } 42 }
43 43
44 44
45 int OS::GetLocalTimeZoneAdjustmentInSeconds() { 45 int OS::GetLocalTimeZoneAdjustmentInSeconds() {
46 // TODO(floitsch): avoid excessive calls to tzset? 46 // TODO(floitsch): avoid excessive calls to tzset?
47 tzset(); 47 tzset();
48 // Even if the offset was 24 hours it would still easily fit into 32 bits. 48 // 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. 49 // Note that Unix and Dart disagree on the sign.
50 return static_cast<int>(-timezone); 50 return static_cast<int>(-timezone);
51 } 51 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 void OS::Abort() { 206 void OS::Abort() {
207 abort(); 207 abort();
208 } 208 }
209 209
210 210
211 void OS::Exit(int code) { 211 void OS::Exit(int code) {
212 exit(code); 212 exit(code);
213 } 213 }
214 214
215 } // namespace dart 215 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/os_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698