ReactOS 0.4.16-dev-732-g2d1144a
tzset.cpp File Reference
#include <corecrt_internal_time.h>
#include <locale.h>
Include dependency graph for tzset.cpp:

Go to the source code of this file.

Classes

struct  anonymous_namespace{tzset.cpp}::transitiondate
 

Namespaces

namespace  anonymous_namespace{tzset.cpp}
 

Enumerations

enum class  anonymous_namespace{tzset.cpp}::date_type { anonymous_namespace{tzset.cpp}::absolute_date , anonymous_namespace{tzset.cpp}::day_in_month }
 
enum class  anonymous_namespace{tzset.cpp}::transition_type { anonymous_namespace{tzset.cpp}::start_of_dst , anonymous_namespace{tzset.cpp}::end_of_dst }
 

Functions

static wchar_tget_tz_environment_variable (wchar_t(&local_buffer)[local_env_buffer_size]) throw ()
 
static void __cdecl tzset_os_copy_to_tzname (const wchar_t *const timezone_name, wchar_t *const wide_tzname, char *const narrow_tzname, unsigned int const code_page)
 
static void __cdecl tzset_from_system_nolock () throw ()
 
static void __cdecl tzset_env_copy_to_tzname (const wchar_t *const tz_env, wchar_t *const wide_tzname, char *const narrow_tzname, rsize_t const tzname_length)
 
static void __cdecl tzset_from_environment_nolock (_In_z_ wchar_t *tz_env) throw ()
 
static void __cdecl tzset_nolock () throw ()
 
void __cdecl _tzset ()
 
void __cdecl __tzset ()
 
static void __cdecl cvtdate (transition_type const trantype, date_type const datetype, int const year, int const month, int const week, int const dayofweek, int const date, int const hour, int const min, int const sec, int const msec) throw ()
 
static int __cdecl _isindst_nolock (tm *const tb) throw ()
 
int __cdecl _isindst (tm *const tb)
 

Variables

static wchar_tlast_wide_tz = nullptr
 
static int tz_api_used
 
static TIME_ZONE_INFORMATION tz_info
 
static __crt_state_management::dual_state_global< longtzset_init_state
 
size_t const anonymous_namespace{tzset.cpp}::local_env_buffer_size = 256
 
int const anonymous_namespace{tzset.cpp}::milliseconds_per_day = 24 * 60 * 60 * 1000
 
static transitiondate dststart = { -1, 0, 0 }
 
static transitiondate dstend = { -1, 0, 0 }
 

Function Documentation

◆ __tzset()

void __cdecl __tzset ( )

Definition at line 392 of file tzset.cpp.

393{
394 auto const first_time = tzset_init_state.dangerous_get_state_array() + __crt_state_management::get_current_state_index();
395
396 if (__crt_interlocked_read(first_time) != 0)
397 {
398 return;
399 }
400
402 __try
403 {
404 if (__crt_interlocked_read(first_time) != 0)
405 {
406 __leave;
407 }
408
409 tzset_nolock();
410
411 _InterlockedIncrement(first_time);
412 }
414 {
416 }
418}
void __cdecl __acrt_unlock(_In_ __acrt_lock_id lock)
Definition: locks.cpp:57
@ __acrt_time_lock
__acrt_lock(__acrt_heap_lock)
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)
#define __try
Definition: pseh2_64.h:172
#define __leave
Definition: pseh2_64.h:176
#define __endtry
Definition: pseh2_64.h:175
#define __finally
Definition: pseh2_64.h:174
static __crt_state_management::dual_state_global< long > tzset_init_state
Definition: tzset.cpp:30
static void __cdecl tzset_nolock()
Definition: tzset.cpp:338

Referenced by common_ftime_s(), common_localtime_s(), common_loctotime_t(), common_mktime(), and expand_time().

◆ _isindst()

int __cdecl _isindst ( tm *const  tb)

Definition at line 699 of file tzset.cpp.

700{
701 int retval = 0;
702
704 __try
705 {
707 }
709 {
711 }
713
714 return retval;
715}
static const WCHAR tb[]
Definition: suminfo.c:285
static int __cdecl _isindst_nolock(tm *const tb)
Definition: tzset.cpp:533
int retval
Definition: wcstombs.cpp:91

◆ _isindst_nolock()

static int __cdecl _isindst_nolock ( tm *const  tb)
throw (
)
static

Definition at line 533 of file tzset.cpp.

