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

Side by Side Diff: runtime/vm/os_linux.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: 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
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 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
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
OLDNEW
« runtime/vm/os_android.cc ('K') | « runtime/vm/os_android.cc ('k') | runtime/vm/os_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698