42#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
54#if defined(WIZARDSTOOLKIT_LTDL_DELEGATE)
64#if !defined(MAP_FAILED)
65#define MAP_FAILED ((void *) -1)
71#if !defined(WIZARDSTOOLKIT_LTDL_DELEGATE)
73 *lt_slsearchpath = (
char *) NULL;
79#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
81 DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved);
127#if defined(_DLL) && defined( ProvideDllMain )
128BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
132 case DLL_PROCESS_ATTACH:
143 sizeof(*module_path));
147 if ((module_path == (
char *) NULL) || (new_path == (
char *) NULL) ||
148 (path == (
char *) NULL))
153 for ( ; count > 0; count--)
154 if (module_path[count] ==
'\\')
156 module_path[count+1]=
'\0';
161 if ((count != 0) && (strstr(path,module_path) == (
char *) NULL))
166 "%s;%s",module_path,path);
167 SetEnvironmentVariable(
"PATH",new_path);
176 case DLL_PROCESS_DETACH:
215 TerminateProcess(GetCurrentProcess(),(
unsigned int) status);
220#if !defined(__MINGW32__) && !defined(__MINGW64__)
245WizardExport int gettimeofday (
struct timeval *time_value,
246 struct timezone *time_zone)
248#define EpochFiletime WizardLLConstant(116444736000000000)
253 if (time_value != (
struct timeval *) NULL)
264 GetSystemTimeAsFileTime(&file_time);
265 date_time.LowPart=file_time.dwLowDateTime;
266 date_time.HighPart=file_time.dwHighDateTime;
267 time=date_time.QuadPart;
270 time_value->tv_sec=(ssize_t) (time / 1000000);
271 time_value->tv_usec=(ssize_t) (time % 1000000);
273 if (time_zone != (
struct timezone *) NULL)
280 time_zone->tz_minuteswest=_timezone/60;
281 time_zone->tz_dsttime=_daylight;
311 version_info.dwOSVersionInfoSize=
sizeof(version_info);
312 if (GetVersionEx(&version_info) &&
313 (version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS))
343WizardExport char **NTArgvToUTF8(
const int argc,
wchar_t **argv)
352 if (utf8 == (
char **) NULL)
354 for (i=0; i < (ssize_t) argc; i++)
359 count=WideCharToMultiByte(CP_UTF8,0,argv[i],-1,NULL,0,NULL,NULL);
363 if (utf8[i] == (
char *) NULL)
365 for (i--; i >= 0; i--)
370 count=WideCharToMultiByte(CP_UTF8,0,argv[i],-1,utf8[i],count,NULL,NULL);
402 assert(entry != (DIR *) NULL);
403 FindClose(entry->hSearch);
433 return(FreeLibrary(handle));
434 return(!(FreeLibrary(handle)));
457static BOOL ControlHandler(DWORD type)
465 return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
501 GetSystemTime(&system_time);
502 SystemTimeToFileTime(&system_time,&elapsed_time.filetime);
503 return((
double) 1.0e-7*elapsed_time.filetime64);
535 const char *description)
541 if (reason == (
char *) NULL)
547 if ((description != (
char *) NULL) && errno)
551 if (description != (
char *) NULL)
562 (void) MessageBox(NULL,buffer,
"Wizard's Toolkit Exception",MB_OK |
563 MB_TASKMODAL | MB_SETFOREGROUND | MB_ICONEXCLAMATION);
625 file_handle=_get_osfhandle(file);
626 if (file_handle == -1L)
628 low=(long) (length & 0xffffffffUL);
630 file_pointer=SetFilePointer((HANDLE) file_handle,low,&high,FILE_BEGIN);
631 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
633 if (SetEndOfFile((HANDLE) file_handle) == 0)
665 GetModuleFileName(0,path,(DWORD) extent);
687char *NTGetLastError(
void)
696 buffer = (LPVOID) NULL;
698 status=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
699 FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),
700 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR) &buffer,0,NULL);
740 error=NTGetLastError();
772void *NTGetLibrarySymbol(
void *handle,
const char *name)
777 lpfnDllFunc1=(LPFNDLLFUNC1) GetProcAddress(handle,name);
779 return((
void *) NULL);
780 return((
void *) lpfnDllFunc1);
819 handle=GetModuleHandle(module);
820 if (handle == (HMODULE) NULL)
854 unsigned char *random)
862 handle=(HCRYPTPROV) NULL;
863 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
864 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET));
866 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
867 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET));
870 status=CryptGenRandom(handle,(DWORD) length,random);
873 status=CryptReleaseContext(handle,0);
876 status=CryptReleaseContext(handle,0);
924WizardExport void *NTMapMemory(
char *address,
size_t length,
int protection,
943 file_handle=INVALID_HANDLE_VALUE;
944 low_length=(DWORD) (length & 0xFFFFFFFFUL);
946 map_handle=INVALID_HANDLE_VALUE;
948 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
949 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
951 if (protection & PROT_WRITE)
953 access_mode=FILE_MAP_WRITE;
954 if (!(flags & MAP_PRIVATE))
955 protection_mode=PAGE_READWRITE;
958 access_mode=FILE_MAP_COPY;
959 protection_mode=PAGE_WRITECOPY;
963 if (protection & PROT_READ)
965 access_mode=FILE_MAP_READ;
966 protection_mode=PAGE_READONLY;
968 if ((file == -1) && (flags & MAP_ANONYMOUS))
969 file_handle=INVALID_HANDLE_VALUE;
971 file_handle=(HANDLE) _get_osfhandle(file);
972 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
976 map=(
void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
978 CloseHandle(map_handle);
980 if (map == (
void *) NULL)
982 return((
void *) ((
char *) map));
1019 assert(path != (
const char *) NULL);
1022 return((DIR *) NULL);
1026 return((DIR *) NULL);
1028 if (entry != (DIR *) NULL)
1030 entry->firsttime=TRUE;
1031 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1033 if (entry->hSearch == INVALID_HANDLE_VALUE)
1039 return((DIR *) NULL);
1041 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1042 if (entry->hSearch == INVALID_HANDLE_VALUE)
1045 return((DIR *) NULL);
1076static const char *GetSearchPath(
void )
1078#if defined(WIZARDSTOOLKIT_LTDL_DELEGATE)
1079 return(lt_dlgetsearchpath());
1081 return(lt_slsearchpath);
1087#define MaxPathElements 31
1108 mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
1109 handle=(
void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1110 if ((handle != (
void *) NULL) || (GetSearchPath() == (
char *) NULL))
1115 p=(
char *) GetSearchPath();
1117 while (index < MaxPathElements)
1120 if (q == (
char *) NULL)
1125 handle=(
void *) LoadLibraryEx(buffer,NULL,
1126 LOAD_WITH_ALTERED_SEARCH_PATH);
1133 handle=(
void *) LoadLibraryEx(buffer,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1134 if (handle != (
void *) NULL)
1174 if (entry == (DIR *) NULL)
1175 return((
struct dirent *) NULL);
1176 if (!entry->firsttime)
1178 status=FindNextFile(entry->hSearch,&entry->Win32FindData);
1180 return((
struct dirent *) NULL);
1183 entry->Win32FindData.cFileName,
sizeof(entry->file_info.d_name));
1184 if (length >=
sizeof(entry->file_info.d_name))
1185 return((
struct dirent *) NULL);
1186 entry->firsttime=FALSE;
1187 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
1188 return(&entry->file_info);
1222WizardExport unsigned char *NTRegistryKeyLookup(
const char *subkey)
1246 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1247 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
1248 if (status != ERROR_SUCCESS)
1250 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1251 return((
unsigned char *) NULL);
1258 if (value == (
unsigned char *) NULL)
1260 RegCloseKey(registry_key);
1261 return((
unsigned char *) NULL);
1264 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1265 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
1268 if (value == (BYTE *) NULL)
1270 RegCloseKey(registry_key);
1271 return((
unsigned char *) NULL);
1273 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1275 RegCloseKey(registry_key);
1276 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
1278 return((
unsigned char *) value);
1318 handle=RegisterEventSource(NULL,
"Wizard's Toolkit");
1322 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
1323 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
1324 DeregisterEventSource(handle);
1353WizardExport unsigned char *NTResourceToBlob(
const char *
id)
1374 assert(
id != (
const char *) NULL);
1379 handle=GetModuleHandle(path);
1381 handle=GetModuleHandle(0);
1383 return((
char *) NULL);
1384 resource=FindResource(handle,
id,
"WizardsToolkit");
1386 return((
char *) NULL);
1387 global=LoadResource(handle,resource);
1389 return((
char *) NULL);
1390 length=SizeofResource(handle,resource);
1391 value=(
unsigned char *) LockResource(global);
1394 FreeResource(global);
1395 return((
char *) NULL);
1399 if (blob != (
unsigned char *) NULL)
1404 UnlockResource(global);
1405 FreeResource(global);
1435WizardExport void NTSeekDirectory(DIR *entry,ssize_t position)
1438 assert(entry != (DIR *) NULL);
1467#if defined(WIZARDSTOOLKIT_LTDL_DELEGATE)
1468 lt_dlsetsearchpath(path);
1470 if (lt_slsearchpath != (
char *) NULL)
1472 if (path != (
char *) NULL)
1504WizardExport int NTSyncMemory(
void *address,
size_t length,
int flags)
1506 if (FlushViewOfFile(address,length) ==
WizardFalse)
1554 if (command == (
char *) NULL)
1556 GetStartupInfo(&startup_info);
1557 startup_info.dwFlags=STARTF_USESHOWWINDOW;
1558 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
1560 background_process=command[strlen(command)-1] ==
'&';
1561 if (background_process)
1562 local_command[strlen(command)-1]=
'\0';
1563 if (command[strlen(command)-1] ==
'|')
1564 local_command[strlen(command)-1]=
'\0';
1566 startup_info.wShowWindow=SW_SHOWDEFAULT;
1567 status=CreateProcess((LPCTSTR) NULL,local_command,
1568 (LPSECURITY_ATTRIBUTES) NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,
1569 (DWORD) NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
1573 if (background_process)
1574 return(status == 0);
1575 status=WaitForSingleObject(process_info.hProcess,INFINITE);
1576 if (status != WAIT_OBJECT_0)
1578 status=GetExitCodeProcess(process_info.hProcess,&child_status);
1581 CloseHandle(process_info.hProcess);
1582 CloseHandle(process_info.hThread);
1583 return((
int) child_status);
1618 GetSystemInfo(&system_info);
1619 return(system_info.dwPageSize);
1621 case _SC_PHYS_PAGES:
1635 handle=GetModuleHandle(
"kernel32.dll");
1636 if (handle == (HMODULE) NULL)
1638 GetSystemInfo(&system_info);
1639 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,
"GlobalMemoryStatusEx");
1640 if (module == (LPFNDLLFUNC2) NULL)
1645 GlobalMemoryStatus(&status);
1646 return((ssize_t) status.dwAvailPhys/system_info.dwPageSize/4);
1648 status.dwLength=
sizeof(status);
1649 if (module(&status) == 0)
1651 return((ssize_t) status.ullAvailPhys/system_info.dwPageSize/4);
1686 assert(entry != (DIR *) NULL);
1716 if (!UnmapViewOfFile(map))
1770 OsVersionInfo.dwOSVersionInfoSize=
sizeof(OSVERSIONINFO);
1771 GetVersionEx(&OsVersionInfo);
1772 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
1773 return(NTElapsedTime());
1774 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
1775 &kernel_time.filetime,&user_time.filetime);
1778 return((
double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
1810 const char *reason,
const char *description)
1815 if (reason == (
char *) NULL)
1817 if (description == (
char *) NULL)
1823 (void) MessageBox(NULL,buffer,
"Wizard's Toolkit Warning",MB_OK |
1824 MB_TASKMODAL | MB_SETFOREGROUND | MB_ICONINFORMATION);
WizardExport const char * GetClientPath(void)
WizardExport const char * GetClientName(void)
#define ThrowFatalException(severity, tag)
WizardExport char * GetExceptionMessage(const int error)
WizardExport ssize_t FormatLocaleString(char *string, const size_t length, const char *format,...)
WizardBooleanType LogWizardEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
#define GetWizardModule()
WizardExport void * AcquireWizardMemory(const size_t size)
WizardExport void * CopyWizardMemory(void *destination, const void *source, const size_t size)
WizardExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
WizardExport void * RelinquishWizardMemory(void *memory)
WizardExport void * ResizeQuantumMemory(void *memory, const size_t count, const size_t quantum)
WizardExport void AsynchronousResourceComponentTerminus(void)
WizardExport char * DestroyString(char *string)
WizardExport size_t ConcatenateWizardString(char *destination, const char *source, const size_t length)
WizardExport char * AcquireString(const char *source)
WizardExport size_t CopyWizardString(char *destination, const char *source, const size_t length)
#define DirectorySeparator
#define DirectoryListSeparator
WizardExport void GetPathComponent(const char *path, PathType type, char *component)
WizardExport WizardBooleanType IsPathAcessible(const char *path)
#define WizardLibVersionText
#define WizardPackageName
WizardExport void WizardsToolkitGenesis(const char *path)
WizardExport void WizardsToolkitTerminus(void)