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);
1654MagickExport MagickBooleanType NTIsSymlinkWide(
const char *path)
1662 path_wide=NTCreateWidePath(path);
1663 attributes=GetFileAttributesW(path_wide);
1664 if (attributes == INVALID_FILE_ATTRIBUTES)
1665 return(MagickFalse);
1666 return(((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) ? MagickTrue :
1688MagickPrivate
int NTInitializeLibrary(
void)
1711MagickPrivate
void NTInitializeWinsock(MagickBooleanType use_lock)
1716 ActivateSemaphoreInfo(&winsock_semaphore);
1717 LockSemaphoreInfo(winsock_semaphore);
1719 if (wsaData == (WSADATA *) NULL)
1721 wsaData=(WSADATA *) AcquireMagickMemory(
sizeof(WSADATA));
1722 if (WSAStartup(MAKEWORD(2,2),wsaData) != 0)
1723 ThrowFatalException(CacheFatalError,
"WSAStartup failed");
1726 UnlockSemaphoreInfo(winsock_semaphore);
1748MagickExport MagickBooleanType NTLongPathsEnabled()
1750 if (long_paths_enabled == 2)
1763 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1764 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1765 "SYSTEM\\CurrentControlSet\\Control\\FileSystem",0,KEY_READ,
1767 if (status != ERROR_SUCCESS)
1769 long_paths_enabled=0;
1770 RegCloseKey(registry_key);
1771 return(MagickFalse);
1774 status=RegQueryValueExA(registry_key,
"LongPathsEnabled",0,&type,NULL,
1776 if ((status != ERROR_SUCCESS) || (type != REG_DWORD))
1778 long_paths_enabled=0;
1779 RegCloseKey(registry_key);
1780 return(MagickFalse);
1782 status=RegQueryValueExA(registry_key,
"LongPathsEnabled",0,&type,
1783 (LPBYTE) &value,&size);
1784 RegCloseKey(registry_key);
1785 if (status != ERROR_SUCCESS)
1787 long_paths_enabled=0;
1788 return(MagickFalse);
1790 long_paths_enabled=(size_t) value;
1792 return(long_paths_enabled == 1 ? MagickTrue : MagickFalse);
1814MagickPrivate
void *NTMapMemory(
char *address,
size_t length,
int protection,
1815 int flags,
int file,MagickOffsetType offset)
1834 file_handle=INVALID_HANDLE_VALUE;
1835 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1836 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1837 map_handle=INVALID_HANDLE_VALUE;
1839 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1840 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1842 if (protection & PROT_WRITE)
1844 access_mode=FILE_MAP_WRITE;
1845 if (!(flags & MAP_PRIVATE))
1846 protection_mode=PAGE_READWRITE;
1849 access_mode=FILE_MAP_COPY;
1850 protection_mode=PAGE_WRITECOPY;
1854 if (protection & PROT_READ)
1856 access_mode=FILE_MAP_READ;
1857 protection_mode=PAGE_READONLY;
1859 if ((file == -1) && (flags & MAP_ANONYMOUS))
1860 file_handle=INVALID_HANDLE_VALUE;
1862 file_handle=(HANDLE) _get_osfhandle(file);
1863 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
1867 map=(
void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
1869 CloseHandle(map_handle);
1871 if (map == (
void *) NULL)
1872 return((
void *) ((
char *) MAP_FAILED));
1873 return((
void *) ((
char *) map));
1899MagickPrivate DIR *NTOpenDirectory(
const char *path)
1908 file_specification[MaxTextExtent];
1910 assert(path != (
const char *) NULL);
1911 length=MultiByteToWideChar(CP_UTF8,0,path,-1,file_specification,
1914 return((DIR *) NULL);
1915 if(wcsncat(file_specification,L
"\\*.*",MaxTextExtent-wcslen(
1916 file_specification)-1) == (
wchar_t*) NULL)
1917 return((DIR *) NULL);
1918 entry=(DIR *) AcquireCriticalMemory(
sizeof(DIR));
1919 entry->firsttime=TRUE;
1920 entry->hSearch=FindFirstFileW(file_specification,&entry->Win32FindData);
1921 if (entry->hSearch == INVALID_HANDLE_VALUE)
1923 entry=(DIR *) RelinquishMagickMemory(entry);
1924 return((DIR *) NULL);
1953static inline const char *GetSearchPath(
void)
1955#if defined(MAGICKCORE_LTDL_DELEGATE)
1956 return(lt_dlgetsearchpath());
1958 return(lt_slsearchpath);
1962static UINT ChangeErrorMode(
void)
1965 (CALLBACK *GETERRORMODE)(void);
1976 mode=SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
1978 handle=GetModuleHandle(
"kernel32.dll");
1979 if (handle == (HMODULE) NULL)
1980 return SetErrorMode(mode);
1982 getErrorMode=(GETERRORMODE) NTGetLibrarySymbol(handle,
"GetErrorMode");
1983 if (getErrorMode != (GETERRORMODE) NULL)
1984 mode=getErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
1986 return SetErrorMode(mode);
1989static inline void *NTLoadLibrary(
const char *filename)
1995 path[MaxTextExtent];
1997 length=MultiByteToWideChar(CP_UTF8,0,filename,-1,path,MaxTextExtent);
1999 return((
void *) NULL);
2000 return (
void *) LoadLibraryExW(path,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
2003MagickPrivate
void *NTOpenLibrary(
const char *filename)
2006 path[MaxTextExtent];
2018 mode=ChangeErrorMode();
2019 handle=NTLoadLibrary(filename);
2020 if (handle == (
void *) NULL)
2023 while (p != (
const char*) NULL)
2025 q=strchr(p,DirectoryListSeparator);
2026 if (q != (
const char*) NULL)
2027 (void) CopyMagickString(path,p,q-p+1);
2029 (
void) CopyMagickString(path,p,MaxTextExtent);
2030 (void) ConcatenateMagickString(path,DirectorySeparator,MaxTextExtent);
2031 (void) ConcatenateMagickString(path,filename,MaxTextExtent);
2032 handle=NTLoadLibrary(path);
2033 if (handle != (
void *) NULL || q == (
const char*) NULL)
2066static inline wchar_t *create_wchar_mode(
const char *mode)
2074 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,NULL,0);
2075 wide=(
wchar_t *) AcquireQuantumMemory((
size_t) count+1,
2077 if (wide == (
wchar_t *) NULL)
2078 return((
wchar_t *) NULL);
2079 if (MultiByteToWideChar(CP_UTF8,0,mode,-1,wide,count) == 0)
2081 wide=(
wchar_t *) RelinquishMagickMemory(wide);
2082 return((
wchar_t *) NULL);
2085 wide[count] = L
'\0';
2086 wide[count-1] = L
'N';
2090MagickExport FILE *NTOpenFileWide(
const char* path,
const char* mode)
2099 path_wide=NTCreateWidePath(path);
2100 if (path_wide == (
wchar_t *) NULL)
2101 return((FILE *) NULL);
2102 mode_wide=create_wchar_mode(mode);
2103 if (mode_wide == (
wchar_t *) NULL)
2105 path_wide=(
wchar_t *) RelinquishMagickMemory(path_wide);
2106 return((FILE *) NULL);
2108 if (_wfopen_s(&file,path_wide,mode_wide) != 0)
2110 mode_wide=(
wchar_t *) RelinquishMagickMemory(mode_wide);
2111 path_wide=(
wchar_t *) RelinquishMagickMemory(path_wide);
2139MagickExport FILE *NTOpenPipeWide(
const char *command,
const char *type)
2152 length=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,5);
2155 length=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0);
2158 command_wide=(
wchar_t *) AcquireQuantumMemory((
size_t) length,
2159 sizeof(*command_wide));
2160 if (command_wide == (
wchar_t *) NULL)
2162 length=MultiByteToWideChar(CP_UTF8,0,command,-1,command_wide,length);
2164 file=_wpopen(command_wide,type_wide);
2165 command_wide=(
wchar_t *) RelinquishMagickMemory(command_wide);
2195MagickExport
int NTOpenWide(
const char* path,
int flags,mode_t mode)
2204 path_wide=NTCreateWidePath(path);
2205 if (path_wide == (
wchar_t *) NULL)
2208 status=_wsopen_s(&file_handle,path_wide,flags | O_NOINHERIT,_SH_DENYNO,mode);
2209 path_wide=(
wchar_t *) RelinquishMagickMemory(path_wide);
2210 return(status == 0 ? file_handle : -1);
2237MagickPrivate
struct dirent *NTReadDirectory(DIR *entry)
2245 if (entry == (DIR *) NULL)
2246 return((
struct dirent *) NULL);
2247 if (!entry->firsttime)
2249 status=FindNextFileW(entry->hSearch,&entry->Win32FindData);
2251 return((
struct dirent *) NULL);
2253 length=WideCharToMultiByte(CP_UTF8,0,entry->Win32FindData.cFileName,-1,
2254 entry->file_info.d_name,
sizeof(entry->file_info.d_name),NULL,NULL);
2256 return((
struct dirent *) NULL);
2257 entry->firsttime=FALSE;
2258 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
2259 return(&entry->file_info);
2284static inline wchar_t* resolve_symlink(
const wchar_t* path)
2295 file_handle=CreateFileW(path,GENERIC_READ,FILE_SHARE_READ |FILE_SHARE_WRITE |
2296 FILE_SHARE_DELETE,NULL,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,NULL);
2297 if (file_handle == INVALID_HANDLE_VALUE)
2298 return((
wchar_t *) NULL);
2299 link_length=GetFinalPathNameByHandleW(file_handle,NULL,0,
2300 FILE_NAME_NORMALIZED);
2301 link=(
wchar_t *) AcquireQuantumMemory(link_length,
sizeof(
wchar_t));
2302 if (link == (
wchar_t *) NULL)
2304 CloseHandle(file_handle);
2305 return((
wchar_t *) NULL);
2307 GetFinalPathNameByHandleW(file_handle,link,link_length,FILE_NAME_NORMALIZED);
2308 CloseHandle(file_handle);
2312MagickExport
char *NTRealPathWide(
const char *path)
2321 wide_path=NTCreateWidePath(path);
2322 wide_real_path=resolve_symlink(wide_path);
2323 if (wide_real_path == (
wchar_t*) NULL)
2328 full_path_length=GetFullPathNameW(wide_path,0,NULL,NULL);
2329 wide_real_path=(
wchar_t *) AcquireQuantumMemory(full_path_length,
2331 if (wide_real_path == (
wchar_t*) NULL)
2333 wide_path=(
wchar_t *) RelinquishMagickMemory(wide_path);
2334 return((
char*) NULL);
2336 GetFullPathNameW(wide_path,full_path_length,wide_real_path,NULL);
2338 wide_path=(
wchar_t *) RelinquishMagickMemory(wide_path);
2342 if (wcsncmp(wide_real_path,L
"\\\\?\\",4) == 0)
2343 real_path=create_utf8_string(wide_real_path+4);
2345 real_path=create_utf8_string(wide_real_path);
2346 wide_real_path=(
wchar_t *) RelinquishMagickMemory(wide_real_path);
2382MagickPrivate
unsigned char *NTRegistryKeyLookup(
const char *subkey)
2385 package_key[MaxTextExtent] =
"";
2390 (void) FormatLocaleString(package_key,MagickPathExtent,
2391 "SOFTWARE\\%s\\%s\\Q:%d",MagickPackageName,MagickLibVersionText,
2392 MAGICKCORE_QUANTUM_DEPTH);
2393 value=NTGetRegistryValue(HKEY_LOCAL_MACHINE,package_key,0,subkey);
2394 if (value == (
unsigned char *) NULL)
2395 value=NTGetRegistryValue(HKEY_CURRENT_USER,package_key,0,subkey);
2421MagickExport
int NTRemoveWide(
const char *path)
2429 path_wide=NTCreateWidePath(path);
2430 if (path_wide == (
wchar_t *) NULL)
2432 status=_wremove(path_wide);
2433 path_wide=(
wchar_t *) RelinquishMagickMemory(path_wide);
2461MagickExport
int NTRenameWide(
const char* source,
const char* destination)
2470 source_wide=NTCreateWidePath(source);
2471 if (source_wide == (
wchar_t *) NULL)
2473 destination_wide=NTCreateWidePath(destination);
2474 if (destination_wide == (
wchar_t *) NULL)
2476 source_wide=(
wchar_t *) RelinquishMagickMemory(source_wide);
2479 status=_wrename(source_wide,destination_wide);
2480 destination_wide=(
wchar_t *) RelinquishMagickMemory(destination_wide);
2481 source_wide=(
wchar_t *) RelinquishMagickMemory(source_wide);
2510MagickPrivate MagickBooleanType NTReportEvent(
const char *event,
2511 const MagickBooleanType error)
2522 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
2524 return(MagickFalse);
2526 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
2527 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
2528 DeregisterEventSource(handle);
2557MagickPrivate
unsigned char *NTResourceToBlob(
const char *
id)
2560#ifndef MAGICKCORE_LIBRARY_NAME
2562 path[MaxTextExtent];
2581 assert(
id != (
const char *) NULL);
2582 if (IsEventLogging() != MagickFalse)
2583 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
id);
2584#ifdef MAGICKCORE_LIBRARY_NAME
2585 handle=GetModuleHandle(MAGICKCORE_LIBRARY_NAME);
2587 (void) FormatLocaleString(path,MaxTextExtent,
"%s%s%s",GetClientPath(),
2588 DirectorySeparator,GetClientName());
2589 if (IsPathAccessible(path) != MagickFalse)
2590 handle=GetModuleHandle(path);
2592 handle=GetModuleHandle(0);
2595 return((
unsigned char *) NULL);
2596 resource=FindResource(handle,
id,
"IMAGEMAGICK");
2598 return((
unsigned char *) NULL);
2599 global=LoadResource(handle,resource);
2601 return((
unsigned char *) NULL);
2602 length=SizeofResource(handle,resource);
2603 value=(
unsigned char *) LockResource(global);
2606 FreeResource(global);
2607 return((
unsigned char *) NULL);
2609 blob=(
unsigned char *) AcquireQuantumMemory(length+MaxTextExtent,
2611 if (blob != (
unsigned char *) NULL)
2613 (void) memcpy(blob,value,length);
2616 UnlockResource(global);
2617 FreeResource(global);
2645MagickExport
int NTSetFileTimestamp(
const char *path,
struct stat *attributes)
2657 path_wide=NTCreateWidePath(path);
2658 if (path_wide == (WCHAR *) NULL)
2660 handle=CreateFileW(path_wide,FILE_WRITE_ATTRIBUTES,FILE_SHARE_WRITE |
2661 FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
2662 if (handle != (HANDLE) NULL)
2672 date_time.QuadPart=(ULONGLONG) (attributes->st_ctime*10000000LL)+
2673 116444736000000000LL;
2674 creation_time.dwLowDateTime=date_time.LowPart;
2675 creation_time.dwHighDateTime=date_time.HighPart;
2676 date_time.QuadPart=(ULONGLONG) (attributes->st_atime*10000000LL)+
2677 116444736000000000LL;
2678 last_access_time.dwLowDateTime=date_time.LowPart;
2679 last_access_time.dwHighDateTime=date_time.HighPart;
2680 date_time.QuadPart=(ULONGLONG) (attributes->st_mtime*10000000LL)+
2681 116444736000000000LL;
2682 last_write_time.dwLowDateTime=date_time.LowPart;
2683 last_write_time.dwHighDateTime=date_time.HighPart;
2684 status=SetFileTime(handle,&creation_time,&last_access_time,&last_write_time);
2685 CloseHandle(handle);
2688 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
2716MagickPrivate
int NTSetSearchPath(
const char *path)
2718#if defined(MAGICKCORE_LTDL_DELEGATE)
2719 lt_dlsetsearchpath(path);
2721 if (lt_slsearchpath != (
char *) NULL)
2722 lt_slsearchpath=DestroyString(lt_slsearchpath);
2723 if (path != (
char *) NULL)
2724 lt_slsearchpath=AcquireString(path);
2753MagickExport
int NTStatWide(
const char *path,
struct stat *attributes)
2761 path_wide=NTCreateWidePath(path);
2762 if (path_wide == (WCHAR *) NULL)
2764 status=wstat(path_wide,attributes);
2765 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
2794MagickPrivate
int NTSystemCommand(
const char *command,
char *output)
2796#define CleanupOutputHandles \
2797 if (read_output != (HANDLE) NULL) \
2799 CloseHandle(read_output); \
2800 read_output=(HANDLE) NULL; \
2801 CloseHandle(write_output); \
2802 write_output=(HANDLE) NULL; \
2805#define CopyLastError \
2806 last_error=GetLastError(); \
2807 if (output != (char *) NULL) \
2809 error=NTGetLastErrorMessage(last_error); \
2810 if (error != (char *) NULL) \
2812 CopyMagickString(output,error,MaxTextExtent); \
2813 error=DestroyString(error); \
2819 local_command[MaxTextExtent];
2844 if (command == (
char *) NULL)
2846 read_output=(HANDLE) NULL;
2847 write_output=(HANDLE) NULL;
2848 GetStartupInfo(&startup_info);
2849 startup_info.dwFlags=STARTF_USESHOWWINDOW;
2850 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
2851 (void) CopyMagickString(local_command,command,MaxTextExtent);
2852 asynchronous=command[strlen(command)-1] ==
'&' ? MagickTrue : MagickFalse;
2853 if (asynchronous != MagickFalse)
2855 local_command[strlen(command)-1]=
'\0';
2856 startup_info.wShowWindow=SW_SHOWDEFAULT;
2860 if (command[strlen(command)-1] ==
'|')
2861 local_command[strlen(command)-1]=
'\0';
2863 startup_info.wShowWindow=SW_HIDE;
2864 read_output=(HANDLE) NULL;
2865 if (output != (
char *) NULL)
2867 if (CreatePipe(&read_output,&write_output,NULL,0))
2869 if (SetHandleInformation(write_output,HANDLE_FLAG_INHERIT,
2870 HANDLE_FLAG_INHERIT))
2872 startup_info.dwFlags|=STARTF_USESTDHANDLES;
2873 startup_info.hStdOutput=write_output;
2874 startup_info.hStdError=write_output;
2877 CleanupOutputHandles;
2880 read_output=(HANDLE) NULL;
2883 status=CreateProcess((LPCTSTR) NULL,local_command,(LPSECURITY_ATTRIBUTES)
2884 NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) TRUE,(DWORD)
2885 NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
2890 CleanupOutputHandles;
2891 return(last_error == ERROR_FILE_NOT_FOUND ? 127 : -1);
2893 if (output != (
char *) NULL)
2895 if (asynchronous != MagickFalse)
2896 return(status == 0);
2898 status=STATUS_TIMEOUT;
2899 while (status == STATUS_TIMEOUT)
2904 status=WaitForSingleObject(process_info.hProcess,1000);
2906 if (read_output != (HANDLE) NULL)
2907 if (!PeekNamedPipe(read_output,NULL,0,NULL,&size,NULL))
2912 buffer[MagickPathExtent];
2917 if (ReadFile(read_output,buffer,MagickPathExtent-1,&bytes_read,NULL))
2922 count=MagickMin(MagickPathExtent-output_offset,
2923 (
size_t) bytes_read+1);
2926 CopyMagickString(output+output_offset,buffer,count);
2927 output_offset+=count-1;
2930 if (!PeekNamedPipe(read_output,NULL,0,NULL,&size,NULL))
2934 if (status != WAIT_OBJECT_0)
2937 CleanupOutputHandles;
2940 status=GetExitCodeProcess(process_info.hProcess,&child_status);
2944 CleanupOutputHandles;
2947 CloseHandle(process_info.hProcess);
2948 CloseHandle(process_info.hThread);
2949 CleanupOutputHandles;
2950 return((
int) child_status);
2976MagickPrivate ssize_t NTSystemConfiguration(
int name)
2985 GetSystemInfo(&system_info);
2986 return(system_info.dwPageSize);
2988 case _SC_PHYS_PAGES:
2996 status.dwLength=
sizeof(status);
2997 if (GlobalMemoryStatusEx(&status) == 0)
2999 GetSystemInfo(&system_info);
3000 return((ssize_t) status.ullTotalPhys/system_info.dwPageSize);
3034MagickPrivate
int NTTruncateFile(
int file,off_t length)
3046 file_handle=(HANDLE) _get_osfhandle(file);
3047 if (file_handle == INVALID_HANDLE_VALUE)
3049 low=(long) (length & 0xffffffffUL);
3050 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
3051 file_pointer=SetFilePointer(file_handle,low,&high,FILE_BEGIN);
3052 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
3054 if (SetEndOfFile(file_handle) == 0)
3083MagickPrivate
int NTUnmapMemory(
void *map,
size_t length)
3086 if (UnmapViewOfFile(map) == 0)
3110MagickPrivate
double NTUserTime(
void)
3140 OsVersionInfo.dwOSVersionInfoSize=
sizeof(OSVERSIONINFO);
3141 GetVersionEx(&OsVersionInfo);
3142 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
3143 return(NTElapsedTime());
3144 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
3145 &kernel_time.filetime,&user_time.filetime);
3148 return((
double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
3179MagickPrivate
void NTWarningHandler(
const ExceptionType severity,
3180 const char *reason,
const char *description)
3183 buffer[2*MaxTextExtent];
3186 if (reason == (
char *) NULL)
3188 if (description == (
char *) NULL)
3189 (void) FormatLocaleString(buffer,MaxTextExtent,
"%s: %s.\n",GetClientName(),
3192 (
void) FormatLocaleString(buffer,MaxTextExtent,
"%s: %s (%s).\n",
3193 GetClientName(),reason,description);
3194 (void) MessageBox(NULL,buffer,
"ImageMagick Warning",MB_OK | MB_TASKMODAL |
3195 MB_SETFOREGROUND | MB_ICONINFORMATION);
3216MagickPrivate
void NTWindowsGenesis(
void)
3221 mode=GetEnvironmentValue(
"MAGICK_ERRORMODE");
3222 if (mode != (
char *) NULL)
3224 (void) SetErrorMode(StringToInteger(mode));
3225 mode=DestroyString(mode);
3227#if defined(_DEBUG) && !defined(__MINGW32__)
3228 if (IsEventLogging() != MagickFalse)
3233 debug=_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
3235 debug |= _CRTDBG_DELAY_FREE_MEM_DF;
3236 debug |= _CRTDBG_LEAK_CHECK_DF;
3237 (void) _CrtSetDbgFlag(debug);
3244#if defined(MAGICKCORE_INSTALLED_SUPPORT)
3249 path=NTRegistryKeyLookup(
"LibPath");
3250 if (path != (
unsigned char *) NULL)
3255 lib_path=NTCreateWidePath((
const char *) path);
3256 if (lib_path != (
wchar_t *) NULL)
3258 SetDllDirectoryW(lib_path);
3259 lib_path=(
wchar_t *) RelinquishMagickMemory(lib_path);
3261 path=(
unsigned char *) RelinquishMagickMemory(path);
3285MagickPrivate
void NTWindowsTerminus(
void)
3287 NTGhostscriptUnLoadDLL();
3289 ActivateSemaphoreInfo(&winsock_semaphore);
3290 LockSemaphoreInfo(winsock_semaphore);
3291 if (wsaData != (WSADATA *) NULL)
3294 wsaData=(WSADATA *) RelinquishMagickMemory((
void *) wsaData);
3296 UnlockSemaphoreInfo(winsock_semaphore);
3297 DestroySemaphoreInfo(&winsock_semaphore);