|
WizardsToolkit
1.0.7
|
00001 /* 00002 Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization 00003 dedicated to making software imaging solutions freely available. 00004 00005 You may not use this file except in compliance with the License. 00006 obtain a copy of the License at 00007 00008 http://www.wizards-toolkit.org/script/license.php 00009 00010 Unless required by applicable law or agreed to in writing, software 00011 distributed under the License is distributed on an "AS IS" BASIS, 00012 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 See the License for the specific language governing permissions and 00014 limitations under the License. 00015 00016 Windows NT utility methods for the Wizard's Toolkit. 00017 */ 00018 #ifndef _WIZARDSTOOLKIT_NTBASE_H 00019 #define _WIZARDSTOOLKIT_NTBASE_H 00020 00021 #if defined(__cplusplus) || defined(c_plusplus) 00022 extern "C" { 00023 #endif 00024 00025 #define WIN32_LEAN_AND_MEAN 00026 #define VC_EXTRALEAN 00027 #include <windows.h> 00028 #include <winuser.h> 00029 #include <wingdi.h> 00030 #include <io.h> 00031 #include <process.h> 00032 #include <errno.h> 00033 #if defined(_DEBUG) 00034 #include <crtdbg.h> 00035 #endif 00036 00037 #include <stdarg.h> 00038 #include "wizard/exception.h" 00039 00040 #define PROT_READ 0x01 00041 #define PROT_WRITE 0x02 00042 #define MAP_SHARED 0x01 00043 #define MAP_PRIVATE 0x02 00044 #define MAP_ANONYMOUS 0x20 00045 #define F_OK 0 00046 #define R_OK 4 00047 #define W_OK 2 00048 #define RW_OK 6 00049 #define _SC_PAGESIZE 1 00050 #define _SC_PHYS_PAGES 2 00051 #define _SC_OPEN_MAX 3 00052 #if !defined(SSIZE_MAX) 00053 #define SSIZE_MAX 0x7fffffffL 00054 #endif 00055 00056 /* 00057 _MSC_VER values: 00058 1100 MSVC 5.0 00059 1200 MSVC 6.0 00060 1300 MSVC 7.0 Visual C++ .NET 2002 00061 1310 Visual c++ .NET 2003 00062 1400 Visual C++ 2005 00063 1500 Visual C++ 2008 00064 */ 00065 00066 #if !defined(chsize) 00067 # if defined(__BORLANDC__) 00068 # define chsize(file,length) chsize(file,length) 00069 # else 00070 # define chsize(file,length) _chsize(file,length) 00071 # endif 00072 #endif 00073 00074 #if !defined(access) 00075 #if defined(_VISUALC_) && (_MSC_VER >= 1400) 00076 # define access(path,mode) _access_s(path,mode) 00077 #endif 00078 #endif 00079 #if !defined(chdir) 00080 # define chdir _chdir 00081 #endif 00082 #if !defined(close) 00083 # define close _close 00084 #endif 00085 #if !defined(closedir) 00086 # define closedir(directory) NTCloseDirectory(directory) 00087 #endif 00088 #if !defined(fdopen) 00089 # define fdopen _fdopen 00090 #endif 00091 #if !defined(fileno) 00092 # define fileno _fileno 00093 #endif 00094 #if !defined(fseek) && !defined(__MINGW32__) 00095 #if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) && !defined(Windows95) && \ 00096 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800) 00097 # define fseek _fseeki64 00098 #endif 00099 #endif 00100 #if !defined(fstat) && !defined(__BORLANDC__) 00101 #if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) && !defined(Windows95) && \ 00102 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800) 00103 # define fstat _fstati64 00104 #else 00105 # define fstat _fstat 00106 #endif 00107 #endif 00108 #if !defined(fsync) 00109 # define fsync _commit 00110 #endif 00111 #if !defined(ftell) && !defined(__MINGW32__) 00112 #if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) && !defined(Windows95) && \ 00113 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800) 00114 # define ftell _ftelli64 00115 #endif 00116 #endif 00117 #if !defined(ftruncate) 00118 # define ftruncate(file,length) NTTruncateFile(file,length) 00119 #endif 00120 #if !defined(getcwd) 00121 # define getcwd _getcwd 00122 #endif 00123 #if !defined(getpid) 00124 # define getpid _getpid 00125 #endif 00126 #if !defined(hypot) 00127 # define hypot _hypot 00128 #endif 00129 #if !defined(inline) 00130 # define inline __inline 00131 #endif 00132 #if !defined(isatty) 00133 # define isatty _isatty 00134 #endif 00135 #if !defined(locale_t) 00136 #define locale_t _locale_t 00137 #endif 00138 #if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) && !defined(Windows95) && \ 00139 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800) 00140 # define lseek _lseeki64 00141 #else 00142 # define lseek _lseek 00143 #endif 00144 #if !defined(WIZARDSTOOLKIT_LTDL_DELEGATE) 00145 #if !defined(lt_dlclose) 00146 # define lt_dlclose(handle) NTCloseLibrary(handle) 00147 #endif 00148 #if !defined(lt_dlerror) 00149 # define lt_dlerror() NTGetLibraryError() 00150 #endif 00151 #if !defined(lt_dlexit) 00152 # define lt_dlexit() NTExitLibrary() 00153 #endif 00154 #if !defined(lt_dlinit) 00155 # define lt_dlinit() NTInitializeLibrary() 00156 #endif 00157 #if !defined(lt_dlopen) 00158 # define lt_dlopen(filename) NTOpenLibrary(filename) 00159 #endif 00160 #if !defined(lt_dlsetsearchpath) 00161 # define lt_dlsetsearchpath(path) NTSetSearchPath(path) 00162 #endif 00163 #if !defined(lt_dlsym) 00164 # define lt_dlsym(handle,name) NTGetLibrarySymbol(handle,name) 00165 #endif 00166 #endif 00167 #if !defined(mkdir) 00168 # define mkdir _mkdir 00169 #endif 00170 #if !defined(mmap) 00171 # define mmap(address,length,protection,access,file,offset) \ 00172 NTMapMemory(address,length,protection,access,file,offset) 00173 #endif 00174 #if !defined(msync) 00175 # define msync(address,length,flags) NTSyncMemory(address,length,flags) 00176 #endif 00177 #if !defined(munmap) 00178 # define munmap(address,length) NTUnmapMemory(address,length) 00179 #endif 00180 #if !defined(opendir) 00181 # define opendir(directory) NTOpenDirectory(directory) 00182 #endif 00183 #if !defined(open) 00184 # define open _open 00185 #endif 00186 #if !defined(pclose) 00187 # define pclose _pclose 00188 #endif 00189 #if !defined(popen) 00190 # define popen _popen 00191 #endif 00192 #if !defined(fprintf_l) 00193 #define fprintf_l _fprintf_s_l 00194 #endif 00195 #if !defined(read) 00196 # define read _read 00197 #endif 00198 #if !defined(readdir) 00199 # define readdir(directory) NTReadDirectory(directory) 00200 #endif 00201 #if !defined(seekdir) 00202 # define seekdir(directory,offset) NTSeekDirectory(directory,offset) 00203 #endif 00204 #if !defined(setmode) 00205 # define setmode _setmode 00206 #endif 00207 #if !defined(spawnvp) 00208 # define spawnvp _spawnvp 00209 #endif 00210 #if !defined(stat) && !defined(__BORLANDC__) 00211 #if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) && !defined(Windows95) && \ 00212 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800) 00213 # define stat _stati64 00214 #else 00215 # define stat _stat 00216 #endif 00217 #endif 00218 #if !defined(strcasecmp) 00219 # define strcasecmp _strcmpi 00220 #endif 00221 #if !defined(strncasecmp) 00222 # define strncasecmp _strnicmp 00223 #endif 00224 #if !defined(strtod_l) 00225 #define strtod_l _strtod_l 00226 #endif 00227 #if !defined(sysconf) 00228 # define sysconf(name) NTSystemConfiguration(name) 00229 #endif 00230 #if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) && !defined(Windows95) && \ 00231 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800) 00232 # define tell _telli64 00233 #else 00234 # define tell _tell 00235 #endif 00236 #if !defined(telldir) 00237 # define telldir(directory) NTTellDirectory(directory) 00238 #endif 00239 #if !defined(tempnam) 00240 # define tempnam _tempnam_s 00241 #endif 00242 #if !defined(vfprintf_l) 00243 #define vfprintf_l _vfprintf_l 00244 #endif 00245 #if !defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER < 1500) 00246 #define vsnprintf _vsnprintf 00247 #endif 00248 #if !defined(vsnprintf_l) 00249 #define vsnprintf_l _vsnprintf_l 00250 #endif 00251 #if !defined(write) 00252 # define write _write 00253 #endif 00254 #if !defined(wstat) && !defined(__BORLANDC__) 00255 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \ 00256 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800) 00257 # define wstat _wstati64 00258 #else 00259 # define wstat _wstat 00260 #endif 00261 #endif 00262 00263 #if defined(_MT) && defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) 00264 # define SAFE_GLOBAL __declspec(thread) 00265 #else 00266 # define SAFE_GLOBAL 00267 #endif 00268 00269 #if defined(__BORLANDC__) 00270 #undef _O_RANDOM 00271 #define _O_RANDOM 0 00272 #undef _O_SEQUENTIAL 00273 #define _O_SEQUENTIAL 0 00274 #undef _O_SHORT_LIVED 00275 #define _O_SHORT_LIVED 0 00276 #undef _O_TEMPORARY 00277 #define _O_TEMPORARY 0 00278 #endif 00279 00280 #if !defined(XS_VERSION) 00281 struct dirent 00282 { 00283 char 00284 d_name[2048]; 00285 00286 int 00287 d_namlen; 00288 }; 00289 00290 typedef struct _DIR 00291 { 00292 HANDLE 00293 hSearch; 00294 00295 WIN32_FIND_DATA 00296 Win32FindData; 00297 00298 BOOL 00299 firsttime; 00300 00301 struct dirent 00302 file_info; 00303 } DIR; 00304 00305 typedef struct _NTMEMORYSTATUSEX 00306 { 00307 DWORD 00308 dwLength, 00309 dwMemoryLoad; 00310 00311 DWORDLONG 00312 ullTotalPhys, 00313 ullAvailPhys, 00314 ullTotalPageFile, 00315 ullAvailPageFile, 00316 ullTotalVirtual, 00317 ullAvailVirtual, 00318 ullAvailExtendedVirtual; 00319 } NTMEMORYSTATUSEX; 00320 00321 #if !defined(__MINGW32__) 00322 struct timezone 00323 { 00324 int 00325 tz_minuteswest, 00326 tz_dsttime; 00327 }; 00328 00329 typedef _locale_t locale_t; 00330 #endif 00331 00332 typedef UINT 00333 (CALLBACK *LPFNDLLFUNC1)(DWORD,UINT); 00334 00335 typedef UINT 00336 (CALLBACK *LPFNDLLFUNC2)(NTMEMORYSTATUSEX *); 00337 00338 #endif 00339 00340 #if defined(WIZARDSTOOLKIT_BZLIB_DELEGATE) 00341 # if defined(_WIN32) 00342 # define BZ_IMPORT 1 00343 # endif 00344 #endif 00345 00346 extern WizardExport char 00347 *NTGetLastError(void); 00348 00349 #if !defined(WIZARDSTOOLKIT_LTDL_DELEGATE) 00350 extern WizardExport const char 00351 *NTGetLibraryError(void); 00352 #endif 00353 00354 #if !defined(XS_VERSION) 00355 extern WizardExport char 00356 *NTRegistryKeyLookup(const char *); 00357 00358 extern WizardExport DIR 00359 *NTOpenDirectory(const char *); 00360 00361 extern WizardExport double 00362 NTElapsedTime(void), 00363 NTUserTime(void); 00364 00365 extern WizardExport int 00366 Exit(int), 00367 #if !defined(__MINGW32__) 00368 gettimeofday(struct timeval *,struct timezone *), 00369 #endif 00370 IsWindows95(), 00371 NTCloseDirectory(DIR *), 00372 NTCloseLibrary(void *), 00373 NTControlHandler(void), 00374 NTExitLibrary(void), 00375 NTInitializeLibrary(void), 00376 NTSetSearchPath(const char *), 00377 NTSyncMemory(void *,size_t,int), 00378 NTUnmapMemory(void *,size_t), 00379 NTSystemCommand(const char *); 00380 00381 extern WizardExport ssize_t 00382 NTSystemConfiguration(int), 00383 NTTellDirectory(DIR *); 00384 00385 extern WizardExport WizardBooleanType 00386 NTGetExecutionPath(char *,const size_t), 00387 NTGetModulePath(const char *,char *), 00388 NTGatherRandomData(const size_t,unsigned char *), 00389 NTReportEvent(const char *,const WizardBooleanType), 00390 NTReportException(const char *,const WizardBooleanType); 00391 00392 extern WizardExport struct dirent 00393 *NTReadDirectory(DIR *); 00394 00395 extern WizardExport unsigned char 00396 *NTResourceToBlob(const char *); 00397 00398 extern WizardExport void 00399 NTErrorHandler(const ExceptionType,const char *,const char *), 00400 *NTGetLibrarySymbol(void *,const char *), 00401 *NTMapMemory(char *,size_t,int,int,int,WizardOffsetType), 00402 *NTOpenLibrary(const char *), 00403 NTSeekDirectory(DIR *,ssize_t), 00404 NTWarningHandler(const ExceptionType,const char *,const char *); 00405 00406 #endif /* !XS_VERSION */ 00407 00408 #if defined(__cplusplus) || defined(c_plusplus) 00409 } 00410 #endif /* !C++ */ 00411 00412 #endif /* !_WIZARDSTOOLKIT_NTBASE_H */