534{
535 int daylight = 0;
537 if (daylight == 0)
538 return 0;
539
540 // Compute (or recompute) the transition dates for Daylight Savings Time
541 // if necessary. The yr fields of dststart and dstend are compared to the
542 // year of interest to determine necessity.
543 if (tb->tm_year != dststart.yr || tb->tm_year != dstend.yr)
544 {
545 if (tz_api_used)
546 {
547 // Convert the start of daylight savings time to dststart:
548 if (tz_info.DaylightDate.wYear == 0)
549 {
550 cvtdate(
553 tb->tm_year,
557 0,
562 }
563 else
564 {
565 cvtdate(
568 tb->tm_year,
570 0,
571 0,
577 }
578
579 // Convert start of standard time to dstend:
580 if (tz_info.StandardDate.wYear == 0)
581 {
582 cvtdate(
585 tb->tm_year,
589 0,
594 }
595 else
596 {
597 cvtdate(
600 tb->tm_year,
602 0,
603 0,
609 }
610 }
611 else
612 {
613 // The GetTimeZoneInformation API was not used, or failed. We use
614 // the USA Daylight Savings Time rules as a fallback.
615 int startmonth = 3; // March
616 int startweek = 2; // Second week
617 int endmonth = 11;// November
618 int endweek = 1; // First week
619
620 // The rules changed in 2007:
621 if (107 > tb->tm_year)
622 {
623 startmonth = 4; // April
624 startweek = 1; // first week
625 endmonth = 10;// October
626 endweek = 5; // last week
627 }
628
629 cvtdate(
632 tb->tm_year,
633 startmonth,
634 startweek,
635 0, // Sunday
636 0,
637 2, // 02:00 (2 AM)
638 0,
639 0,
640 0);
641
642 cvtdate(
645 tb->tm_year,
646 endmonth,
647 endweek,
648 0, // Sunday
649 0,
650 2, // 02:00 (2 AM)
651 0,
652 0,
653 0);
654 }
655 }
656
657 // Handle simple cases first:
658 if (dststart.yd < dstend.yd)
659 {
660 // Northern hemisphere ordering:
661 if (tb->tm_yday < dststart.yd || tb->tm_yday > dstend.yd)
662 return 0;
663
664 if (tb->tm_yday > dststart.yd && tb->tm_yday < dstend.yd)
665 return 1;
666 }
667 else
668 {
669 // Southern hemisphere ordering:
670 if (tb->tm_yday < dstend.yd || tb->tm_yday > dststart.yd)
671 return 1;
672
673 if (tb->tm_yday > dstend.yd && tb->tm_yday < dststart.yd)
674 return 0;
675 }
676
677 long const ms = 1000 * (tb->tm_sec + 60 * tb->tm_min + 3600 * tb->tm_hour);
678
679 if (tb->tm_yday == dststart.yd)
680 {
681
682 return ms >= dststart.ms ? 1 : 0;
683 }
684 else
685 {
686 return ms < dstend.ms ? 1 : 0;
687 }
688}
#define _ERRCHECK(e)
_CRTIMP errno_t __cdecl _get_daylight(_Out_ int *_Daylight)
_CRTIMP int daylight
WORD wYear
Definition: winbase.h:930
WORD wMilliseconds
Definition: winbase.h:937
WORD wMonth
Definition: winbase.h:931
WORD wHour
Definition: winbase.h:934
WORD wSecond
Definition: winbase.h:936
WORD wMinute
Definition: winbase.h:935
WORD wDay
Definition: winbase.h:933
WORD wDayOfWeek
Definition: winbase.h:932
SYSTEMTIME DaylightDate
Definition: winbase.h:1236
SYSTEMTIME StandardDate
Definition: winbase.h:1233
static transitiondate dstend
Definition: tzset.cpp:60
static void __cdecl cvtdate(transition_type const trantype, date_type const datetype, int const year, int const month, int const week, int const dayofweek, int const date, int const hour, int const min, int const sec, int const msec)
Definition: tzset.cpp:430
static int tz_api_used
Definition: tzset.cpp:27
static TIME_ZONE_INFORMATION tz_info
Definition: tzset.cpp:28
static transitiondate dststart
Definition: tzset.cpp:59

Referenced by _isindst().

◆ _tzset()

void __cdecl _tzset ( void  )

Definition at line 373 of file tzset.cpp.

374{
376 __try
377 {
378 tzset_nolock();
379 }
381 {
383 }
385}

Referenced by _Strftime(), gettimeofday(), localtime(), and test__tzset().

◆ cvtdate()

static void __cdecl cvtdate ( transition_type const  trantype,
date_type const  datetype,
int const  year,
int const  month,
int const  week,
int const  dayofweek,
int const  date,
int const  hour,
int const  min,
int const  sec,
int const  msec 
)
throw (
)
static

Definition at line 430 of file tzset.cpp.

443{
444 int yearday;
445 int monthdow;
446 long dstbias = 0;
447
448 if (datetype == date_type::day_in_month)
449 {
450 // Figure out the year-day of the start of the month:
451 yearday = 1 + (__crt_time_is_leap_year(year)
452 ? _lpdays[month - 1]
453 : _days[month - 1]);
454
455 // Figureo ut the day of the week of the start of the month:
456 monthdow = (yearday + ((year - 70) * 365) +
458
459 // Figure out the year-day of the transition date:
460 if (monthdow <= dayofweek)
461 yearday += (dayofweek - monthdow) + (week - 1) * 7;
462 else
463 yearday += (dayofweek - monthdow) + week * 7;
464
465 // We may have to adjust the calculation above if week == 5 (meaning the
466 // last instance of the day in the month). Check if the year falls
467 // beyond after month and adjust accordingly:
468 int const days_to_compare = __crt_time_is_leap_year(year)
469 ? _lpdays[month]
470 : _days[month];
471
472 if (week == 5 && yearday > days_to_compare)
473 {
474 yearday -= 7;
475 }
476 }
477 else
478 {
479 yearday = __crt_time_is_leap_year(year)
480 ? _lpdays[month - 1]
481 : _days[month - 1];
482
483 yearday += date;
484 }
485
486 if (trantype == transition_type::start_of_dst)
487 {
488 dststart.yd = yearday;
489 dststart.ms = msec + (1000 * (sec + 60 * (min + 60 * hour)));
490
491 // Set the year field of dststart so that unnecessary calls to cvtdate()
492 // may be avoided:
493 dststart.yr = year;
494 }
495 else // end_of_dst
496 {
497 dstend.yd = yearday;
498 dstend.ms = msec + (1000 * (sec + 60 * (min + 60 * hour)));
499
500 // The converted date is still a DST date. We must convert to a standard
501 // (local) date while being careful the millisecond field does not
502 // overflow or underflow
503 _ERRCHECK(_get_dstbias(&dstbias));
504 dstend.ms += (dstbias * 1000);
505 if (dstend.ms < 0)
506 {
508 dstend.yd--;
509 }
510 else if (dstend.ms >= milliseconds_per_day)
511 {
513 dstend.yd++;
514 }
515
516 // Set the year field of dstend so that unnecessary calls to cvtdate()
517 // may be avoided:
518 dstend.yr = year;
519 }
520
521 return;
522}
#define _BASE_DOW
int const _lpdays[]
Definition: days.cpp:21
bool __cdecl __crt_time_is_leap_year(TimeType const yr)
TimeType __cdecl __crt_time_elapsed_leap_years(TimeType const yr)
int const _days[]
Definition: days.cpp:14
static const WCHAR month[12][4]
Definition: session.c:2150
__u16 date
Definition: mkdosfs.c:8
#define min(a, b)
Definition: monoChain.cc:55
_CRTIMP errno_t __cdecl _get_dstbias(_Out_ long *_Daylight_savings_bias)

Referenced by _isindst_nolock().

◆ get_tz_environment_variable()

static wchar_t * get_tz_environment_variable ( wchar_t(&)  local_buffer[local_env_buffer_size])
throw (
)
static

Definition at line 76 of file tzset.cpp.

77{
78 size_t required_length;
79 errno_t const status = _wgetenv_s(&required_length, local_buffer, local_env_buffer_size, L"TZ");
80 if (status == 0)
81 {
82 return local_buffer;
83 }
84
85 if (status != ERANGE)
86 {
87 return nullptr;
88 }
89
90 __crt_unique_heap_ptr<wchar_t> dynamic_buffer(_malloc_crt_t(wchar_t, required_length));
91 if (dynamic_buffer.get() == nullptr)
92 {
93 return nullptr;
94 }
95
96 size_t actual_length;
97 if (_wgetenv_s(&actual_length, dynamic_buffer.get(), required_length, L"TZ") != 0)
98 {
99 return nullptr;
100 }
101
102 return dynamic_buffer.detach();
103}
#define ERANGE
Definition: acclib.h:92
errno_t __cdecl _wgetenv_s(size_t *const required_count, wchar_t *const buffer, size_t const buffer_count, wchar_t const *const name)
Definition: getenv.cpp:179
size_t const local_env_buffer_size
Definition: tzset.cpp:54
#define L(x)
Definition: ntvdm.h:50
Definition: ps.c:97
int errno_t
Definition: corecrt.h:615

Referenced by tzset_nolock().

◆ tzset_env_copy_to_tzname()

static void __cdecl tzset_env_copy_to_tzname ( const wchar_t *const  tz_env,
wchar_t *const  wide_tzname,
char *const  narrow_tzname,
rsize_t const  tzname_length 
)
static

Definition at line 203 of file tzset.cpp.

204{
205 _ERRCHECK(wcsncpy_s(wide_tzname, _TZ_STRINGS_SIZE, tz_env, tzname_length));
206
207 // Historically when getting _tzname via TZ, the narrow environment was used to populate _tzname when getting _tzname.
208 // The narrow environment is always encoded in the ACP (so _tzname was encoded in the ACP when coming from TZ), but
209 // when getting _tzname from the OS, the current active code page (set via setlocale()) was used instead.
210 // To maintain behavior compatibility, we remain intentionally inconsistent with
211 // how _tzname is generated when getting time zone information from the OS by explicitly encoding with the ACP.
212 // UTF-8 mode is opt-in, so we can correct this inconsistency when the current code page is UTF-8.
213
214 // Invalid characters are replaced by closest approximation or default character.
215 // On other failure, simply leave _tzname blank.
218 0,
219 wide_tzname,
220 static_cast<int>(tzname_length),
221 narrow_tzname,
222 _TZ_STRINGS_SIZE - 1, // Leave room for null terminator
223 nullptr,
224 nullptr);
225}
return __acrt_WideCharToMultiByte(code_page, 0, buffer.get(), -1, result_size !=0 ? result :nullptr, result_size, nullptr, nullptr)
#define _TZ_STRINGS_SIZE
unsigned int __acrt_get_utf8_acp_compatibility_codepage()
#define wcsncpy_s(d, l, s, n)
Definition: utility.h:202

Referenced by tzset_from_environment_nolock().

◆ tzset_from_environment_nolock()

static void __cdecl tzset_from_environment_nolock ( _In_z_ wchar_t tz_env)
throw (
)
static

Definition at line 227 of file tzset.cpp.

228{
230 char** tzname = _tzname;
231 wchar_t** wide_tzname = __wide_tzname();
233
234 long timezone = 0;
235 int daylight = 0;
238
239 // Check to see if the TZ value is unchanged from an earlier call to this
240 // function. If it hasn't changed, we have no work to do:
241 if (last_wide_tz != nullptr && wcscmp(tz_env, last_wide_tz) == 0)
242 {
243 return;
244 }
245
246 // Update the global last_wide_tz variable:
247 auto new_wide_tz = _malloc_crt_t(wchar_t, wcslen(tz_env) + 1);
248 if (!new_wide_tz)
249 {
250 return;
251 }
252
254 last_wide_tz = new_wide_tz.detach();
255
256 _ERRCHECK(wcscpy_s(last_wide_tz, wcslen(tz_env) + 1, tz_env));
257
258 // Process TZ value and update _tzname, _timezone and _daylight.
259 memset(wide_tzname[0], 0, _TZ_STRINGS_SIZE * sizeof(wchar_t));
260 memset(wide_tzname[1], 0, _TZ_STRINGS_SIZE * sizeof(wchar_t));
263
264 rsize_t const tzname_length = 3;
265
266 // Copy standard time zone name (index 0)
267 tzset_env_copy_to_tzname(tz_env, wide_tzname[0], tzname[0], tzname_length);
268
269 // Skip first few characters if present.
270 for (rsize_t i = 0; i < tzname_length; ++i)
271 {
272 if (*tz_env)
273 {
274 ++tz_env;
275 }
276 }
277
278 // The time difference is of the form:
279 // [+|-]hh[:mm[:ss]]
280 // Check for the minus sign first:
281 bool const is_negative_difference = *tz_env == L'-';
282 if (is_negative_difference)
283 {
284 ++tz_env;
285 }
286
287 wchar_t * dummy;
288 int const decimal_base = 10;
289
290 // process, then skip over, the hours
291 timezone = wcstol(tz_env, &dummy, decimal_base) * 3600;
292 while (*tz_env == '+' || (*tz_env >= L'0' && *tz_env <= L'9'))
293 {
294 ++tz_env;
295 }
296
297
298 // Check if minutes were specified:
299 if (*tz_env == L':')
300 {
301 // Process, then skip over, the minutes
302 timezone += wcstol(++tz_env, &dummy, decimal_base) * 60;
303 while (*tz_env >= L'0' && *tz_env <= L'9')
304 {
305 ++tz_env;
306 }
307
308 // Check if seconds were specified:
309 if (*tz_env == L':')
310 {
311 // Process, then skip over, the seconds:
312 timezone += wcstol(++tz_env, &dummy, decimal_base);
313 while (*tz_env >= L'0' && *tz_env <= L'9')
314 {
315 ++tz_env;
316 }
317 }
318 }
319
320 if (is_negative_difference)
321 {
323 }
324
325 // Finally, check for a DST zone suffix:
326 daylight = *tz_env ? 1 : 0;
327
328 if (daylight)
329 {
330 // Copy daylight time zone name (index 1)
331 tzset_env_copy_to_tzname(tz_env, wide_tzname[1], tzname[1], tzname_length);
332 }
333
334 _set_timezone(timezone);
335 _set_daylight(daylight);
336}
_Check_return_ _Deref_ret_z_ wchar_t **__cdecl __wide_tzname()
Definition: timeset.cpp:185
size_t rsize_t
Definition: stubs.c:780
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define _BEGIN_SECURE_CRT_DEPRECATION_DISABLE
#define _free_crt
#define _END_SECURE_CRT_DEPRECATION_DISABLE
#define wcscpy_s(d, l, s)
Definition: utility.h:201
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP char * tzname[2]
_CRTIMP errno_t __cdecl _get_timezone(_Out_ long *_Timezone)
#define _tzname
Definition: time.h:88
#define memset(x, y, z)
Definition: compat.h:39
Definition: fake.h:14
static void __cdecl tzset_env_copy_to_tzname(const wchar_t *const tz_env, wchar_t *const wide_tzname, char *const narrow_tzname, rsize_t const tzname_length)
Definition: tzset.cpp:203
static wchar_t * last_wide_tz
Definition: tzset.cpp:23

Referenced by tzset_nolock().

◆ tzset_from_system_nolock()

static void __cdecl tzset_from_system_nolock ( )
throw (
)
static

Definition at line 127 of file tzset.cpp.

128{
130 char** tzname = _tzname;
131 wchar_t** wide_tzname = __wide_tzname();
133
134 long timezone = 0;
135 int daylight = 0;
136 long dstbias = 0;
139 _ERRCHECK(_get_dstbias (&dstbias ));
140
141 // If there is a last_wide_tz already, discard it:
143 last_wide_tz = nullptr;
144
145 if (GetTimeZoneInformation(&tz_info) != 0xFFFFFFFF)
146 {
147 // Record that the API was used:
148 tz_api_used = 1;
149
150 // Derive _timezone value from Bias and StandardBias fields.
151 timezone = tz_info.Bias * 60;
152
153 if (tz_info.StandardDate.wMonth != 0)
155
156 // Check to see if there is a daylight time bias. Since the StandardBias
157 // has been added into _timezone, it must be compensated for in the
158 // value computed for _dstbias:
160 {
161 daylight = 1;
162 dstbias = (tz_info.DaylightBias - tz_info.StandardBias) * 60;
163 }
164 else
165 {
166 daylight = 0;
167
168 // Set the bias to 0 because GetTimeZoneInformation may return
169 // TIME_ZONE_ID_DAYLIGHT even though there is no DST (e.g., in NT
170 // 3.51, this can happen if automatic DST adjustment is disabled
171 // in the Control Panel.
172 dstbias = 0;
173 }
174
175 memset(wide_tzname[0], 0, _TZ_STRINGS_SIZE * sizeof(wchar_t));
176 memset(wide_tzname[1], 0, _TZ_STRINGS_SIZE * sizeof(wchar_t));
179
180 // Try to grab the name strings for both the time zone and the daylight
181 // zone. Note the wide character strings in tz_info must be converted
182 // to multibyte character strings. The locale code page must be used
183 // for this. Note that if setlocale() has not yet been called with
184 // LC_ALL or LC_CTYPE, then the code page will be 0, which is CP_ACP,
185 // so we will use the host's default ANSI code page.
186 //
187 // CRT_REFACTOR TODO We use the current locale for this transformation.
188 // If per-thread locale has been enabled for this thread, then we'll be
189 // using this thread's locale to update a global variable that is
190 // accessed from multiple threads. Does the time zone information also
191 // need to be stored per-thread?
192 unsigned const code_page = ___lc_codepage_func();
193
196 }
197
198 _set_timezone(timezone);
199 _set_daylight(daylight);
200 _set_dstbias(dstbias);
201}
_Out_opt_ UINT * code_page
DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
Definition: timezone.c:262
_CRTIMP unsigned int __cdecl ___lc_codepage_func(void)
Definition: locale.c:629
WCHAR DaylightName[32]
Definition: winbase.h:1235
WCHAR StandardName[32]
Definition: winbase.h:1232
static void __cdecl tzset_os_copy_to_tzname(const wchar_t *const timezone_name, wchar_t *const wide_tzname, char *const narrow_tzname, unsigned int const code_page)
Definition: tzset.cpp:105

Referenced by tzset_nolock().

◆ tzset_nolock()

static void __cdecl tzset_nolock ( )
throw (
)
static

Definition at line 338 of file tzset.cpp.

339{
340 // Clear the flag indicated whether GetTimeZoneInformation was used.
341 tz_api_used = 0;
342
343 // Set year fields of dststart and dstend structures to -1 to ensure
344 // they are recomputed as after this
345 dststart.yr = dstend.yr = -1;
346
347 // Get the value of the TZ environment variable:
348 wchar_t local_env_buffer[local_env_buffer_size];
349 wchar_t* const tz_env = get_tz_environment_variable(local_env_buffer);
350
351 // If the buffer ended up being dynamically allocated, make sure we
352 // clean it up before we return:
353 __crt_unique_heap_ptr<wchar_t> tz_env_cleanup(tz_env == local_env_buffer
354 ? nullptr
355 : tz_env);
356
357 // If the environment variable is not available for whatever reason, update
358 // without using the environment (note that unless the Desktop CRT is loaded
359 // and we have access to non-MSDK APIs, we will always tak this path).
360 if (tz_env == nullptr || tz_env[0] == '\0')
362
363 return tzset_from_environment_nolock(tz_env);
364}
static void __cdecl tzset_from_environment_nolock(_In_z_ wchar_t *tz_env)
Definition: tzset.cpp:227
static wchar_t * get_tz_environment_variable(wchar_t(&local_buffer)[local_env_buffer_size])
Definition: tzset.cpp:76
static void __cdecl tzset_from_system_nolock()
Definition: tzset.cpp:127

Referenced by __tzset(), and _tzset().

◆ tzset_os_copy_to_tzname()

static void __cdecl tzset_os_copy_to_tzname ( const wchar_t *const  timezone_name,
wchar_t *const  wide_tzname,
char *const  narrow_tzname,
unsigned int const  code_page 
)
static

Definition at line 105 of file tzset.cpp.

106{
107 // Maximum time zone name from OS is 32 characters long
108 // (see https://docs.microsoft.com/en-us/windows/desktop/api/timezoneapi/ns-timezoneapi-_time_zone_information)
109 _ERRCHECK(wcsncpy_s(wide_tzname, _TZ_STRINGS_SIZE, timezone_name, 32));
110
111 // Invalid characters are replaced by closest approximation or default character.
112 // On other failure, leave narrow tzname blank.
114 code_page,
115 0,
116 timezone_name,
117 -1,
118 narrow_tzname,
119 _TZ_STRINGS_SIZE, // Passing -1 as source size, so null terminator included.
120 nullptr,
121 nullptr
122 );
123}

Referenced by tzset_from_system_nolock().

Variable Documentation

◆ dstend

transitiondate dstend = { -1, 0, 0 }
static

◆ dststart

transitiondate dststart = { -1, 0, 0 }
static

◆ last_wide_tz

wchar_t* last_wide_tz = nullptr
static

Definition at line 23 of file tzset.cpp.

Referenced by tzset_from_environment_nolock(), and tzset_from_system_nolock().

◆ tz_api_used

int tz_api_used
static

Definition at line 27 of file tzset.cpp.

Referenced by _isindst_nolock(), tzset_from_system_nolock(), and tzset_nolock().

◆ tz_info

TIME_ZONE_INFORMATION tz_info
static

Definition at line 28 of file tzset.cpp.

Referenced by _isindst_nolock(), common_ftime_s(), and tzset_from_system_nolock().

◆ tzset_init_state

__crt_state_management::dual_state_global<long> tzset_init_state
static

Definition at line 30 of file tzset.cpp.

Referenced by __tzset().