From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 2735A38460B2; Wed, 3 Apr 2024 16:56:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2735A38460B2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1712163376; bh=3aPf4MD7hmKTHlheJivNjYPBCe61RWFsEBX++BTsNL4=; h=From:To:Subject:Date:From; b=MyyA5pHYDzjvbRl8vnpXnyhYEnCyRQA3LF2OYKwhWmSnZxWDIWe/xsWGtvw6a/ck8 Hdr9eR6I5ye2BbhwzLCyO6NzQTaegFw/Rtw55hsMfrkJLpusj5sNouKkSSvdToDzzY YUhP//yHqTuEeY0sA5nKuTNfQYaKr15kig4Vmuj0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_5-branch] Cygwin: tzset(1): use GetDynamicTimeZoneInformation X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/cygwin-3_5-branch X-Git-Oldrev: 372eaba70d64596e2825ea2f454dd85de3e50c58 X-Git-Newrev: 6c0240b54539d5396df1c6ee0c75b213e57c67bc Message-Id: <20240403165616.2735A38460B2@sourceware.org> Date: Wed, 3 Apr 2024 16:56:16 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D6c0240b5453= 9d5396df1c6ee0c75b213e57c67bc commit 6c0240b54539d5396df1c6ee0c75b213e57c67bc Author: Corinna Vinschen AuthorDate: Thu Mar 21 21:24:11 2024 +0100 Commit: Corinna Vinschen CommitDate: Wed Apr 3 18:53:56 2024 +0200 Cygwin: tzset(1): use GetDynamicTimeZoneInformation =20 Use official GetDynamicTimeZoneInformation() function instead of scanning the registry for the timezone keyname. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/utils/tzset.c | 67 ++++--------------------------------------------= ---- 1 file changed, 5 insertions(+), 62 deletions(-) diff --git a/winsup/utils/tzset.c b/winsup/utils/tzset.c index d369ff7a2cd3..0660da7d1d8e 100644 --- a/winsup/utils/tzset.c +++ b/winsup/utils/tzset.c @@ -15,10 +15,6 @@ details. */ #include #include =20 -#ifndef GEOID_NOT_AVAILABLE -#define GEOID_NOT_AVAILABLE -1 -#endif - /* The auto-generated tzmap.h contains the mapping table from Windows time= zone and country per ISO 3166-1 to POSIX timezone. For more info, see the f= ile itself. */ @@ -35,49 +31,6 @@ static struct option longopts[] =3D =20 static char opts[] =3D "hV"; =20 -#define REG_TZINFO L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformati= on" -#define REG_TZDB L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Z= ones" - -static inline HKEY -reg_open (HKEY pkey, PCWSTR path, const char *msg) -{ - LONG ret; - HKEY hkey; - - ret =3D RegOpenKeyExW (pkey, path, 0, KEY_READ, &hkey); - if (ret =3D=3D ERROR_SUCCESS) - return hkey; - if (msg) - fprintf (stderr, "%s: cannot open registry %s, error code %" PRIu32 "\= n", - program_invocation_short_name, msg, (unsigned int) ret); - return NULL; -} - -/* For symmetry */ -#define reg_close(hkey) RegCloseKey(hkey) - -static inline BOOL -reg_query (HKEY hkey, PCWSTR value, PWCHAR buf, DWORD size, const char *ms= g) -{ - LONG ret; - DWORD type; - - ret =3D RegQueryValueExW (hkey, value, 0, &type, (LPBYTE) buf, &size); - if (ret =3D=3D ERROR_SUCCESS) - return TRUE; - if (msg) - fprintf (stderr, "%s: cannot query registry %s, error code %" PRIu32 "= \n", - program_invocation_short_name, msg, (unsigned int) ret); - return FALSE; -} - -static inline BOOL -reg_enum (HKEY hkey, int idx, PWCHAR name, DWORD size) -{ - return RegEnumKeyExW (hkey, idx, name, &size, NULL, NULL, NULL, NULL) - =3D=3D ERROR_SUCCESS; -} - static void __attribute__ ((__noreturn__)) usage (FILE *stream) { @@ -119,8 +72,8 @@ print_version () int main (int argc, char **argv) { - HKEY hkey; - WCHAR keyname[256], country[10], *spc; + DYNAMIC_TIME_ZONE_INFORMATION tz; + WCHAR country[10], *spc; GEOID geo; int opt, idx, gotit =3D -1; =20 @@ -141,18 +94,8 @@ main (int argc, char **argv) if (optind < argc) usage (stderr); =20 - /* First fetch current timezone information from registry. */ - hkey =3D reg_open (HKEY_LOCAL_MACHINE, REG_TZINFO, "timezone information= "); - if (!hkey) + if (GetDynamicTimeZoneInformation (&tz) =3D=3D TIME_ZONE_ID_INVALID) return 1; - /* Vista introduced the TimeZoneKeyName value, which simplifies the - job a lot. */ - if (!reg_query (hkey, L"TimeZoneKeyName", keyname, sizeof keyname, NULL)) - { - reg_close (hkey); - return 1; - } - reg_close (hkey); =20 /* We fetch the current Geo-location of the user and convert it to an ISO 3166-1 compatible nation code. */ @@ -169,7 +112,7 @@ main (int argc, char **argv) /* Now iterate over the mapping table and find the right entry. */ for (idx =3D 0; idx < TZMAP_SIZE; ++idx) { - if (!wcscasecmp (keyname, tzmap[idx].win_tzkey)) + if (!wcscasecmp (tz.TimeZoneKeyName, tzmap[idx].win_tzkey)) { if (gotit < 0) gotit =3D idx; @@ -189,7 +132,7 @@ main (int argc, char **argv) fprintf (stderr, "%s: can't find matching POSIX timezone for " "Windows timezone \"%ls\"\n", - program_invocation_short_name, keyname); + program_invocation_short_name, tz.TimeZoneKeyName); return 1; } idx =3D gotit;