mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2026-10-24 00:48:56 +03:00
tzsanitize: Fix test failures on MSVC.
* lib/tzsanitize.c: Include <windows.h>. (tzsanitize): Except on mingw, sanitize also the environment variable in the process environment block.
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
2026-10-01 Bruno Haible <bruno@clisp.org>
|
||||
|
||||
tzsanitize: Fix test failures on MSVC.
|
||||
* lib/tzsanitize.c: Include <windows.h>.
|
||||
(tzsanitize): Except on mingw, sanitize also the environment variable
|
||||
in the process environment block.
|
||||
|
||||
2026-10-01 Bruno Haible <bruno@clisp.org>
|
||||
|
||||
tzsanitize: New module.
|
||||
|
||||
@@ -25,6 +25,11 @@
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#if !defined __MINGW32__
|
||||
# define WIN32_LEAN_AND_MEAN /* avoid including junk */
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
tzsanitize (void)
|
||||
{
|
||||
@@ -51,5 +56,28 @@ tzsanitize (void)
|
||||
if (ws[0] == L'T' && ws[1] == L'Z' && ws[2] == L'=')
|
||||
ws[0] = L'$';
|
||||
}
|
||||
#if !defined __MINGW32__
|
||||
SetEnvironmentVariable ("TZ", NULL);
|
||||
#endif
|
||||
}
|
||||
#if !defined __MINGW32__
|
||||
/* On MSVC, we also need to sanitize the environment variables stored in the
|
||||
process's environment block.
|
||||
We don't lose much by assuming that the environment variable's value
|
||||
is not too large. */
|
||||
else
|
||||
{
|
||||
/* Documentation:
|
||||
<https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getenvironmentvariable> */
|
||||
char tz_buf[256];
|
||||
DWORD tz_len = GetEnvironmentVariable ("TZ", tz_buf, sizeof (tz_buf));
|
||||
if (tz_len > 0 && tz_len < sizeof (tz_buf)
|
||||
&& strchr (tz_buf, '/') != NULL)
|
||||
{
|
||||
/* Documentation:
|
||||
<https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setenvironmentvariable> */
|
||||
SetEnvironmentVariable ("TZ", NULL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user