Switch to using GetEnvironmentVariableW on Windows (#6843).

This commit is contained in:
Dirk Lemstra
2023-11-10 09:08:31 +01:00
parent fb02f76da9
commit 8a69bfb2f1
3 changed files with 57 additions and 1 deletions
+2 -1
View File
@@ -83,7 +83,8 @@ static inline void *NTAcquireQuantumMemory(const size_t count,
}
extern MagickPrivate char
*NTGetLastError(void);
*NTGetLastError(void),
*NTGetEnvironmentValue(const char *);
#if !defined(MAGICKCORE_LTDL_DELEGATE)
extern MagickPrivate const char
+51
View File
@@ -764,6 +764,57 @@ MagickPrivate MagickBooleanType NTGatherRandomData(const size_t length,
% %
% %
% %
% N T G e t E n v i r o n m e n t V a l u e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% NTGetEnvironmentValue() returns the environment string that matches the
% specified name.
%
% The format of the NTGetEnvironmentValue method is:
%
% char *GetEnvironmentValue(const char *name)
%
% A description of each parameter follows:
%
% o name: the environment name.
%
*/
extern MagickPrivate char *NTGetEnvironmentValue(const char *name)
{
char
*environment = (char *) NULL;
DWORD
size;
LPWSTR
wide;
wchar_t
wide_name[50];
if (MultiByteToWideChar(CP_UTF8,0,name,-1,wide_name,50) == 0)
return(environment);
size=GetEnvironmentVariableW(wide_name,(LPWSTR) NULL,0);
if (size == 0)
return(environment);
wide=(LPWSTR) NTAcquireQuantumMemory((const size_t) size,sizeof(*wide));
if (wide == (LPWSTR) NULL)
return(environment);
if (GetEnvironmentVariableW(wide_name,wide,size) != 0)
environment=create_utf8_string(wide);
wide=(LPWSTR) RelinquishMagickMemory(wide);
return(environment);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% N T G e t E x e c u t i o n P a t h %
% %
% %
+4
View File
@@ -1159,6 +1159,9 @@ MagickExport ssize_t FormatMagickSize(const MagickSizeType size,
*/
MagickExport char *GetEnvironmentValue(const char *name)
{
#if defined(MAGICKCORE_WINDOWS_SUPPORT)
return(NTGetEnvironmentValue(name));
#else
const char
*environment;
@@ -1166,6 +1169,7 @@ MagickExport char *GetEnvironmentValue(const char *name)
if (environment == (const char *) NULL)
return((char *) NULL);
return(ConstantString(environment));
#endif
}
/*