diff --git a/MagickCore/nt-base-private.h b/MagickCore/nt-base-private.h index 98ac1bd825..8be06332b0 100644 --- a/MagickCore/nt-base-private.h +++ b/MagickCore/nt-base-private.h @@ -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 diff --git a/MagickCore/nt-base.c b/MagickCore/nt-base.c index 6fe9af78e3..aaf0bae9a0 100644 --- a/MagickCore/nt-base.c +++ b/MagickCore/nt-base.c @@ -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 % % % % % diff --git a/MagickCore/string.c b/MagickCore/string.c index d5c9fa1f91..02aeda2d20 100644 --- a/MagickCore/string.c +++ b/MagickCore/string.c @@ -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 } /*