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

Side by Side Diff: src/platform-posix.cc

Issue 160451: Guard local time posix functions from NaN value of invalid dates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 4 months 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 | « src/platform-nullos.cc ('k') | src/platform-win32.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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 int64_t OS::Ticks() { 80 int64_t OS::Ticks() {
81 // gettimeofday has microsecond resolution. 81 // gettimeofday has microsecond resolution.
82 struct timeval tv; 82 struct timeval tv;
83 if (gettimeofday(&tv, NULL) < 0) 83 if (gettimeofday(&tv, NULL) < 0)
84 return 0; 84 return 0;
85 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; 85 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec;
86 } 86 }
87 87
88 88
89 char* OS::LocalTimezone(double time) { 89 const char* OS::LocalTimezone(double time) {
90 ASSERT(!isnan(time));
90 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); 91 time_t tv = static_cast<time_t>(floor(time/msPerSecond));
91 struct tm* t = localtime(&tv); 92 struct tm* t = localtime(&tv);
92 return const_cast<char*>(t->tm_zone); 93 if (NULL == t) return "";
94 return t->tm_zone;
93 } 95 }
94 96
95 97
96 double OS::DaylightSavingsOffset(double time) { 98 double OS::DaylightSavingsOffset(double time) {
99 ASSERT(!isnan(time));
97 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); 100 time_t tv = static_cast<time_t>(floor(time/msPerSecond));
98 struct tm* t = localtime(&tv); 101 struct tm* t = localtime(&tv);
102 if (NULL == t) return nan_value();
99 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0; 103 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0;
100 } 104 }
101 105
102 106
103 double OS::LocalTimeOffset() { 107 double OS::LocalTimeOffset() {
104 time_t tv = time(NULL); 108 time_t tv = time(NULL);
105 struct tm* t = localtime(&tv); 109 struct tm* t = localtime(&tv);
106 // tm_gmtoff includes any daylight savings offset, so subtract it. 110 // tm_gmtoff includes any daylight savings offset, so subtract it.
107 return static_cast<double>(t->tm_gmtoff * msPerSecond - 111 return static_cast<double>(t->tm_gmtoff * msPerSecond -
108 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); 112 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 return ntohl(value); 358 return ntohl(value);
355 } 359 }
356 360
357 361
358 Socket* OS::CreateSocket() { 362 Socket* OS::CreateSocket() {
359 return new POSIXSocket(); 363 return new POSIXSocket();
360 } 364 }
361 365
362 366
363 } } // namespace v8::internal 367 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-nullos.cc ('k') | src/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698