% Windows NT Utility Methods for MagickCore %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% December 1996 %
% %
% %
-% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
#include "MagickCore/studio.h"
#if defined(MAGICKCORE_WINDOWS_SUPPORT)
#include "MagickCore/client.h"
+#include "MagickCore/exception-private.h"
#include "MagickCore/locale_.h"
#include "MagickCore/log.h"
#include "MagickCore/magick.h"
#include "MagickCore/memory_.h"
+#include "MagickCore/nt-base.h"
+#include "MagickCore/nt-base-private.h"
#include "MagickCore/resource_.h"
+#include "MagickCore/resource-private.h"
#include "MagickCore/timer.h"
#include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
#include "MagickCore/utility.h"
+#include "MagickCore/utility-private.h"
#include "MagickCore/version.h"
#if defined(MAGICKCORE_LTDL_DELEGATE)
# include "ltdl.h"
#endif
-#include "MagickCore/nt-base.h"
#if defined(MAGICKCORE_CIPHER_SUPPORT)
#include <ntsecapi.h>
#include <wincrypt.h>
static void
*ghost_handle = (void *) NULL;
\f
+struct
+{
+ const HKEY
+ hkey;
+
+ const char
+ *name;
+}
+const registry_roots[2] =
+{
+ { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
+ { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
+};
+
/*
External declarations.
*/
extern "C" BOOL WINAPI
DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved);
#endif
+
+static inline char *create_utf8_string(const wchar_t *wideChar)
+{
+ char
+ *utf8;
+
+ int
+ count;
+
+ count=WideCharToMultiByte(CP_UTF8,0,wideChar,-1,NULL,0,NULL,NULL);
+ if (count < 0)
+ return((char *) NULL);
+ utf8=(char *) AcquireQuantumMemory(count+1,sizeof(*utf8));
+ if (utf8 == (char *) NULL)
+ return((char *) NULL);
+ count=WideCharToMultiByte(CP_UTF8,0,wideChar,-1,utf8,count,NULL,NULL);
+ if (count == 0)
+ {
+ utf8=DestroyString(utf8);
+ return((char *) NULL);
+ }
+ utf8[count]=0;
+ return(utf8);
+}
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ssize_t
count;
- module_path=(char *) AcquireQuantumMemory(MaxTextExtent,
- sizeof(*module_path));
- if (module_path == (char *) NULL)
+ wchar_t
+ *wide_path;
+
+ wide_path=(wchar_t *) AcquireQuantumMemory(MaxTextExtent,
+ sizeof(*wide_path));
+ if (wide_path == (wchar_t *) NULL)
return(FALSE);
- count=(ssize_t) GetModuleFileName(handle,module_path,MaxTextExtent);
+ count=(ssize_t) GetModuleFileNameW(handle,wide_path,MaxTextExtent);
if (count != 0)
{
char
*path;
+ module_path=create_utf8_string(wide_path);
for ( ; count > 0; count--)
if (module_path[count] == '\\')
{
if (path == (char *) NULL)
{
module_path=DestroyString(module_path);
+ wide_path=(wchar_t *) RelinquishMagickMemory(wide_path);
return(FALSE);
}
count=(ssize_t) GetEnvironmentVariable("PATH",path,16*MaxTextExtent);
{
path=DestroyString(path);
module_path=DestroyString(module_path);
+ wide_path=(wchar_t *) RelinquishMagickMemory(wide_path);
return(FALSE);
}
(void) FormatLocaleString(variable,16*MaxTextExtent,
}
}
path=DestroyString(path);
+ module_path=DestroyString(module_path);
}
- module_path=DestroyString(module_path);
+ wide_path=(wchar_t *) RelinquishMagickMemory(wide_path);
break;
}
case DLL_PROCESS_DETACH:
% process.
%
*/
-MagickExport int Exit(int status)
+MagickPrivate int Exit(int status)
{
if (IsWindows95())
- TerminateProcess(GetCurrentProcess(),(unsigned int) status);
+ {
+ TerminateProcess(GetCurrentProcess(),(unsigned int) status);
+ return(0);
+ }
exit(status);
- return(0);
}
\f
-#if !defined(__MINGW32__)
+#if !defined(__MINGW32__) && !defined(__MINGW64__)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% o time_zone: the time zone.
%
*/
-MagickExport int gettimeofday (struct timeval *time_value,
+MagickPrivate int gettimeofday (struct timeval *time_value,
struct timezone *time_zone)
{
#define EpochFiletime MagickLLConstant(116444736000000000)
% int IsWindows95()
%
*/
-MagickExport int IsWindows95()
+MagickPrivate int IsWindows95()
{
OSVERSIONINFO
version_info;
% %
% %
% %
+% N T A r g v T o U T F 8 %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% NTArgvToUTF8() converts the wide command line arguments to UTF-8 to ensure
+% compatibility with Linux.
+%
+% The format of the NTArgvToUTF8 method is:
+%
+% char **NTArgvToUTF8(const int argc,wchar_t **argv)
+%
+% A description of each parameter follows:
+%
+% o argc: the number of command line arguments.
+%
+% o argv: the wide-character command line arguments.
+%
+*/
+MagickPrivate char **NTArgvToUTF8(const int argc,wchar_t **argv)
+{
+ char
+ **utf8;
+
+ ssize_t
+ i;
+
+ utf8=(char **) AcquireQuantumMemory(argc,sizeof(*utf8));
+ if (utf8 == (char **) NULL)
+ ThrowFatalException(ResourceLimitFatalError,"UnableToConvertStringToARGV");
+ for (i=0; i < (ssize_t) argc; i++)
+ {
+ utf8[i]=create_utf8_string(argv[i]);
+ if (utf8[i] == (char *) NULL)
+ {
+ for (i--; i >= 0; i--)
+ utf8[i]=DestroyString(utf8[i]);
+ ThrowFatalException(ResourceLimitFatalError,
+ "UnableToConvertStringToARGV");
+ }
+ }
+ return(utf8);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% N T C l o s e D i r e c t o r y %
% %
% %
% o entry: Specifies a pointer to a DIR structure.
%
*/
-MagickExport int NTCloseDirectory(DIR *entry)
+MagickPrivate int NTCloseDirectory(DIR *entry)
{
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
assert(entry != (DIR *) NULL);
% o handle: Specifies a handle to a previously loaded dynamic module.
%
*/
-MagickExport int NTCloseLibrary(void *handle)
+MagickPrivate int NTCloseLibrary(void *handle)
{
if (IsWindows95())
return(FreeLibrary((HINSTANCE) handle));
return(FALSE);
}
-MagickExport int NTControlHandler(void)
+MagickPrivate int NTControlHandler(void)
{
return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
}
% double NTElapsedTime(void)
%
*/
-MagickExport double NTElapsedTime(void)
+MagickPrivate double NTElapsedTime(void)
{
union
{
% o description: Specifies any description to the reason.
%
*/
-MagickExport void NTErrorHandler(const ExceptionType severity,
+MagickPrivate void NTErrorHandler(const ExceptionType severity,
const char *reason,const char *description)
{
char
% int NTExitLibrary(void)
%
*/
-MagickExport int NTExitLibrary(void)
+MagickPrivate int NTExitLibrary(void)
{
return(0);
}
% random: the random data is returned here.
%
*/
-MagickExport MagickBooleanType NTGatherRandomData(const size_t length,
+MagickPrivate MagickBooleanType NTGatherRandomData(const size_t length,
unsigned char *random)
{
#if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
% o extent: the maximum extent of the path.
%
*/
-MagickExport MagickBooleanType NTGetExecutionPath(char *path,
+MagickPrivate MagickBooleanType NTGetExecutionPath(char *path,
const size_t extent)
{
- GetModuleFileName(0,path,(DWORD) extent);
+ wchar_t
+ wide_path[MaxTextExtent];
+
+ (void) GetModuleFileNameW(0,wide_path,(DWORD) extent);
+ (void) WideCharToMultiByte(CP_UTF8,0,wide_path,-1,path,(int) extent,NULL,
+ NULL);
return(MagickTrue);
}
\f
% const char *NTGetLibraryError(void)
%
*/
-MagickExport const char *NTGetLibraryError(void)
+MagickPrivate const char *NTGetLibraryError(void)
{
static char
last_error[MaxTextExtent];
% path: the module path is returned here.
%
*/
-MagickExport MagickBooleanType NTGetModulePath(const char *module,char *path)
+MagickPrivate MagickBooleanType NTGetModulePath(const char *module,char *path)
{
char
module_path[MaxTextExtent];
%
*/
-static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
+static int NTGetRegistryValue(HKEY root,const char *key,DWORD flags,const char *name,
char *value,int *length)
{
BYTE
/*
Get a registry value: key = root\\key, named value = name.
*/
- if (RegOpenKeyExA(root,key,0,KEY_READ,&hkey) != ERROR_SUCCESS)
+ if (RegOpenKeyExA(root,key,0,KEY_READ | flags,&hkey) != ERROR_SUCCESS)
return(1); /* no match */
p=(BYTE *) value;
type=REG_SZ;
return(1); /* not found */
}
-static int NTLocateGhostscript(const char **product_family,int *major_version,
- int *minor_version)
+static int NTLocateGhostscript(DWORD flags,int *root_index,
+ const char **product_family,int *major_version,int *minor_version)
{
int
i;
/*
Find the most recent version of Ghostscript.
*/
- status=FALSE;
+ status=MagickFalse;
+ *root_index=0;
*product_family=NULL;
*major_version=5;
*minor_version=49; /* min version of Ghostscript is 5.50 */
key[MaxTextExtent];
HKEY
- hkey,
- root;
+ hkey;
+
+ int
+ j;
REGSAM
mode;
(void) FormatLocaleString(key,MaxTextExtent,"SOFTWARE\\%s",products[i]);
- root=HKEY_LOCAL_MACHINE;
- mode=KEY_READ;
-#if defined(KEY_WOW64_32KEY)
- mode|=KEY_WOW64_32KEY;
-#endif
- if (RegOpenKeyExA(root,key,0,mode,&hkey) == ERROR_SUCCESS)
- {
- DWORD
- extent;
-
- int
- j;
-
- /*
- Now enumerate the keys.
- */
- extent=sizeof(key)/sizeof(char);
- for (j=0; RegEnumKeyA(hkey,j,key,extent) == ERROR_SUCCESS; j++)
+ for (j=0; j < (ssize_t) (sizeof(registry_roots)/sizeof(registry_roots[0]));
+ j++)
+ {
+ mode=KEY_READ | flags;
+ if (RegOpenKeyExA(registry_roots[j].hkey,key,0,mode,&hkey) ==
+ ERROR_SUCCESS)
{
+ DWORD
+ extent;
+
int
- major,
- minor;
-
- major=0;
- minor=0;
- if (sscanf(key,"%d.%d",&major,&minor) != 2)
- continue;
- if ((major > *major_version) || ((major == *major_version) &&
- (minor > *minor_version)))
- {
- *product_family=products[i];
- *major_version=major;
- *minor_version=minor;
- status=TRUE;
- }
+ k;
+
+ /*
+ Now enumerate the keys.
+ */
+ extent=sizeof(key)/sizeof(char);
+ for (k=0; RegEnumKeyA(hkey,k,key,extent) == ERROR_SUCCESS; k++)
+ {
+ int
+ major,
+ minor;
+
+ major=0;
+ minor=0;
+ if (sscanf(key,"%d.%d",&major,&minor) != 2)
+ continue;
+ if ((major > *major_version) || ((major == *major_version) &&
+ (minor > *minor_version)))
+ {
+ *root_index=j;
+ *product_family=products[i];
+ *major_version=major;
+ *minor_version=minor;
+ status=MagickTrue;
+ }
+ }
+ (void) RegCloseKey(hkey);
}
- (void) RegCloseKey(hkey);
- }
+ }
}
- if (status == FALSE)
+ if (status == MagickFalse)
{
*major_version=0;
*minor_version=0;
return(status);
}
-static int NTGhostscriptGetString(const char *name,char *value,
- const size_t length)
+static int NTGhostscriptGetString(const char *name,BOOL *is_64_bit,
+ char *value,const size_t length)
{
char
- key[MaxTextExtent];
+ buffer[MaxTextExtent],
+ *directory;
int
- i,
extent;
static const char
- *product_family = (const char *) NULL;
+ *product_family=(const char *) NULL;
+
+ static BOOL
+ is_64_bit_version=FALSE;
static int
+ flags=0,
major_version=0,
- minor_version=0;
-
- struct
- {
- const HKEY
- hkey;
-
- const char
- *name;
- }
- hkeys[2] =
- {
- { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
- { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
- };
+ minor_version=0,
+ root_index=0;
/*
Get a string from the installed Ghostscript.
*/
*value='\0';
+ directory=(char *) NULL;
+ if (LocaleCompare(name, "GS_DLL") == 0)
+ {
+ directory=GetEnvironmentValue("MAGICK_GHOSTSCRIPT_PATH");
+ if (directory != (char *) NULL)
+ {
+ (void) FormatLocaleString(buffer,MaxTextExtent,"%s%sgsdll32.dll",
+ directory,DirectorySeparator);
+ if (IsPathAccessible(buffer) != MagickFalse)
+ {
+ (void) CopyMagickString(value,buffer,length);
+ if (is_64_bit != NULL)
+ *is_64_bit=FALSE;
+ return(TRUE);
+ }
+ (void) FormatLocaleString(buffer,MaxTextExtent,"%s%sgsdll64.dll",
+ directory,DirectorySeparator);
+ if (IsPathAccessible(buffer) != MagickFalse)
+ {
+ (void) CopyMagickString(value,buffer,length);
+ if (is_64_bit != NULL)
+ *is_64_bit=TRUE;
+ return(TRUE);
+ }
+ return(FALSE);
+ }
+ }
+ if (product_family == NULL)
+ {
+ flags=0;
+#if defined(KEY_WOW64_32KEY)
+#if defined(_WIN64)
+ flags=KEY_WOW64_64KEY;
+#else
+ flags=KEY_WOW64_32KEY;
+#endif
+ (void) NTLocateGhostscript(flags,&root_index,&product_family,
+ &major_version,&minor_version);
+ if (product_family == NULL)
+#if defined(_WIN64)
+ flags=KEY_WOW64_32KEY;
+ else
+ is_64_bit_version=TRUE;
+#else
+ flags=KEY_WOW64_64KEY;
+#endif
+#endif
+ }
if (product_family == NULL)
- (void) NTLocateGhostscript(&product_family,&major_version,&minor_version);
+ {
+ (void) NTLocateGhostscript(flags,&root_index,&product_family,
+ &major_version,&minor_version);
+#if !defined(_WIN64)
+ is_64_bit_version=TRUE;
+#endif
+ }
if (product_family == NULL)
return(FALSE);
- (void) FormatLocaleString(key,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
+ if (is_64_bit != NULL)
+ *is_64_bit=is_64_bit_version;
+ (void) FormatLocaleString(buffer,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
product_family,major_version,minor_version);
- for (i=0; i < (ssize_t) (sizeof(hkeys)/sizeof(hkeys[0])); i++)
- {
- extent=(int) length;
- if (NTGetRegistryValue(hkeys[i].hkey,key,name,value,&extent) == 0)
- {
- (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
- "registry: \"%s\\%s\\%s\"=\"%s\"",hkeys[i].name,key,name,value);
- return(TRUE);
- }
- (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
- "registry: \"%s\\%s\\%s\" (failed)",hkeys[i].name,key,name);
- }
+ extent=(int) length;
+ if (NTGetRegistryValue(registry_roots[root_index].hkey,buffer,flags,name,
+ value,&extent) == 0)
+ {
+ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
+ "registry: \"%s\\%s\\%s\"=\"%s\"",registry_roots[root_index].name,
+ buffer,name,value);
+ return(TRUE);
+ }
return(FALSE);
}
-MagickExport int NTGhostscriptDLL(char *path,int length)
+MagickPrivate int NTGhostscriptDLL(char *path,int length)
{
static char
dll[MaxTextExtent] = { "" };
+ static BOOL
+ is_64_bit_version;
+
*path='\0';
if ((*dll == '\0') &&
- (NTGhostscriptGetString("GS_DLL",dll,sizeof(dll)) == FALSE))
+ (NTGhostscriptGetString("GS_DLL",&is_64_bit_version,dll,sizeof(dll)) == FALSE))
+ return(FALSE);
+
+#if defined(_WIN64)
+ if (!is_64_bit_version)
return(FALSE);
+#else
+ if (is_64_bit_version)
+ return(FALSE);
+#endif
(void) CopyMagickString(path,dll,length);
return(TRUE);
}
% const GhostInfo *NTGhostscriptDLLVectors(void)
%
*/
-MagickExport const GhostInfo *NTGhostscriptDLLVectors(void)
+MagickPrivate const GhostInfo *NTGhostscriptDLLVectors(void)
{
if (NTGhostscriptLoadDLL() == FALSE)
return((GhostInfo *) NULL);
% o length: length of buffer.
%
*/
-MagickExport int NTGhostscriptEXE(char *path,int length)
+MagickPrivate int NTGhostscriptEXE(char *path,int length)
{
register char
*p;
static char
program[MaxTextExtent] = { "" };
+ static BOOL
+ is_64_bit_version = FALSE;
+
(void) CopyMagickString(path,"gswin32c.exe",length);
if ((*program == '\0') &&
- (NTGhostscriptGetString("GS_DLL",program,sizeof(program)) == FALSE))
+ (NTGhostscriptGetString("GS_DLL",&is_64_bit_version,program,sizeof(program)) == FALSE))
return(FALSE);
p=strrchr(program,'\\');
if (p != (char *) NULL)
{
p++;
*p='\0';
- (void) ConcatenateMagickString(program,"gswin32c.exe",sizeof(program));
+ (void) ConcatenateMagickString(program,is_64_bit_version ?
+ "gswin64c.exe" : "gswin32c.exe",sizeof(program));
}
(void) CopyMagickString(path,program,length);
return(TRUE);
% o length: length of the path buffer.
%
*/
-MagickExport int NTGhostscriptFonts(char *path,int length)
+MagickPrivate int NTGhostscriptFonts(char *path,int length)
{
char
buffer[MaxTextExtent],
+ *directory,
filename[MaxTextExtent];
register char
*q;
*path='\0';
- if (NTGhostscriptGetString("GS_LIB",buffer,MaxTextExtent) == FALSE)
- return(FALSE);
+ directory=GetEnvironmentValue("MAGICK_GHOSTSCRIPT_FONT_PATH");
+ if (directory != (char *) NULL)
+ {
+ (void) CopyMagickString(buffer,directory,MaxTextExtent);
+ directory=DestroyString(directory);
+ }
+ else
+ {
+ if (NTGhostscriptGetString("GS_LIB",NULL,buffer,MaxTextExtent) == FALSE)
+ return(FALSE);
+ }
for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
{
(void) CopyMagickString(path,p+1,length+1);
if (IsPathAccessible(filename) != MagickFalse)
return(TRUE);
}
+ *path='\0';
return(FALSE);
}
\f
% int NTGhostscriptLoadDLL(void)
%
*/
-MagickExport int NTGhostscriptLoadDLL(void)
+MagickPrivate int NTGhostscriptLoadDLL(void)
{
char
path[MaxTextExtent];
% int NTGhostscriptUnLoadDLL(void)
%
*/
-MagickExport int NTGhostscriptUnLoadDLL(void)
+MagickPrivate int NTGhostscriptUnLoadDLL(void)
{
int
status;
% int NTInitializeLibrary(void)
%
*/
-MagickExport int NTInitializeLibrary(void)
+MagickPrivate int NTInitializeLibrary(void)
{
return(0);
}
%
% The format of the NTMapMemory method is:
%
-% MagickExport void *NTMapMemory(char *address,size_t length,int protection,
+% MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
% int access,int file,MagickOffsetType offset)
%
*/
-MagickExport void *NTMapMemory(char *address,size_t length,int protection,
+MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
int flags,int file,MagickOffsetType offset)
{
DWORD
CloseHandle(map_handle);
}
if (map == (void *) NULL)
- return((void *) MAP_FAILED);
+ return((void *) ((char *) MAP_FAILED));
return((void *) ((char *) map));
}
\f
% o entry: Specifies a pointer to a DIR structure.
%
*/
-MagickExport DIR *NTOpenDirectory(const char *path)
+MagickPrivate DIR *NTOpenDirectory(const char *path)
{
- char
- file_specification[MaxTextExtent];
-
DIR
*entry;
size_t
length;
+ wchar_t
+ file_specification[MaxTextExtent];
+
assert(path != (const char *) NULL);
- length=CopyMagickString(file_specification,path,MaxTextExtent);
- if (length >= (MaxTextExtent-1))
- return((DIR *) NULL);
- length=ConcatenateMagickString(file_specification,DirectorySeparator,
+ length=MultiByteToWideChar(CP_UTF8,0,path,-1,file_specification,
MaxTextExtent);
- if (length >= (MaxTextExtent-1))
+ if (length == 0)
+ return((DIR *) NULL);
+ if(wcsncat(file_specification,(const wchar_t*) DirectorySeparator,
+ MaxTextExtent-wcslen(file_specification)-1) == (wchar_t*)NULL)
return((DIR *) NULL);
entry=(DIR *) AcquireMagickMemory(sizeof(DIR));
if (entry != (DIR *) NULL)
{
entry->firsttime=TRUE;
- entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
+ entry->hSearch=FindFirstFileW(file_specification,&entry->Win32FindData);
}
if (entry->hSearch == INVALID_HANDLE_VALUE)
{
- length=ConcatenateMagickString(file_specification,"\\*.*",MaxTextExtent);
- if (length >= (MaxTextExtent-1))
+ if(wcsncat(file_specification,L"*.*",
+ MaxTextExtent-wcslen(file_specification)-1) == (wchar_t*)NULL)
{
entry=(DIR *) RelinquishMagickMemory(entry);
return((DIR *) NULL);
}
- entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
+ entry->hSearch=FindFirstFileW(file_specification,&entry->Win32FindData);
if (entry->hSearch == INVALID_HANDLE_VALUE)
{
entry=(DIR *) RelinquishMagickMemory(entry);
%
*/
-static const char *GetSearchPath( void )
+static inline const char *GetSearchPath(void)
{
#if defined(MAGICKCORE_LTDL_DELEGATE)
return(lt_dlgetsearchpath());
#endif
}
-MagickExport void *NTOpenLibrary(const char *filename)
+static UINT ChangeErrorMode(void)
{
-#define MaxPathElements 31
+ typedef UINT
+ (CALLBACK *GETERRORMODE)(void);
- char
- buffer[MaxTextExtent];
+ GETERRORMODE
+ getErrorMode;
+
+ HMODULE
+ handle;
+
+ UINT
+ mode;
+
+ mode=SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
+ handle=GetModuleHandle("kernel32.dll");
+ if (handle == (HMODULE) NULL)
+ return SetErrorMode(mode);
+
+ getErrorMode=(GETERRORMODE) NTGetLibrarySymbol(handle,"GetErrorMode");
+ if (getErrorMode != (GETERRORMODE) NULL)
+ mode=getErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
+
+ return SetErrorMode(mode);
+}
+
+static inline void *NTLoadLibrary(const char *filename)
+{
int
- index;
+ length;
+
+ wchar_t
+ path[MaxTextExtent];
+
+ length=MultiByteToWideChar(CP_UTF8,0,filename,-1,path,MaxTextExtent);
+ if (length == 0)
+ return((void *) NULL);
+ return (void *) LoadLibraryExW(path,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
+}
+
+MagickPrivate void *NTOpenLibrary(const char *filename)
+{
+ char
+ path[MaxTextExtent];
register const char
*p,
*q;
- register int
- i;
-
UINT
mode;
void
*handle;
- mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
- handle=(void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
- if ((handle != (void *) NULL) || (GetSearchPath() == (char *) NULL))
+ mode=ChangeErrorMode();
+ handle=NTLoadLibrary(filename);
+ if (handle == (void *) NULL)
{
- SetErrorMode(mode);
- return(handle);
- }
- p=(char *) GetSearchPath();
- index=0;
- while (index < MaxPathElements)
- {
- q=strchr(p,DirectoryListSeparator);
- if (q == (char *) NULL)
+ p=GetSearchPath();
+ while (p != (const char*) NULL)
{
- (void) CopyMagickString(buffer,p,MaxTextExtent);
- (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
- (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
- handle=(void *) LoadLibraryEx(buffer,NULL,
- LOAD_WITH_ALTERED_SEARCH_PATH);
- break;
+ q=strchr(p,DirectoryListSeparator);
+ if (q != (const char*) NULL)
+ (void) CopyMagickString(path,p,q-p+1);
+ else
+ (void) CopyMagickString(path,p,MaxTextExtent);
+ (void) ConcatenateMagickString(path,DirectorySeparator,MaxTextExtent);
+ (void) ConcatenateMagickString(path,filename,MaxTextExtent);
+ handle=NTLoadLibrary(path);
+ if (handle != (void *) NULL || q == (const char*) NULL)
+ break;
+ p=q+1;
}
- i=q-p;
- (void) CopyMagickString(buffer,p,i+1);
- (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
- (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
- handle=(void *) LoadLibraryEx(buffer,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
- if (handle != (void *) NULL)
- break;
- p=q+1;
- }
+ }
SetErrorMode(mode);
return(handle);
}
% o entry: Specifies a pointer to a DIR structure.
%
*/
-MagickExport struct dirent *NTReadDirectory(DIR *entry)
+MagickPrivate struct dirent *NTReadDirectory(DIR *entry)
{
int
status;
return((struct dirent *) NULL);
if (!entry->firsttime)
{
- status=FindNextFile(entry->hSearch,&entry->Win32FindData);
+ status=FindNextFileW(entry->hSearch,&entry->Win32FindData);
if (status == 0)
return((struct dirent *) NULL);
}
- length=CopyMagickString(entry->file_info.d_name,
- entry->Win32FindData.cFileName,sizeof(entry->file_info.d_name));
- if (length >= sizeof(entry->file_info.d_name))
+ length=WideCharToMultiByte(CP_UTF8,0,entry->Win32FindData.cFileName,-1,
+ entry->file_info.d_name,sizeof(entry->file_info.d_name),NULL,NULL);
+ if (length == 0)
return((struct dirent *) NULL);
entry->firsttime=FALSE;
entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
% may coexist.
%
% Values are stored in the registry under a base path path similar to
-% "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\5.5.7\Q:16". The provided subkey
+% "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\6.7.4\Q:16" or
+% "HKEY_CURRENT_USER/SOFTWARE\ImageMagick\6.7.4\Q:16". The provided subkey
% is appended to this base path to form the full key.
%
% The format of the NTRegistryKeyLookup method is:
% "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
%
*/
-MagickExport unsigned char *NTRegistryKeyLookup(const char *subkey)
+MagickPrivate unsigned char *NTRegistryKeyLookup(const char *subkey)
{
char
package_key[MaxTextExtent];
(void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
registry_key=(HKEY) INVALID_HANDLE_VALUE;
status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
+ if (status != ERROR_SUCCESS)
+ status=RegOpenKeyExA(HKEY_CURRENT_USER,package_key,0,KEY_READ,
+ ®istry_key);
if (status != ERROR_SUCCESS)
{
registry_key=(HKEY) INVALID_HANDLE_VALUE;
% o error: MagickTrue the event is an error.
%
*/
-MagickExport MagickBooleanType NTReportEvent(const char *event,
+MagickPrivate MagickBooleanType NTReportEvent(const char *event,
const MagickBooleanType error)
{
const char
% o id: Specifies a string that identifies the resource.
%
*/
-MagickExport unsigned char *NTResourceToBlob(const char *id)
+MagickPrivate unsigned char *NTResourceToBlob(const char *id)
{
+
+#ifndef MAGICKCORE_LIBRARY_NAME
char
path[MaxTextExtent];
+#endif
DWORD
length;
assert(id != (const char *) NULL);
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
+#ifdef MAGICKCORE_LIBRARY_NAME
+ handle=GetModuleHandle(MAGICKCORE_LIBRARY_NAME);
+#else
(void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
DirectorySeparator,GetClientName());
if (IsPathAccessible(path) != MagickFalse)
handle=GetModuleHandle(path);
else
handle=GetModuleHandle(0);
+#endif
if (!handle)
return((unsigned char *) NULL);
resource=FindResource(handle,id,"IMAGEMAGICK");
% stream.
%
*/
-MagickExport void NTSeekDirectory(DIR *entry,ssize_t position)
+MagickPrivate void NTSeekDirectory(DIR *entry,ssize_t position)
{
(void) position;
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
% for DLL's that can be dynamically loaded.
%
*/
-MagickExport int NTSetSearchPath(const char *path)
+MagickPrivate int NTSetSearchPath(const char *path)
{
#if defined(MAGICKCORE_LTDL_DELEGATE)
lt_dlsetsearchpath(path);
% o flags: Option flags (ignored for Windows).
%
*/
-MagickExport int NTSyncMemory(void *address,size_t length,int flags)
+MagickPrivate int NTSyncMemory(void *address,size_t length,int flags)
{
(void) flags;
if (FlushViewOfFile(address,length) == MagickFalse)
% o command: This string is the command to execute.
%
*/
-MagickExport int NTSystemCommand(const char *command)
+MagickPrivate int NTSystemCommand(const char *command)
{
char
local_command[MaxTextExtent];
status;
MagickBooleanType
- background_process;
+ asynchronous;
PROCESS_INFORMATION
process_info;
startup_info.dwFlags=STARTF_USESHOWWINDOW;
startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
(void) CopyMagickString(local_command,command,MaxTextExtent);
- background_process=command[strlen(command)-1] == '&' ? MagickTrue :
- MagickFalse;
- if (background_process)
- local_command[strlen(command)-1]='\0';
- if (command[strlen(command)-1] == '|')
- local_command[strlen(command)-1]='\0';
- else
- startup_info.wShowWindow=SW_SHOWDEFAULT;
- status=CreateProcess((LPCTSTR) NULL,local_command,
- (LPSECURITY_ATTRIBUTES) NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,
- (DWORD) NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
+ asynchronous=command[strlen(command)-1] == '&' ? MagickTrue : MagickFalse;
+ if (asynchronous != MagickFalse)
+ {
+ local_command[strlen(command)-1]='\0';
+ startup_info.wShowWindow=SW_SHOWDEFAULT;
+ }
+ else
+ if (command[strlen(command)-1] == '|')
+ local_command[strlen(command)-1]='\0';
+ else
+ startup_info.wShowWindow=SW_HIDE;
+ status=CreateProcess((LPCTSTR) NULL,local_command,(LPSECURITY_ATTRIBUTES)
+ NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,(DWORD)
+ NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
&process_info);
if (status == 0)
return(-1);
- if (background_process)
+ if (asynchronous != MagickFalse)
return(status == 0);
status=WaitForSingleObject(process_info.hProcess,INFINITE);
if (status != WAIT_OBJECT_0)
% o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
%
*/
-MagickExport ssize_t NTSystemConfiguration(int name)
+MagickPrivate ssize_t NTSystemConfiguration(int name)
{
switch (name)
{
status;
GlobalMemoryStatus(&status);
- return((ssize_t) status.dwTotalPhys/system_info.dwPageSize);
+ return((ssize_t) status.dwTotalPhys/system_info.dwPageSize/4);
}
status.dwLength=sizeof(status);
if (module(&status) == 0)
return(0L);
- return((ssize_t) status.ullTotalPhys/system_info.dwPageSize);
+ return((ssize_t) status.ullTotalPhys/system_info.dwPageSize/4);
}
case _SC_OPEN_MAX:
return(2048);
% o entry: Specifies a pointer to a DIR structure.
%
*/
-MagickExport ssize_t NTTellDirectory(DIR *entry)
+MagickPrivate ssize_t NTTellDirectory(DIR *entry)
{
assert(entry != (DIR *) NULL);
return(0);
% o length: the file length.
%
*/
-MagickExport int NTTruncateFile(int file,off_t length)
+MagickPrivate int NTTruncateFile(int file,off_t length)
{
DWORD
file_pointer;
+ HANDLE
+ file_handle;
+
long
- file_handle,
high,
low;
- file_handle=_get_osfhandle(file);
- if (file_handle == -1L)
+ file_handle=(HANDLE) _get_osfhandle(file);
+ if (file_handle == (HANDLE) -1L)
return(-1);
low=(long) (length & 0xffffffffUL);
high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
- file_pointer=SetFilePointer((HANDLE) file_handle,low,&high,FILE_BEGIN);
+ file_pointer=SetFilePointer(file_handle,low,&high,FILE_BEGIN);
if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
return(-1);
- if (SetEndOfFile((HANDLE) file_handle) == 0)
+ if (SetEndOfFile(file_handle) == 0)
return(-1);
return(0);
}
% o length: the length of the binary large object.
%
*/
-MagickExport int NTUnmapMemory(void *map,size_t length)
+MagickPrivate int NTUnmapMemory(void *map,size_t length)
{
(void) length;
if (UnmapViewOfFile(map) == 0)
% double NTUserTime(void)
%
*/
-MagickExport double NTUserTime(void)
+MagickPrivate double NTUserTime(void)
{
DWORD
status;
% o description: Specifies any description to the reason.
%
*/
-MagickExport void NTWarningHandler(const ExceptionType severity,
+MagickPrivate void NTWarningHandler(const ExceptionType severity,
const char *reason,const char *description)
{
char
(void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
MB_SETFOREGROUND | MB_ICONINFORMATION);
}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% N T W i n d o w s G e n e s i s %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% NTWindowsGenesis() initializes the MagickCore Windows environment.
+%
+% The format of the NTWindowsGenesis method is:
+%
+% void NTWindowsGenesis(void)
+%
+*/
+MagickPrivate void NTWindowsGenesis(void)
+{
+ char
+ *mode;
+
+ mode=GetEnvironmentValue("MAGICK_ERRORMODE");
+ if (mode != (char *) NULL)
+ {
+ (void) SetErrorMode(StringToInteger(mode));
+ mode=DestroyString(mode);
+ }
+#if defined(_DEBUG) && !defined(__BORLANDC__) && !defined(__MINGW32__) && !defined(__MINGW64__)
+ if (IsEventLogging() != MagickFalse)
+ {
+ int
+ debug;
+
+ debug=_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
+ debug|=_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF;
+ (void) _CrtSetDbgFlag(debug);
+ _ASSERTE(_CrtCheckMemory());
+ }
+#endif
+}
#endif