41#include "magick/studio.h"
42#if defined(MAGICKCORE_WINDOWS_SUPPORT)
43#include "magick/client.h"
44#include "magick/exception-private.h"
45#include "magick/image-private.h"
46#include "magick/locale_.h"
47#include "magick/log.h"
48#include "magick/magick.h"
49#include "magick/memory_.h"
50#include "magick/memory-private.h"
51#include "magick/nt-base.h"
52#include "magick/nt-base-private.h"
53#include "magick/resource_.h"
54#include "magick/timer.h"
55#include "magick/string_.h"
56#include "magick/string-private.h"
57#include "magick/utility.h"
58#include "magick/utility-private.h"
59#include "magick/version.h"
60#if defined(MAGICKCORE_LTDL_DELEGATE)
63#if defined(MAGICKCORE_CIPHER_SUPPORT)
71#if !defined(MAP_FAILED)
72#define MAP_FAILED ((void *)(LONG_PTR) -1)
74#define MaxWideByteExtent 100
88typedef struct _NTGhostInfo
91 (MagickDLLCall *delete_instance)(gs_main_instance *);
94 (MagickDLLCall *new_instance)(gs_main_instance **,
void *);
103#if !defined(MAGICKCORE_LTDL_DELEGATE)
105 *lt_slsearchpath = (
char *) NULL;
115 *ghost_handle = (
void *) NULL;
122 *wsaData = (WSADATA*) NULL;
125 long_paths_enabled = 2;
135const registry_roots[2] =
137 { HKEY_CURRENT_USER,
"HKEY_CURRENT_USER" },
138 { HKEY_LOCAL_MACHINE,
"HKEY_LOCAL_MACHINE" }
144#if !defined(MAGICKCORE_WINDOWS_SUPPORT)
145extern "C" BOOL WINAPI
146 DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved);
149static void MagickDLLCall NTGhostscriptDeleteInstance(
150 gs_main_instance *instance)
152 LockSemaphoreInfo(ghost_semaphore);
153 nt_ghost_info.delete_instance(instance);
154 nt_ghost_info.has_instance=MagickFalse;
155 UnlockSemaphoreInfo(ghost_semaphore);
158static int MagickDLLCall NTGhostscriptNewInstance(gs_main_instance **pinstance,
164 LockSemaphoreInfo(ghost_semaphore);
166 if (nt_ghost_info.has_instance == MagickFalse)
168 status=nt_ghost_info.new_instance(pinstance,caller_handle);
170 nt_ghost_info.has_instance=MagickTrue;
172 UnlockSemaphoreInfo(ghost_semaphore);
176static inline char *create_utf8_string(
const wchar_t *wideChar)
184 count=WideCharToMultiByte(CP_UTF8,0,wideChar,-1,NULL,0,NULL,NULL);
186 return((
char *) NULL);
187 utf8=(
char *) NTAcquireQuantumMemory(count+1,
sizeof(*utf8));
188 if (utf8 == (
char *) NULL)
189 return((
char *) NULL);
190 count=WideCharToMultiByte(CP_UTF8,0,wideChar,-1,utf8,count,NULL,NULL);
193 utf8=DestroyString(utf8);
194 return((
char *) NULL);
200static unsigned char *NTGetRegistryValue(HKEY root,
const char *key,DWORD flags,
217 wide_name[MaxWideByteExtent];
219 value=(
unsigned char *) NULL;
220 status=RegOpenKeyExA(root,key,0,(KEY_READ | flags),®istry_key);
221 if (status != ERROR_SUCCESS)
223 if (MultiByteToWideChar(CP_UTF8,0,name,-1,wide_name,MaxWideByteExtent) == 0)
225 RegCloseKey(registry_key);
228 status=RegQueryValueExW(registry_key,wide_name,0,&type,0,&size);
229 if ((status == ERROR_SUCCESS) && (type == REG_SZ))
234 wide=(LPBYTE) NTAcquireQuantumMemory((
const size_t) size,
sizeof(*wide));
235 if (wide != (LPBYTE) NULL)
237 status=RegQueryValueExW(registry_key,wide_name,0,&type,wide,&size);
238 if ((status == ERROR_SUCCESS) && (type == REG_SZ))
239 value=(
unsigned char *) create_utf8_string((
const wchar_t *) wide);
240 wide=(LPBYTE) RelinquishMagickMemory(wide);
243 RegCloseKey(registry_key);
290#if defined(_DLL) && defined(ProvideDllMain)
291BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
293 magick_unreferenced(lpvReserved);
297 case DLL_PROCESS_ATTACH:
308 MagickCoreGenesis((
const char*) NULL,MagickFalse);
309 wide_path=(
wchar_t *) NTAcquireQuantumMemory(MaxTextExtent,
311 if (wide_path == (
wchar_t *) NULL)
313 count=(ssize_t) GetModuleFileNameW(handle,wide_path,MaxTextExtent);
319 module_path=create_utf8_string(wide_path);
320 for ( ; count > 0; count--)
321 if (module_path[count] ==
'\\')
323 module_path[count+1]=
'\0';
326 path=(
char *) NTAcquireQuantumMemory(MaxTextExtent,16*
sizeof(*path));
327 if (path == (
char *) NULL)
329 module_path=DestroyString(module_path);
330 wide_path=(
wchar_t *) RelinquishMagickMemory(wide_path);
333 count=(ssize_t) GetEnvironmentVariable(
"PATH",path,16*MaxTextExtent);
334 if ((count != 0) && (strstr(path,module_path) == (
char *) NULL))
336 if ((strlen(module_path)+count+1) < (16*MaxTextExtent-1))
341 variable=(
char *) NTAcquireQuantumMemory(MaxTextExtent,
342 16*
sizeof(*variable));
343 if (variable == (
char *) NULL)
345 path=DestroyString(path);
346 module_path=DestroyString(module_path);
347 wide_path=(
wchar_t *) RelinquishMagickMemory(wide_path);
350 (void) FormatLocaleString(variable,16*MaxTextExtent,
351 "%s;%s",module_path,path);
352 SetEnvironmentVariable(
"PATH",variable);
353 variable=DestroyString(variable);
356 path=DestroyString(path);
357 module_path=DestroyString(module_path);
359 wide_path=(
wchar_t *) RelinquishMagickMemory(wide_path);
362 case DLL_PROCESS_DETACH:
364 MagickCoreTerminus();
374#if !defined(__MINGW32__)
399MagickPrivate
int gettimeofday (
struct timeval *time_value,
400 struct timezone *time_zone)
402#define EpochFiletime MagickLLConstant(116444736000000000)
407 if (time_value != (
struct timeval *) NULL)
418 GetSystemTimeAsFileTime(&file_time);
419 date_time.LowPart=file_time.dwLowDateTime;
420 date_time.HighPart=file_time.dwHighDateTime;
421 time=date_time.QuadPart;
424 time_value->tv_sec=(ssize_t) (time / 1000000);
425 time_value->tv_usec=(ssize_t) (time % 1000000);
427 if (time_zone != (
struct timezone *) NULL)
434 time_zone->tz_minuteswest=_timezone/60;
435 time_zone->tz_dsttime=_daylight;
465MagickExport
int NTAccessWide(
const char *path,
int mode)
473 path_wide=NTCreateWidePath(path);
474 if (path_wide == (
wchar_t *) NULL)
476 status=_waccess(path_wide,mode);
477 path_wide=(
wchar_t *) RelinquishMagickMemory(path_wide);
506MagickPrivate
char **NTArgvToUTF8(
const int argc,
wchar_t **argv)
514 utf8=(
char **) NTAcquireQuantumMemory(argc,
sizeof(*utf8));
515 if (utf8 == (
char **) NULL)
516 ThrowFatalException(ResourceLimitFatalError,
"UnableToConvertStringToARGV");
517 for (i=0; i < (ssize_t) argc; i++)
519 utf8[i]=create_utf8_string(argv[i]);
520 if (utf8[i] == (
char *) NULL)
522 for (i--; i >= 0; i--)
523 utf8[i]=DestroyString(utf8[i]);
524 ThrowFatalException(ResourceLimitFatalError,
525 "UnableToConvertStringToARGV");
554MagickPrivate
int NTCloseDirectory(DIR *entry)
556 assert(entry != (DIR *) NULL);
557 if (IsEventLogging() != MagickFalse)
558 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
559 FindClose(entry->hSearch);
560 entry=(DIR *) RelinquishMagickMemory(entry);
586MagickPrivate
int NTCloseLibrary(
void *handle)
588 return(!(FreeLibrary((HINSTANCE) handle)));
614MagickExport
wchar_t* NTCreateWidePath(
const char *utf8)
622 count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,NULL,0);
623 if ((count > MAX_PATH) && (strncmp(utf8,
"\\\\?\\",4) != 0) &&
624 (NTLongPathsEnabled() == MagickFalse))
627 buffer[MagickPathExtent];
636 (void) FormatLocaleString(buffer,MagickPathExtent,
"\\\\?\\%s",utf8);
638 longPath=(
wchar_t *) NTAcquireQuantumMemory((
size_t) count,
640 if (longPath == (
wchar_t *) NULL)
641 return((
wchar_t *) NULL);
642 count=MultiByteToWideChar(CP_UTF8,0,buffer,-1,longPath,count);
644 count=(int) GetShortPathNameW(longPath,shortPath,MAX_PATH);
645 longPath=(
wchar_t *) RelinquishMagickMemory(longPath);
646 if ((count < 5) || (count >= MAX_PATH))
647 return((
wchar_t *) NULL);
648 length=(size_t) count-3;
649 wide=(
wchar_t *) NTAcquireQuantumMemory(length,
sizeof(*wide));
650 wcscpy_s(wide,length,shortPath+4);
653 wide=(
wchar_t *) NTAcquireQuantumMemory((
size_t) count,
sizeof(*wide));
654 if ((wide != (
wchar_t *) NULL) &&
655 (MultiByteToWideChar(CP_UTF8,0,utf8,-1,wide,count) == 0))
656 wide=(
wchar_t *) RelinquishMagickMemory(wide);
680static BOOL ControlHandler(DWORD type)
683 AsynchronousResourceComponentTerminus();
687MagickPrivate
int NTControlHandler(
void)
689 return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
711MagickPrivate
double NTElapsedTime(
void)
731 if (frequency.QuadPart == 0)
733 if (QueryPerformanceFrequency(&frequency) == 0)
734 frequency.QuadPart=1;
736 if (frequency.QuadPart > 1)
738 QueryPerformanceCounter(&performance_count);
739 return((
double) performance_count.QuadPart/frequency.QuadPart);
741 GetSystemTime(&system_time);
742 SystemTimeToFileTime(&system_time,&elapsed_time.filetime);
743 return((
double) 1.0e-7*elapsed_time.filetime64);
774MagickPrivate
void NTErrorHandler(
const ExceptionType severity,
775 const char *reason,
const char *description)
778 buffer[3*MaxTextExtent],
782 if (reason == (
char *) NULL)
784 MagickCoreTerminus();
787 message=GetExceptionMessage(errno);
788 if ((description != (
char *) NULL) && errno)
789 (void) FormatLocaleString(buffer,MaxTextExtent,
"%s: %s (%s) [%s].\n",
790 GetClientName(),reason,description,message);
792 if (description != (
char *) NULL)
793 (void) FormatLocaleString(buffer,MaxTextExtent,
"%s: %s (%s).\n",
794 GetClientName(),reason,description);
797 (void) FormatLocaleString(buffer,MaxTextExtent,
"%s: %s [%s].\n",
798 GetClientName(),reason,message);
800 (
void) FormatLocaleString(buffer,MaxTextExtent,
"%s: %s.\n",
801 GetClientName(),reason);
802 message=DestroyString(message);
803 (void) MessageBox(NULL,buffer,
"ImageMagick Exception",MB_OK | MB_TASKMODAL |
804 MB_SETFOREGROUND | MB_ICONEXCLAMATION);
805 MagickCoreTerminus();
827MagickPrivate
int NTExitLibrary(
void)
857MagickPrivate MagickBooleanType NTGatherRandomData(
const size_t length,
858 unsigned char *random)
860#if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
867 handle=(HCRYPTPROV) NULL;
868 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
869 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET));
871 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
872 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET));
875 status=CryptGenRandom(handle,(DWORD) length,random);
878 status=CryptReleaseContext(handle,0);
881 status=CryptReleaseContext(handle,0);
914extern MagickPrivate
char *NTGetEnvironmentValue(
const char *name)
917 *environment = (
char *) NULL;
926 wide_name[MaxWideByteExtent];
928 if (MultiByteToWideChar(CP_UTF8,0,name,-1,wide_name,MaxWideByteExtent) == 0)
930 size=GetEnvironmentVariableW(wide_name,(LPWSTR) NULL,0);
933 wide=(LPWSTR) NTAcquireQuantumMemory((
const size_t) size,
sizeof(*wide));
934 if (wide == (LPWSTR) NULL)
936 if (GetEnvironmentVariableW(wide_name,wide,size) != 0)
937 environment=create_utf8_string(wide);
938 wide=(LPWSTR) RelinquishMagickMemory(wide);
966MagickPrivate MagickBooleanType NTGetExecutionPath(
char *path,
970 wide_path[MaxTextExtent];
972 (void) GetModuleFileNameW((HMODULE) NULL,wide_path,(DWORD) extent);
973 (void) WideCharToMultiByte(CP_UTF8,0,wide_path,-1,path,(
int) extent,NULL,
1000static char *NTGetLastErrorMessage(DWORD last_error)
1009 buffer = (LPVOID) NULL;
1011 status=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
1012 FORMAT_MESSAGE_FROM_SYSTEM,NULL,last_error,
1013 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR) &buffer,0,NULL);
1015 reason=AcquireString(
"An unknown error occurred");
1018 reason=AcquireString((
const char *) buffer);
1044MagickPrivate
const char *NTGetLibraryError(
void)
1047 last_error[MaxTextExtent];
1053 error=NTGetLastErrorMessage(GetLastError());
1055 (void) CopyMagickString(last_error,error,MaxTextExtent);
1056 error=DestroyString(error);
1085void *NTGetLibrarySymbol(
void *handle,
const char *name)
1090 proc_address=GetProcAddress((HMODULE) handle,(LPCSTR) name);
1091 if (proc_address == (FARPROC) NULL)
1092 return((
void *) NULL);
1093 return((
void *) proc_address);
1120MagickPrivate MagickBooleanType NTGetModulePath(
const char *module,
char *path)
1123 module_path[MaxTextExtent];
1132 handle=GetModuleHandle(module);
1133 if (handle == (HMODULE) NULL)
1134 return(MagickFalse);
1135 length=GetModuleFileName(handle,module_path,MaxTextExtent);
1137 GetPathComponent(module_path,HeadPath,path);
1162static int NTLocateGhostscript(DWORD flags,
int *root_index,
1163 const char **product_family,
int *major_version,
int *minor_version,
1175 "Artifex Ghostscript",
1184 *product_family=NULL;
1187 for (i=0; i < (ssize_t) (
sizeof(products)/
sizeof(products[0])); i++)
1190 key[MagickPathExtent];
1201 (void) FormatLocaleString(key,MagickPathExtent,
"SOFTWARE\\%s",products[i]);
1202 for (j=0; j < (ssize_t) (
sizeof(registry_roots)/
sizeof(registry_roots[0]));
1205 mode=KEY_READ | flags;
1206 if (RegOpenKeyExA(registry_roots[j].hkey,key,0,mode,&hkey) ==
1218 extent=
sizeof(key)/
sizeof(
char);
1219 for (k=0; RegEnumKeyA(hkey,k,key,extent) == ERROR_SUCCESS; k++)
1229 if (sscanf(key,
"%d.%d.%d",&major,&minor,&patch) != 3)
1230 if (sscanf(key,
"%d.%d",&major,&minor) != 2)
1232 if ((major > *major_version) ||
1233 ((major == *major_version) && (minor > *minor_version)) ||
1234 ((minor == *minor_version) && (patch > *patch_version)))
1237 *product_family=products[i];
1238 *major_version=major;
1239 *minor_version=minor;
1240 *patch_version=patch;
1244 (void) RegCloseKey(hkey);
1248 if (status == MagickFalse)
1254 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
"Ghostscript (%s) "
1255 "version %d.%d.%d",*product_family,*major_version,*minor_version,*patch_version);
1259static MagickBooleanType NTGhostscriptGetString(
const char *name,
1260 BOOL *is_64_bit,
char *value,
const size_t length)
1263 buffer[MagickPathExtent],
1267 *product_family = (
const char *) NULL;
1270 is_64_bit_version = FALSE;
1286 directory=(
char *) NULL;
1287 if (LocaleCompare(name,
"GS_DLL") == 0)
1289 directory=GetEnvironmentValue(
"MAGICK_GHOSTSCRIPT_PATH");
1290 if (directory != (
char *) NULL)
1292 (void) FormatLocaleString(buffer,MagickPathExtent,
"%s%sgsdll64.dll",
1293 directory,DirectorySeparator);
1294 if (IsPathAccessible(buffer) != MagickFalse)
1296 directory=DestroyString(directory);
1297 (void) CopyMagickString(value,buffer,length);
1298 if (is_64_bit != NULL)
1302 (void) FormatLocaleString(buffer,MagickPathExtent,
"%s%sgsdll32.dll",
1303 directory,DirectorySeparator);
1304 if (IsPathAccessible(buffer) != MagickFalse)
1306 directory=DestroyString(directory);
1307 (void) CopyMagickString(value,buffer,length);
1308 if (is_64_bit != NULL)
1312 return(MagickFalse);
1315 if (product_family == (
const char *) NULL)
1318#if defined(KEY_WOW64_32KEY)
1320 flags=KEY_WOW64_64KEY;
1322 flags=KEY_WOW64_32KEY;
1324 (void) NTLocateGhostscript(flags,&root_index,&product_family,
1325 &major_version,&minor_version,&patch_version);
1326 if (product_family == (
const char *) NULL)
1328 flags=KEY_WOW64_32KEY;
1330 is_64_bit_version=TRUE;
1332 flags=KEY_WOW64_64KEY;
1336 if (product_family == (
const char *) NULL)
1338 (void) NTLocateGhostscript(flags,&root_index,&product_family,
1339 &major_version,&minor_version,&patch_version);
1341 is_64_bit_version=TRUE;
1344 if (product_family == (
const char *) NULL)
1345 return(MagickFalse);
1346 if (is_64_bit != NULL)
1347 *is_64_bit=is_64_bit_version;
1348 (void) FormatLocaleString(buffer,MagickPathExtent,
"SOFTWARE\\%s\\%d.%.2d.%d",
1349 product_family,major_version,minor_version,patch_version);
1350 registry_value=NTGetRegistryValue(registry_roots[root_index].hkey,buffer,
1352 if (registry_value == (
unsigned char *) NULL)
1354 (void) FormatLocaleString(buffer,MagickPathExtent,
"SOFTWARE\\%s\\%d.%02d",
1355 product_family,major_version,minor_version);
1356 registry_value=NTGetRegistryValue(registry_roots[root_index].hkey,buffer,
1359 if (registry_value == (
unsigned char *) NULL)
1360 return(MagickFalse);
1361 (void) CopyMagickString(value,(
const char *) registry_value,length);
1362 registry_value=(
unsigned char *) RelinquishMagickMemory(registry_value);
1363 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1364 "registry: \"%s\\%s\\%s\"=\"%s\"",registry_roots[root_index].name,
1369static MagickBooleanType NTGhostscriptDLL(
char *path,
int length)
1372 dll[MagickPathExtent] = {
"" };
1378 if ((*dll ==
'\0') &&
1379 (NTGhostscriptGetString(
"GS_DLL",&is_64_bit,dll,
sizeof(dll)) != MagickTrue))
1380 return(MagickFalse);
1383 return(MagickFalse);
1386 return(MagickFalse);
1388 (void) CopyMagickString(path,dll,length);
1392static inline MagickBooleanType NTGhostscriptHasValidHandle()
1394 if ((nt_ghost_info.delete_instance == NULL) || (ghost_info.exit == NULL) ||
1395 (nt_ghost_info.new_instance == NULL) || (ghost_info.set_stdio == NULL) ||
1396 (ghost_info.init_with_args == NULL) || (ghost_info.revision == NULL))
1397 return(MagickFalse);
1401MagickPrivate
const GhostInfo *NTGhostscriptDLLVectors(
void)
1404 path[MaxTextExtent];
1407 ActivateSemaphoreInfo(&ghost_semaphore);
1408 LockSemaphoreInfo(ghost_semaphore);
1409 if (ghost_handle != (
void *) NULL)
1411 UnlockSemaphoreInfo(ghost_semaphore);
1412 if (NTGhostscriptHasValidHandle() == MagickFalse)
1413 return((GhostInfo *) NULL);
1414 return(&ghost_info);
1416 if (NTGhostscriptDLL(path,
sizeof(path)) == MagickFalse)
1418 UnlockSemaphoreInfo(ghost_semaphore);
1421 ghost_handle=lt_dlopen(path);
1422 if (ghost_handle == (
void *) NULL)
1424 UnlockSemaphoreInfo(ghost_semaphore);
1427 (void) memset((
void *) &nt_ghost_info,0,
sizeof(NTGhostInfo));
1428 nt_ghost_info.delete_instance=(void (MagickDLLCall *)(gs_main_instance *)) (
1429 lt_dlsym(ghost_handle,
"gsapi_delete_instance"));
1430 nt_ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,
1431 void *)) (lt_dlsym(ghost_handle,
"gsapi_new_instance"));
1432 nt_ghost_info.has_instance=MagickFalse;
1433 (void) memset((
void *) &ghost_info,0,
sizeof(GhostInfo));
1434 ghost_info.delete_instance=NTGhostscriptDeleteInstance;
1435 ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
1436 lt_dlsym(ghost_handle,
"gsapi_exit");
1437 ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
1438 char **)) (lt_dlsym(ghost_handle,
"gsapi_init_with_args"));
1439 ghost_info.new_instance=NTGhostscriptNewInstance;
1440 ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,
const char *,
1441 int,
int *)) (lt_dlsym(ghost_handle,
"gsapi_run_string"));
1442 ghost_info.set_stdio=(int (MagickDLLCall *)(gs_main_instance *,int(
1443 MagickDLLCall *)(
void *,
char *,int),
int(MagickDLLCall *)(
void *,
1444 const char *,int),
int(MagickDLLCall *)(
void *,
const char *,int)))
1445 (lt_dlsym(ghost_handle,
"gsapi_set_stdio"));
1446 ghost_info.revision=(int (MagickDLLCall *)(gsapi_revision_t *,int)) (
1447 lt_dlsym(ghost_handle,
"gsapi_revision"));
1448 UnlockSemaphoreInfo(ghost_semaphore);
1449 if (NTGhostscriptHasValidHandle() == MagickFalse)
1450 return((GhostInfo *) NULL);
1451 return(&ghost_info);
1480MagickPrivate
int NTGhostscriptEXE(
char *path,
int length)
1486 program[MaxTextExtent] = {
"" };
1489 is_64_bit_version = FALSE;
1491 if (*program ==
'\0')
1494 ActivateSemaphoreInfo(&ghost_semaphore);
1495 LockSemaphoreInfo(ghost_semaphore);
1496 if (*program ==
'\0')
1498 if (NTGhostscriptGetString(
"GS_DLL",&is_64_bit_version,program,
1499 sizeof(program)) == MagickFalse)
1501 UnlockSemaphoreInfo(ghost_semaphore);
1503 (void) CopyMagickString(program,
"gswin64c.exe",
sizeof(program));
1505 (void) CopyMagickString(program,
"gswin32c.exe",
sizeof(program));
1507 (void) CopyMagickString(path,program,length);
1510 p=strrchr(program,
'\\');
1511 if (p != (
char *) NULL)
1515 (void) ConcatenateMagickString(program,is_64_bit_version ?
1516 "gswin64c.exe" :
"gswin32c.exe",
sizeof(program));
1519 UnlockSemaphoreInfo(ghost_semaphore);
1521 (void) CopyMagickString(path,program,length);
1550MagickPrivate
int NTGhostscriptFonts(
char *path,
int length)
1553 buffer[MaxTextExtent],
1555 filename[MaxTextExtent];
1562 directory=GetEnvironmentValue(
"MAGICK_GHOSTSCRIPT_FONT_PATH");
1563 if (directory != (
char *) NULL)
1565 (void) CopyMagickString(buffer,directory,MaxTextExtent);
1566 directory=DestroyString(directory);
1570 if (NTGhostscriptGetString(
"GS_LIB",NULL,buffer,MaxTextExtent) == MagickFalse)
1573 for (p=buffer-1; p != (
char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1575 (void) CopyMagickString(path,p+1,length+1);
1576 q=strchr(path,DirectoryListSeparator);
1577 if (q != (
char *) NULL)
1579 (void) FormatLocaleString(filename,MaxTextExtent,
"%s%sfonts.dir",path,
1580 DirectorySeparator);
1581 if (IsPathAccessible(filename) != MagickFalse)
1583 (void) FormatLocaleString(filename,MaxTextExtent,
"%s%sn019003l.pfb",path,
1584 DirectorySeparator);
1585 if (IsPathAccessible(filename) != MagickFalse)
1611MagickPrivate
int NTGhostscriptUnLoadDLL(
void)
1617 ActivateSemaphoreInfo(&ghost_semaphore);
1618 LockSemaphoreInfo(ghost_semaphore);
1620 if (ghost_handle != (
void *) NULL)
1622 status=lt_dlclose(ghost_handle);
1623 ghost_handle=(
void *) NULL;
1624 (void) memset((
void *) &ghost_info,0,
sizeof(GhostInfo));
1626 UnlockSemaphoreInfo(ghost_semaphore);
1627 DestroySemaphoreInfo(&ghost_semaphore);
1649MagickPrivate
int NTInitializeLibrary(
void)
1672MagickPrivate
void NTInitializeWinsock(MagickBooleanType use_lock)
1677 ActivateSemaphoreInfo(&winsock_semaphore);
1678 LockSemaphoreInfo(winsock_semaphore);
1680 if (wsaData == (WSADATA *) NULL)
1682 wsaData=(WSADATA *) AcquireMagickMemory(
sizeof(WSADATA));
1683 if (WSAStartup(MAKEWORD(2,2),wsaData) != 0)
1684 ThrowFatalException(CacheFatalError,
"WSAStartup failed");
1687 UnlockSemaphoreInfo(winsock_semaphore);
1709MagickExport MagickBooleanType NTLongPathsEnabled()
1711 if (long_paths_enabled == 2)
1724 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1725 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1726 "SYSTEM\\CurrentControlSet\\Control\\FileSystem",0,KEY_READ,
1728 if (status != ERROR_SUCCESS)
1730 long_paths_enabled=0;
1731 RegCloseKey(registry_key);
1732 return(MagickFalse);
1735 status=RegQueryValueExA(registry_key,
"LongPathsEnabled",0,&type,NULL,
1737 if ((status != ERROR_SUCCESS) || (type != REG_DWORD))
1739 long_paths_enabled=0;
1740 RegCloseKey(registry_key);
1741 return(MagickFalse);
1743 status=RegQueryValueExA(registry_key,
"LongPathsEnabled",0,&type,
1744 (LPBYTE) &value,&size);
1745 RegCloseKey(registry_key);
1746 if (status != ERROR_SUCCESS)
1748 long_paths_enabled=0;
1749 return(MagickFalse);
1751 long_paths_enabled=(size_t) value;
1753 return(long_paths_enabled == 1 ? MagickTrue : MagickFalse);
1775MagickPrivate
void *NTMapMemory(
char *address,
size_t length,
int protection,
1776 int flags,
int file,MagickOffsetType offset)
1795 file_handle=INVALID_HANDLE_VALUE;
1796 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1797 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1798 map_handle=INVALID_HANDLE_VALUE;
1800 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1801 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1803 if (protection & PROT_WRITE)
1805 access_mode=FILE_MAP_WRITE;
1806 if (!(flags & MAP_PRIVATE))
1807 protection_mode=PAGE_READWRITE;
1810 access_mode=FILE_MAP_COPY;
1811 protection_mode=PAGE_WRITECOPY;
1815 if (protection & PROT_READ)
1817 access_mode=FILE_MAP_READ;
1818 protection_mode=PAGE_READONLY;
1820 if ((file == -1) && (flags & MAP_ANONYMOUS))
1821 file_handle=INVALID_HANDLE_VALUE;
1823 file_handle=(HANDLE) _get_osfhandle(file);
1824 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
1828 map=(
void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
1830 CloseHandle(map_handle);
1832 if (map == (
void *) NULL)
1833 return((
void *) ((
char *) MAP_FAILED));
1834 return((
void *) ((
char *) map));
1860MagickPrivate DIR *NTOpenDirectory(
const char *path)
1869 file_specification[MaxTextExtent];
1871 assert(path != (
const char *) NULL);
1872 length=MultiByteToWideChar(CP_UTF8,0,path,-1,file_specification,
1875 return((DIR *) NULL);
1876 if(wcsncat(file_specification,L
"\\*.*",MaxTextExtent-wcslen(
1877 file_specification)-1) == (
wchar_t*) NULL)
1878 return((DIR *) NULL);
1879 entry=(DIR *) AcquireCriticalMemory(
sizeof(DIR));
1880 entry->firsttime=TRUE;
1881 entry->hSearch=FindFirstFileW(file_specification,&entry->Win32FindData);
1882 if (entry->hSearch == INVALID_HANDLE_VALUE)
1884 entry=(DIR *) RelinquishMagickMemory(entry);
1885 return((DIR *) NULL);
1914static inline const char *GetSearchPath(
void)
1916#if defined(MAGICKCORE_LTDL_DELEGATE)
1917 return(lt_dlgetsearchpath());
1919 return(lt_slsearchpath);
1923static UINT ChangeErrorMode(
void)
1926 (CALLBACK *GETERRORMODE)(void);
1937 mode=SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
1939 handle=GetModuleHandle(
"kernel32.dll");
1940 if (handle == (HMODULE) NULL)
1941 return SetErrorMode(mode);
1943 getErrorMode=(GETERRORMODE) NTGetLibrarySymbol(handle,
"GetErrorMode");
1944 if (getErrorMode != (GETERRORMODE) NULL)
1945 mode=getErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
1947 return SetErrorMode(mode);
1950static inline void *NTLoadLibrary(
const char *filename)
1956 path[MaxTextExtent];
1958 length=MultiByteToWideChar(CP_UTF8,0,filename,-1,path,MaxTextExtent);
1960 return((
void *) NULL);
1961 return (
void *) LoadLibraryExW(path,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1964MagickPrivate
void *NTOpenLibrary(
const char *filename)
1967 path[MaxTextExtent];
1979 mode=ChangeErrorMode();
1980 handle=NTLoadLibrary(filename);
1981 if (handle == (
void *) NULL)
1984 while (p != (
const char*) NULL)
1986 q=strchr(p,DirectoryListSeparator);
1987 if (q != (
const char*) NULL)
1988 (void) CopyMagickString(path,p,q-p+1);
1990 (
void) CopyMagickString(path,p,MaxTextExtent);
1991 (void) ConcatenateMagickString(path,DirectorySeparator,MaxTextExtent);
1992 (void) ConcatenateMagickString(path,filename,MaxTextExtent);
1993 handle=NTLoadLibrary(path);
1994 if (handle != (
void *) NULL || q == (
const char*) NULL)
2027static inline wchar_t *create_wchar_mode(
const char *mode)
2035 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,NULL,0);
2036 wide=(
wchar_t *) AcquireQuantumMemory((
size_t) count+1,
2038 if (wide == (
wchar_t *) NULL)
2039 return((
wchar_t *) NULL);
2040 if (MultiByteToWideChar(CP_UTF8,0,mode,-1,wide,count) == 0)
2042 wide=(
wchar_t *) RelinquishMagickMemory(wide);
2043 return((
wchar_t *) NULL);
2046 wide[count] = L
'\0';
2047 wide[count-1] = L
'N';
2051MagickExport FILE *NTOpenFileWide(
const char* path,
const char* mode)
2060 path_wide=NTCreateWidePath(path);
2061 if (path_wide == (
wchar_t *) NULL)
2062 return((FILE *) NULL);
2063 mode_wide=create_wchar_mode(mode);
2064 if (mode_wide == (
wchar_t *) NULL)
2066 path_wide=(
wchar_t *) RelinquishMagickMemory(path_wide);
2067 return((FILE *) NULL);
2069 if (_wfopen_s(&file,path_wide,mode_wide) != 0)
2071 mode_wide=(
wchar_t *) RelinquishMagickMemory(mode_wide);
2072 path_wide=(
wchar_t *) RelinquishMagickMemory(path_wide);
2100MagickExport FILE *NTOpenPipeWide(
const char *command,
const char *type)
2113 length=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,5);
2116 length=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0);
2119 command_wide=(
wchar_t *) AcquireQuantumMemory((
size_t) length,
2120 sizeof(*command_wide));
2121 if (command_wide == (
wchar_t *) NULL)
2123 length=MultiByteToWideChar(CP_UTF8,0,command,-1,command_wide,length);
2125 file=_wpopen(command_wide,type_wide);
2126 command_wide=(
wchar_t *) RelinquishMagickMemory(command_wide);
2156MagickExport
int NTOpenWide(
const char* path,
int flags,mode_t mode)
2165 path_wide=NTCreateWidePath(path);
2166 if (path_wide == (
wchar_t *) NULL)
2169 status=_wsopen_s(&file_handle,path_wide,flags | O_NOINHERIT,_SH_DENYNO,mode);
2170 path_wide=(
wchar_t *) RelinquishMagickMemory(path_wide);
2171 return(status == 0 ? file_handle : -1);
2198MagickPrivate
struct dirent *NTReadDirectory(DIR *entry)
2206 if (entry == (DIR *) NULL)
2207 return((
struct dirent *) NULL);
2208 if (!entry->firsttime)
2210 status=FindNextFileW(entry->hSearch,&entry->Win32FindData);
2212 return((
struct dirent *) NULL);
2214 length=WideCharToMultiByte(CP_UTF8,0,entry->Win32FindData.cFileName,-1,
2215 entry->file_info.d_name,
sizeof(entry->file_info.d_name),NULL,NULL);
2217 return((
struct dirent *) NULL);
2218 entry->firsttime=FALSE;
2219 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
2220 return(&entry->file_info);
2245static inline wchar_t* resolve_symlink(
const wchar_t* path)
2256 file_handle=CreateFileW(path,GENERIC_READ,FILE_SHARE_READ |FILE_SHARE_WRITE |
2257 FILE_SHARE_DELETE,NULL,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,NULL);
2258 if (file_handle == INVALID_HANDLE_VALUE)
2259 return((
wchar_t *) NULL);
2260 link_length=GetFinalPathNameByHandleW(file_handle,NULL,0,
2261 FILE_NAME_NORMALIZED);
2262 link=(
wchar_t *) AcquireQuantumMemory(link_length,
sizeof(
wchar_t));
2263 if (link == (
wchar_t *) NULL)
2265 CloseHandle(file_handle);
2266 return((
wchar_t *) NULL);
2268 GetFinalPathNameByHandleW(file_handle,link,link_length,FILE_NAME_NORMALIZED);
2269 CloseHandle(file_handle);
2273MagickExport
char *NTRealPathWide(
const char *path)
2282 wide_path=NTCreateWidePath(path);
2283 wide_real_path=resolve_symlink(wide_path);
2284 if (wide_real_path == (
wchar_t*) NULL)
2289 full_path_length=GetFullPathNameW(wide_path,0,NULL,NULL);
2290 wide_real_path=(
wchar_t *) AcquireQuantumMemory(full_path_length,
2292 if (wide_real_path == (
wchar_t*) NULL)
2294 wide_path=(
wchar_t *) RelinquishMagickMemory(wide_path);
2295 return((
char*) NULL);
2297 GetFullPathNameW(wide_path,full_path_length,wide_real_path,NULL);
2299 wide_path=(
wchar_t *) RelinquishMagickMemory(wide_path);
2303 if (wcsncmp(wide_real_path,L
"\\\\?\\",4) == 0)
2304 real_path=create_utf8_string(wide_real_path+4);
2306 real_path=create_utf8_string(wide_real_path);
2307 wide_real_path=(
wchar_t *) RelinquishMagickMemory(wide_real_path);
2343MagickPrivate
unsigned char *NTRegistryKeyLookup(
const char *subkey)
2346 package_key[MaxTextExtent] =
"";
2351 (void) FormatLocaleString(package_key,MagickPathExtent,
2352 "SOFTWARE\\%s\\%s\\Q:%d",MagickPackageName,MagickLibVersionText,
2353 MAGICKCORE_QUANTUM_DEPTH);
2354 value=NTGetRegistryValue(HKEY_LOCAL_MACHINE,package_key,0,subkey);
2355 if (value == (
unsigned char *) NULL)
2356 value=NTGetRegistryValue(HKEY_CURRENT_USER,package_key,0,subkey);
2382MagickExport
int NTRemoveWide(
const char *path)
2390 path_wide=NTCreateWidePath(path);
2391 if (path_wide == (
wchar_t *) NULL)
2393 status=_wremove(path_wide);
2394 path_wide=(
wchar_t *) RelinquishMagickMemory(path_wide);
2422MagickExport
int NTRenameWide(
const char* source,
const char* destination)
2431 source_wide=NTCreateWidePath(source);
2432 if (source_wide == (
wchar_t *) NULL)
2434 destination_wide=NTCreateWidePath(destination);
2435 if (destination_wide == (
wchar_t *) NULL)
2437 source_wide=(
wchar_t *) RelinquishMagickMemory(source_wide);
2440 status=_wrename(source_wide,destination_wide);
2441 destination_wide=(
wchar_t *) RelinquishMagickMemory(destination_wide);
2442 source_wide=(
wchar_t *) RelinquishMagickMemory(source_wide);
2471MagickPrivate MagickBooleanType NTReportEvent(
const char *event,
2472 const MagickBooleanType error)
2483 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
2485 return(MagickFalse);
2487 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
2488 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
2489 DeregisterEventSource(handle);
2518MagickPrivate
unsigned char *NTResourceToBlob(
const char *
id)
2521#ifndef MAGICKCORE_LIBRARY_NAME
2523 path[MaxTextExtent];
2542 assert(
id != (
const char *) NULL);
2543 if (IsEventLogging() != MagickFalse)
2544 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
id);
2545#ifdef MAGICKCORE_LIBRARY_NAME
2546 handle=GetModuleHandle(MAGICKCORE_LIBRARY_NAME);
2548 (void) FormatLocaleString(path,MaxTextExtent,
"%s%s%s",GetClientPath(),
2549 DirectorySeparator,GetClientName());
2550 if (IsPathAccessible(path) != MagickFalse)
2551 handle=GetModuleHandle(path);
2553 handle=GetModuleHandle(0);
2556 return((
unsigned char *) NULL);
2557 resource=FindResource(handle,
id,
"IMAGEMAGICK");
2559 return((
unsigned char *) NULL);
2560 global=LoadResource(handle,resource);
2562 return((
unsigned char *) NULL);
2563 length=SizeofResource(handle,resource);
2564 value=(
unsigned char *) LockResource(global);
2567 FreeResource(global);
2568 return((
unsigned char *) NULL);
2570 blob=(
unsigned char *) AcquireQuantumMemory(length+MaxTextExtent,
2572 if (blob != (
unsigned char *) NULL)
2574 (void) memcpy(blob,value,length);
2577 UnlockResource(global);
2578 FreeResource(global);
2606MagickExport
int NTSetFileTimestamp(
const char *path,
struct stat *attributes)
2618 path_wide=NTCreateWidePath(path);
2619 if (path_wide == (WCHAR *) NULL)
2621 handle=CreateFileW(path_wide,FILE_WRITE_ATTRIBUTES,FILE_SHARE_WRITE |
2622 FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
2623 if (handle != (HANDLE) NULL)
2633 date_time.QuadPart=(ULONGLONG) (attributes->st_ctime*10000000LL)+
2634 116444736000000000LL;
2635 creation_time.dwLowDateTime=date_time.LowPart;
2636 creation_time.dwHighDateTime=date_time.HighPart;
2637 date_time.QuadPart=(ULONGLONG) (attributes->st_atime*10000000LL)+
2638 116444736000000000LL;
2639 last_access_time.dwLowDateTime=date_time.LowPart;
2640 last_access_time.dwHighDateTime=date_time.HighPart;
2641 date_time.QuadPart=(ULONGLONG) (attributes->st_mtime*10000000LL)+
2642 116444736000000000LL;
2643 last_write_time.dwLowDateTime=date_time.LowPart;
2644 last_write_time.dwHighDateTime=date_time.HighPart;
2645 status=SetFileTime(handle,&creation_time,&last_access_time,&last_write_time);
2646 CloseHandle(handle);
2649 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
2677MagickPrivate
int NTSetSearchPath(
const char *path)
2679#if defined(MAGICKCORE_LTDL_DELEGATE)
2680 lt_dlsetsearchpath(path);
2682 if (lt_slsearchpath != (
char *) NULL)
2683 lt_slsearchpath=DestroyString(lt_slsearchpath);
2684 if (path != (
char *) NULL)
2685 lt_slsearchpath=AcquireString(path);
2714MagickExport
int NTStatWide(
const char *path,
struct stat *attributes)
2722 path_wide=NTCreateWidePath(path);
2723 if (path_wide == (WCHAR *) NULL)
2725 status=wstat(path_wide,attributes);
2726 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
2755MagickPrivate
int NTSystemCommand(
const char *command,
char *output)
2757#define CleanupOutputHandles \
2758 if (read_output != (HANDLE) NULL) \
2760 CloseHandle(read_output); \
2761 read_output=(HANDLE) NULL; \
2762 CloseHandle(write_output); \
2763 write_output=(HANDLE) NULL; \
2766#define CopyLastError \
2767 last_error=GetLastError(); \
2768 if (output != (char *) NULL) \
2770 error=NTGetLastErrorMessage(last_error); \
2771 if (error != (char *) NULL) \
2773 CopyMagickString(output,error,MaxTextExtent); \
2774 error=DestroyString(error); \
2780 local_command[MaxTextExtent];
2805 if (command == (
char *) NULL)
2807 read_output=(HANDLE) NULL;
2808 write_output=(HANDLE) NULL;
2809 GetStartupInfo(&startup_info);
2810 startup_info.dwFlags=STARTF_USESHOWWINDOW;
2811 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
2812 (void) CopyMagickString(local_command,command,MaxTextExtent);
2813 asynchronous=command[strlen(command)-1] ==
'&' ? MagickTrue : MagickFalse;
2814 if (asynchronous != MagickFalse)
2816 local_command[strlen(command)-1]=
'\0';
2817 startup_info.wShowWindow=SW_SHOWDEFAULT;
2821 if (command[strlen(command)-1] ==
'|')
2822 local_command[strlen(command)-1]=
'\0';
2824 startup_info.wShowWindow=SW_HIDE;
2825 read_output=(HANDLE) NULL;
2826 if (output != (
char *) NULL)
2828 if (CreatePipe(&read_output,&write_output,NULL,0))
2830 if (SetHandleInformation(write_output,HANDLE_FLAG_INHERIT,
2831 HANDLE_FLAG_INHERIT))
2833 startup_info.dwFlags|=STARTF_USESTDHANDLES;
2834 startup_info.hStdOutput=write_output;
2835 startup_info.hStdError=write_output;
2838 CleanupOutputHandles;
2841 read_output=(HANDLE) NULL;
2844 status=CreateProcess((LPCTSTR) NULL,local_command,(LPSECURITY_ATTRIBUTES)
2845 NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) TRUE,(DWORD)
2846 NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
2851 CleanupOutputHandles;
2852 return(last_error == ERROR_FILE_NOT_FOUND ? 127 : -1);
2854 if (output != (
char *) NULL)
2856 if (asynchronous != MagickFalse)
2857 return(status == 0);
2859 status=STATUS_TIMEOUT;
2860 while (status == STATUS_TIMEOUT)
2865 status=WaitForSingleObject(process_info.hProcess,1000);
2867 if (read_output != (HANDLE) NULL)
2868 if (!PeekNamedPipe(read_output,NULL,0,NULL,&size,NULL))
2873 buffer[MagickPathExtent];
2878 if (ReadFile(read_output,buffer,MagickPathExtent-1,&bytes_read,NULL))
2883 count=MagickMin(MagickPathExtent-output_offset,
2884 (
size_t) bytes_read+1);
2887 CopyMagickString(output+output_offset,buffer,count);
2888 output_offset+=count-1;
2891 if (!PeekNamedPipe(read_output,NULL,0,NULL,&size,NULL))
2895 if (status != WAIT_OBJECT_0)
2898 CleanupOutputHandles;
2901 status=GetExitCodeProcess(process_info.hProcess,&child_status);
2905 CleanupOutputHandles;
2908 CloseHandle(process_info.hProcess);
2909 CloseHandle(process_info.hThread);
2910 CleanupOutputHandles;
2911 return((
int) child_status);
2937MagickPrivate ssize_t NTSystemConfiguration(
int name)
2946 GetSystemInfo(&system_info);
2947 return(system_info.dwPageSize);
2949 case _SC_PHYS_PAGES:
2957 status.dwLength=
sizeof(status);
2958 if (GlobalMemoryStatusEx(&status) == 0)
2960 GetSystemInfo(&system_info);
2961 return((ssize_t) status.ullTotalPhys/system_info.dwPageSize);
2995MagickPrivate
int NTTruncateFile(
int file,off_t length)
3007 file_handle=(HANDLE) _get_osfhandle(file);
3008 if (file_handle == INVALID_HANDLE_VALUE)
3010 low=(long) (length & 0xffffffffUL);
3011 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
3012 file_pointer=SetFilePointer(file_handle,low,&high,FILE_BEGIN);
3013 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
3015 if (SetEndOfFile(file_handle) == 0)
3044MagickPrivate
int NTUnmapMemory(
void *map,
size_t length)
3047 if (UnmapViewOfFile(map) == 0)
3071MagickPrivate
double NTUserTime(
void)
3101 OsVersionInfo.dwOSVersionInfoSize=
sizeof(OSVERSIONINFO);
3102 GetVersionEx(&OsVersionInfo);
3103 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
3104 return(NTElapsedTime());
3105 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
3106 &kernel_time.filetime,&user_time.filetime);
3109 return((
double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
3140MagickPrivate
void NTWarningHandler(
const ExceptionType severity,
3141 const char *reason,
const char *description)
3144 buffer[2*MaxTextExtent];
3147 if (reason == (
char *) NULL)
3149 if (description == (
char *) NULL)
3150 (void) FormatLocaleString(buffer,MaxTextExtent,
"%s: %s.\n",GetClientName(),
3153 (
void) FormatLocaleString(buffer,MaxTextExtent,
"%s: %s (%s).\n",
3154 GetClientName(),reason,description);
3155 (void) MessageBox(NULL,buffer,
"ImageMagick Warning",MB_OK | MB_TASKMODAL |
3156 MB_SETFOREGROUND | MB_ICONINFORMATION);
3177MagickPrivate
void NTWindowsGenesis(
void)
3182 mode=GetEnvironmentValue(
"MAGICK_ERRORMODE");
3183 if (mode != (
char *) NULL)
3185 (void) SetErrorMode(StringToInteger(mode));
3186 mode=DestroyString(mode);
3188#if defined(_DEBUG) && !defined(__MINGW32__)
3189 if (IsEventLogging() != MagickFalse)
3194 debug=_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
3196 debug |= _CRTDBG_DELAY_FREE_MEM_DF;
3197 debug |= _CRTDBG_LEAK_CHECK_DF;
3198 (void) _CrtSetDbgFlag(debug);
3205#if defined(MAGICKCORE_INSTALLED_SUPPORT)
3210 path=NTRegistryKeyLookup(
"LibPath");
3211 if (path != (
unsigned char *) NULL)
3216 lib_path=NTCreateWidePath((
const char *) path);
3217 if (lib_path != (
wchar_t *) NULL)
3219 SetDllDirectoryW(lib_path);
3220 lib_path=(
wchar_t *) RelinquishMagickMemory(lib_path);
3222 path=(
unsigned char *) RelinquishMagickMemory(path);
3246MagickPrivate
void NTWindowsTerminus(
void)
3248 NTGhostscriptUnLoadDLL();
3250 ActivateSemaphoreInfo(&winsock_semaphore);
3251 LockSemaphoreInfo(winsock_semaphore);
3252 if (wsaData != (WSADATA *) NULL)
3255 wsaData=(WSADATA *) RelinquishMagickMemory((
void *) wsaData);
3257 UnlockSemaphoreInfo(winsock_semaphore);
3258 DestroySemaphoreInfo(&winsock_semaphore);