VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/RTTimeZoneGetCurrent-win.cpp@ 83862

Last change on this file since 83862 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* $Id: RTTimeZoneGetCurrent-win.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * IPRT - RTTimeZoneGetCurrent, generic.
4 */
5
6/*
7 * Copyright (C) 2017-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/time.h>
32#include "internal/iprt.h"
33
34#include <iprt/errcore.h>
35#include <iprt/env.h>
36#include <iprt/string.h>
37#include <iprt/utf16.h>
38#include <iprt/win/windows.h>
39#include "internal-r3-win.h"
40
41
42/*********************************************************************************************************************************
43* Structures and Typedefs *
44*********************************************************************************************************************************/
45typedef DWORD (WINAPI *PFNGETDYNAMICTIMEZONEINFORMATION)(PDYNAMIC_TIME_ZONE_INFORMATION);
46
47
48/*********************************************************************************************************************************
49* Global Variables *
50*********************************************************************************************************************************/
51/** Pointer to the GetDynamicTimeZoneInformation API if present. */
52static PFNGETDYNAMICTIMEZONEINFORMATION g_pfnGetDynamicTimeZoneInformation = NULL;
53/** Flipped after we've tried to resolve g_pfnGetDynamicTimeZoneInformation. */
54static bool volatile g_fResolvedApi = false;
55
56
57RTDECL(int) RTTimeZoneGetCurrent(char *pszName, size_t cbName)
58{
59 AssertPtrReturn(pszName, VERR_INVALID_POINTER);
60 AssertReturn(cbName > 0, VERR_BUFFER_OVERFLOW);
61
62 /*
63 * Resolve API.
64 */
65 PFNGETDYNAMICTIMEZONEINFORMATION pfnApi;
66 if (g_fResolvedApi)
67 pfnApi = g_pfnGetDynamicTimeZoneInformation;
68 else
69 {
70 pfnApi = (PFNGETDYNAMICTIMEZONEINFORMATION)GetProcAddress(g_hModKernel32, "GetDynamicTimeZoneInformation");
71 g_pfnGetDynamicTimeZoneInformation = pfnApi;
72 g_fResolvedApi = true;
73 }
74
75 /*
76 * Call the API and convert the name we get.
77 */
78 union
79 {
80 TIME_ZONE_INFORMATION Tzi;
81 DYNAMIC_TIME_ZONE_INFORMATION DynTzi;
82 } uBuf;
83 RT_ZERO(uBuf);
84 DWORD dwRc;
85 PCRTUTF16 pwszSrcName;
86 size_t cwcSrcName;
87 if (pfnApi)
88 {
89 dwRc = pfnApi(&uBuf.DynTzi);
90 pwszSrcName = uBuf.DynTzi.TimeZoneKeyName;
91 cwcSrcName = RT_ELEMENTS(uBuf.DynTzi.TimeZoneKeyName);
92 }
93 else
94 {
95 /* Not sure how helpful this fallback really is... */
96 dwRc = GetTimeZoneInformation(&uBuf.Tzi);
97 pwszSrcName = uBuf.Tzi.StandardName;
98 cwcSrcName = RT_ELEMENTS(uBuf.Tzi.StandardName);
99 }
100 if (dwRc != TIME_ZONE_ID_INVALID)
101 {
102 Assert(*pwszSrcName != '\0');
103 return RTUtf16ToUtf8Ex(pwszSrcName, cwcSrcName, &pszName, cbName, &cbName);
104 }
105 return RTErrConvertFromWin32(GetLastError());
106}
107
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette