cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization |
| 3 | dedicated to making software imaging solutions freely available. |
| 4 | |
| 5 | You may not use this file except in compliance with the License. |
| 6 | obtain a copy of the License at |
| 7 | |
| 8 | http://www.imagemagick.org/script/license.php |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | |
| 16 | MagickCore Windows NT utility methods. |
| 17 | */ |
| 18 | #ifndef _MAGICKCORE_NT_BASE_H |
| 19 | #define _MAGICKCORE_NT_BASE_H |
| 20 | |
| 21 | #if defined(__cplusplus) || defined(c_plusplus) |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | #include "magick/delegate.h" |
| 26 | #include "magick/delegate-private.h" |
| 27 | #include "magick/exception.h" |
| 28 | |
| 29 | #define WIN32_LEAN_AND_MEAN |
| 30 | #define VC_EXTRALEAN |
| 31 | #define _CRT_SECURE_NO_DEPRECATE 1 |
| 32 | #include <windows.h> |
| 33 | #include <wchar.h> |
| 34 | #include <winuser.h> |
| 35 | #include <wingdi.h> |
| 36 | #include <io.h> |
| 37 | #include <process.h> |
| 38 | #include <errno.h> |
| 39 | #if defined(_DEBUG) && !defined(__MINGW32__) |
| 40 | #include <crtdbg.h> |
| 41 | #endif |
| 42 | |
| 43 | #define PROT_READ 0x01 |
| 44 | #define PROT_WRITE 0x02 |
| 45 | #define MAP_SHARED 0x01 |
| 46 | #define MAP_PRIVATE 0x02 |
| 47 | #define MAP_ANONYMOUS 0x20 |
| 48 | #define F_OK 0 |
| 49 | #define R_OK 4 |
| 50 | #define W_OK 2 |
| 51 | #define RW_OK 6 |
| 52 | #define _SC_PAGESIZE 1 |
| 53 | #define _SC_PHYS_PAGES 2 |
| 54 | #define _SC_OPEN_MAX 3 |
| 55 | #if !defined(SSIZE_MAX) |
| 56 | #define SSIZE_MAX 0x7fffffffL |
| 57 | #endif |
| 58 | |
| 59 | /* |
| 60 | _MSC_VER values: |
| 61 | 1100 MSVC 5.0 |
| 62 | 1200 MSVC 6.0 |
| 63 | 1300 MSVC 7.0 Visual C++ .NET 2002 |
| 64 | 1310 Visual c++ .NET 2003 |
| 65 | 1400 Visual C++ 2005 |
| 66 | 1500 Visual C++ 2008 |
| 67 | */ |
| 68 | |
| 69 | #if !defined(chsize) |
| 70 | # if defined(__BORLANDC__) |
| 71 | # define chsize(file,length) chsize(file,length) |
| 72 | # else |
| 73 | # define chsize(file,length) _chsize(file,length) |
| 74 | # endif |
| 75 | #endif |
| 76 | |
| 77 | #if !defined(access) |
| 78 | # define access(path,mode) _access(path,mode) |
| 79 | #endif |
| 80 | #if !defined(chdir) |
| 81 | # define chdir _chdir |
| 82 | #endif |
| 83 | #if !defined(close) |
| 84 | # define close _close |
| 85 | #endif |
| 86 | #if !defined(closedir) |
| 87 | # define closedir(directory) NTCloseDirectory(directory) |
| 88 | #endif |
| 89 | #if !defined(fdopen) |
| 90 | # define fdopen _fdopen |
| 91 | #endif |
| 92 | #if !defined(fileno) |
| 93 | # define fileno _fileno |
| 94 | #endif |
| 95 | #if !defined(fseek) |
| 96 | # define fseeko _fseeki64 |
| 97 | #endif |
| 98 | #if !defined(fstat) && !defined(__BORLANDC__) |
| 99 | #if defined(__WINDOWS__) && !defined(Windows95) && \ |
| 100 | !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800) |
| 101 | # define fstat _fstati64 |
| 102 | #else |
| 103 | # define fstat _fstat |
| 104 | #endif |
| 105 | #endif |
| 106 | #if !defined(fsync) |
| 107 | # define fsync _commit |
| 108 | #endif |
| 109 | #if !defined(ftell) |
| 110 | # define ftello _ftelli64 |
| 111 | #endif |
| 112 | #if !defined(ftruncate) |
| 113 | # define ftruncate(file,length) NTTruncateFile(file,length) |
| 114 | #endif |
| 115 | #if !defined(getcwd) |
| 116 | # define getcwd _getcwd |
| 117 | #endif |
| 118 | #if !defined(getpid) |
| 119 | # define getpid _getpid |
| 120 | #endif |
| 121 | #if !defined(hypot) |
| 122 | # define hypot _hypot |
| 123 | #endif |
| 124 | #if !defined(inline) |
| 125 | # define inline __inline |
| 126 | #endif |
| 127 | #if !defined(isatty) |
| 128 | # define isatty _isatty |
| 129 | #endif |
| 130 | #if !defined(MAGICKCORE_LTDL_DELEGATE) |
| 131 | #if !defined(lt_dlclose) |
| 132 | # define lt_dlclose(handle) NTCloseLibrary(handle) |
| 133 | #endif |
| 134 | #if !defined(lt_dlerror) |
| 135 | # define lt_dlerror() NTGetLibraryError() |
| 136 | #endif |
| 137 | #if !defined(lt_dlexit) |
| 138 | # define lt_dlexit() NTExitLibrary() |
| 139 | #endif |
| 140 | #if !defined(lt_dlinit) |
| 141 | # define lt_dlinit() NTInitializeLibrary() |
| 142 | #endif |
| 143 | #if !defined(lt_dlopen) |
| 144 | # define lt_dlopen(filename) NTOpenLibrary(filename) |
| 145 | #endif |
| 146 | #if !defined(lt_dlsetsearchpath) |
| 147 | # define lt_dlsetsearchpath(path) NTSetSearchPath(path) |
| 148 | #endif |
| 149 | #if !defined(lt_dlsym) |
| 150 | # define lt_dlsym(handle,name) NTGetLibrarySymbol(handle,name) |
| 151 | #endif |
| 152 | #endif |
| 153 | #if !defined(mkdir) |
| 154 | # define mkdir _mkdir |
| 155 | #endif |
| 156 | #if !defined(mmap) |
| 157 | # define mmap(address,length,protection,access,file,offset) \ |
| 158 | NTMapMemory(address,length,protection,access,file,offset) |
| 159 | #endif |
| 160 | #if !defined(msync) |
| 161 | # define msync(address,length,flags) NTSyncMemory(address,length,flags) |
| 162 | #endif |
| 163 | #if !defined(munmap) |
| 164 | # define munmap(address,length) NTUnmapMemory(address,length) |
| 165 | #endif |
| 166 | #if !defined(opendir) |
| 167 | # define opendir(directory) NTOpenDirectory(directory) |
| 168 | #endif |
| 169 | #if !defined(open) |
| 170 | # define open _open |
| 171 | #endif |
| 172 | #if !defined(pclose) |
| 173 | # define pclose _pclose |
| 174 | #endif |
| 175 | #if !defined(popen) |
| 176 | # define popen _popen |
| 177 | #endif |
| 178 | #if !defined(read) |
| 179 | # define read _read |
| 180 | #endif |
| 181 | #if !defined(readdir) |
| 182 | # define readdir(directory) NTReadDirectory(directory) |
| 183 | #endif |
| 184 | #if !defined(seekdir) |
| 185 | # define seekdir(directory,offset) NTSeekDirectory(directory,offset) |
| 186 | #endif |
| 187 | #if !defined(setmode) |
| 188 | # define setmode _setmode |
| 189 | #endif |
| 190 | #if !defined(stat) && !defined(__BORLANDC__) |
| 191 | #if defined(__WINDOWS__) && !defined(Windows95) && \ |
| 192 | !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800) |
| 193 | # define stat _stati64 |
| 194 | #else |
| 195 | # define stat _stat |
| 196 | #endif |
| 197 | #endif |
| 198 | #if !defined(strcasecmp) |
| 199 | # define strcasecmp _strcmpi |
| 200 | #endif |
| 201 | #if !defined(strncasecmp) |
| 202 | # define strncasecmp _strnicmp |
| 203 | #endif |
| 204 | #if !defined(sysconf) |
| 205 | # define sysconf(name) NTSystemConfiguration(name) |
| 206 | #endif |
| 207 | #if !defined(telldir) |
| 208 | # define telldir(directory) NTTellDirectory(directory) |
| 209 | #endif |
| 210 | #if !defined(tempnam) |
| 211 | # define tempnam _tempnam |
| 212 | #endif |
| 213 | #if !defined(vsnprintf) |
| 214 | #if !defined(_MSC_VER) || (defined(_MSC_VER) && (_MSC_VER < 1500)) |
| 215 | #define vsnprintf _vsnprintf |
| 216 | #endif |
| 217 | #endif |
| 218 | #if !defined(write) |
| 219 | # define write _write |
| 220 | #endif |
| 221 | #if !defined(wstat) && !defined(__BORLANDC__) |
| 222 | #if defined(__WINDOWS__) && !defined(Windows95) && \ |
| 223 | !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800) |
| 224 | # define wstat _wstati64 |
| 225 | #else |
| 226 | # define wstat _wstat |
| 227 | #endif |
| 228 | #endif |
| 229 | |
| 230 | #if defined(_MT) && defined(__WINDOWS__) |
| 231 | # define SAFE_GLOBAL __declspec(thread) |
| 232 | #else |
| 233 | # define SAFE_GLOBAL |
| 234 | #endif |
| 235 | |
| 236 | #if defined(__BORLANDC__) |
| 237 | #undef _O_RANDOM |
| 238 | #define _O_RANDOM 0 |
| 239 | #undef _O_SEQUENTIAL |
| 240 | #define _O_SEQUENTIAL 0 |
| 241 | #undef _O_SHORT_LIVED |
| 242 | #define _O_SHORT_LIVED 0 |
| 243 | #undef _O_TEMPORARY |
| 244 | #define _O_TEMPORARY 0 |
| 245 | #endif |
| 246 | |
| 247 | #if !defined(XS_VERSION) |
| 248 | struct dirent |
| 249 | { |
| 250 | char |
| 251 | d_name[2048]; |
| 252 | |
| 253 | int |
| 254 | d_namlen; |
| 255 | }; |
| 256 | |
| 257 | typedef struct _DIR |
| 258 | { |
| 259 | HANDLE |
| 260 | hSearch; |
| 261 | |
| 262 | WIN32_FIND_DATA |
| 263 | Win32FindData; |
| 264 | |
| 265 | BOOL |
| 266 | firsttime; |
| 267 | |
| 268 | struct dirent |
| 269 | file_info; |
| 270 | } DIR; |
| 271 | |
| 272 | typedef struct _NTMEMORYSTATUSEX |
| 273 | { |
| 274 | DWORD |
| 275 | dwLength, |
| 276 | dwMemoryLoad; |
| 277 | |
| 278 | DWORDLONG |
| 279 | ullTotalPhys, |
| 280 | ullAvailPhys, |
| 281 | ullTotalPageFile, |
| 282 | ullAvailPageFile, |
| 283 | ullTotalVirtual, |
| 284 | ullAvailVirtual, |
| 285 | ullAvailExtendedVirtual; |
| 286 | } NTMEMORYSTATUSEX; |
| 287 | |
| 288 | typedef UINT |
| 289 | (CALLBACK *LPFNDLLFUNC1)(DWORD,UINT); |
| 290 | |
| 291 | typedef UINT |
| 292 | (CALLBACK *LPFNDLLFUNC2)(NTMEMORYSTATUSEX *); |
| 293 | |
| 294 | #endif |
| 295 | |
| 296 | #if !defined(ssize_t) && !defined(__MINGW32__) |
| 297 | typedef long ssize_t; |
| 298 | #endif |
| 299 | |
| 300 | #if defined(MAGICKCORE_BZLIB_DELEGATE) |
| 301 | # if defined(_WIN32) |
| 302 | # define BZ_IMPORT 1 |
| 303 | # endif |
| 304 | #endif |
| 305 | |
| 306 | extern MagickExport char |
| 307 | *NTGetLastError(void); |
| 308 | |
cristy | defb3f0 | 2009-09-10 02:18:35 +0000 | [diff] [blame] | 309 | extern MagickExport const GhostInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 310 | *NTGhostscriptDLLVectors(void); |
| 311 | |
| 312 | #if !defined(MAGICKCORE_LTDL_DELEGATE) |
| 313 | extern MagickExport const char |
| 314 | *NTGetLibraryError(void); |
| 315 | #endif |
| 316 | |
| 317 | #if !defined(XS_VERSION) |
| 318 | extern MagickExport const char |
| 319 | *NTGetLibraryError(void); |
| 320 | |
| 321 | extern MagickExport DIR |
| 322 | *NTOpenDirectory(const char *); |
| 323 | |
| 324 | extern MagickExport double |
| 325 | NTElapsedTime(void), |
| 326 | NTUserTime(void); |
| 327 | |
| 328 | extern MagickExport int |
| 329 | Exit(int), |
| 330 | IsWindows95(), |
| 331 | NTCloseDirectory(DIR *), |
| 332 | NTCloseLibrary(void *), |
| 333 | NTControlHandler(void), |
| 334 | NTExitLibrary(void), |
| 335 | NTTruncateFile(int,off_t), |
| 336 | NTGhostscriptDLL(char *,int), |
| 337 | NTGhostscriptEXE(char *,int), |
| 338 | NTGhostscriptFonts(char *,int), |
| 339 | NTGhostscriptLoadDLL(void), |
| 340 | NTGhostscriptUnLoadDLL(void), |
| 341 | NTInitializeLibrary(void), |
| 342 | NTSetSearchPath(const char *), |
| 343 | NTSyncMemory(void *,size_t,int), |
| 344 | NTUnmapMemory(void *,size_t), |
| 345 | NTSystemCommand(const char *); |
| 346 | |
| 347 | extern MagickExport long |
| 348 | NTSystemConfiguration(int), |
| 349 | NTTellDirectory(DIR *); |
| 350 | |
| 351 | extern MagickExport MagickBooleanType |
| 352 | NTGatherRandomData(const size_t,unsigned char *), |
| 353 | NTGetExecutionPath(char *,const size_t), |
| 354 | NTGetModulePath(const char *,char *), |
| 355 | NTReportEvent(const char *,const MagickBooleanType), |
| 356 | NTReportException(const char *,const MagickBooleanType); |
| 357 | |
| 358 | extern MagickExport struct dirent |
| 359 | *NTReadDirectory(DIR *); |
| 360 | |
| 361 | extern MagickExport unsigned char |
| 362 | *NTRegistryKeyLookup(const char *), |
| 363 | *NTResourceToBlob(const char *); |
| 364 | |
| 365 | extern MagickExport void |
| 366 | NTErrorHandler(const ExceptionType,const char *,const char *), |
| 367 | *NTGetLibrarySymbol(void *,const char *), |
| 368 | *NTMapMemory(char *,size_t,int,int,int,MagickOffsetType), |
| 369 | *NTOpenLibrary(const char *), |
| 370 | NTSeekDirectory(DIR *,long), |
| 371 | NTWarningHandler(const ExceptionType,const char *,const char *); |
| 372 | |
| 373 | #endif /* !XS_VERSION */ |
| 374 | |
| 375 | #if defined(__cplusplus) || defined(c_plusplus) |
| 376 | } |
| 377 | #endif /* !C++ */ |
| 378 | |
| 379 | #endif /* !_MAGICKCORE_NT_BASE_H */ |