cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
Cristy | f6ff9ea | 2016-12-05 09:53:35 -0500 | [diff] [blame] | 2 | Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3 | dedicated to making software imaging solutions freely available. |
cristy | 2c5fc27 | 2012-02-22 01:27:46 +0000 | [diff] [blame] | 4 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5 | You may not use this file except in compliance with the License. |
| 6 | obtain a copy of the License at |
cristy | 2c5fc27 | 2012-02-22 01:27:46 +0000 | [diff] [blame] | 7 | |
Cristy | f19d414 | 2017-04-24 11:34:30 -0400 | [diff] [blame^] | 8 | https://www.imagemagick.org/script/license.php |
cristy | 2c5fc27 | 2012-02-22 01:27:46 +0000 | [diff] [blame] | 9 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | */ |
Cristy | 83bceaa | 2016-06-03 20:39:35 -0400 | [diff] [blame] | 18 | #ifndef MAGICKCORE_NT_BASE_H |
| 19 | #define MAGICKCORE_NT_BASE_H |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 20 | |
cristy | 6398ec7 | 2013-11-28 02:00:27 +0000 | [diff] [blame] | 21 | #include "MagickCore/exception.h" |
| 22 | #include "MagickCore/geometry.h" |
| 23 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 24 | #if defined(__cplusplus) || defined(c_plusplus) |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
cristy | 30603ff | 2011-10-07 00:43:07 +0000 | [diff] [blame] | 28 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 29 | |
cristy | d04eadc | 2014-02-21 18:36:36 +0000 | [diff] [blame] | 30 | #define WIN32_LEAN_AND_MEAN |
| 31 | #define VC_EXTRALEAN |
| 32 | #define _CRT_SECURE_NO_DEPRECATE 1 |
| 33 | #include <windows.h> |
| 34 | #include <wchar.h> |
| 35 | #include <winuser.h> |
| 36 | #include <wingdi.h> |
| 37 | #include <io.h> |
| 38 | #include <process.h> |
| 39 | #include <errno.h> |
cristy | 9e2b624 | 2014-03-25 11:49:41 +0000 | [diff] [blame] | 40 | #include <malloc.h> |
Cristy | 9d627d9 | 2016-04-24 15:13:15 -0400 | [diff] [blame] | 41 | #include <sys/utime.h> |
cristy | d04eadc | 2014-02-21 18:36:36 +0000 | [diff] [blame] | 42 | #if defined(_DEBUG) && !defined(__MINGW32__) && !defined(__MINGW64__) |
| 43 | #include <crtdbg.h> |
| 44 | #endif |
| 45 | |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 46 | #define PROT_READ 0x01 |
| 47 | #define PROT_WRITE 0x02 |
| 48 | #define MAP_SHARED 0x01 |
| 49 | #define MAP_PRIVATE 0x02 |
| 50 | #define MAP_ANONYMOUS 0x20 |
| 51 | #define F_OK 0 |
| 52 | #define R_OK 4 |
| 53 | #define W_OK 2 |
| 54 | #define RW_OK 6 |
| 55 | #define _SC_PAGESIZE 1 |
| 56 | #define _SC_PHYS_PAGES 2 |
| 57 | #define _SC_OPEN_MAX 3 |
| 58 | #if !defined(SSIZE_MAX) |
| 59 | #define SSIZE_MAX 0x7fffffffL |
| 60 | #endif |
| 61 | |
| 62 | /* |
| 63 | _MSC_VER values: |
| 64 | 1100 MSVC 5.0 |
| 65 | 1200 MSVC 6.0 |
| 66 | 1300 MSVC 7.0 Visual C++ .NET 2002 |
| 67 | 1310 Visual c++ .NET 2003 |
| 68 | 1400 Visual C++ 2005 |
| 69 | 1500 Visual C++ 2008 |
Cristy | 36421ee | 2015-08-28 11:58:20 -0400 | [diff] [blame] | 70 | 1600 Visual C++ 2010 |
| 71 | 1700 Visual C++ 2012 |
| 72 | 1800 Visual C++ 2013 |
| 73 | 1900 Visual C++ 2015 |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 74 | */ |
| 75 | |
| 76 | #if !defined(chsize) |
| 77 | # if defined(__BORLANDC__) |
| 78 | # define chsize(file,length) chsize(file,length) |
| 79 | # else |
| 80 | # define chsize(file,length) _chsize(file,length) |
| 81 | # endif |
| 82 | #endif |
| 83 | |
| 84 | #if !defined(access) |
| 85 | #if defined(_VISUALC_) && (_MSC_VER >= 1400) |
| 86 | # define access(path,mode) _access_s(path,mode) |
| 87 | #endif |
| 88 | #endif |
| 89 | #if !defined(chdir) |
| 90 | # define chdir _chdir |
| 91 | #endif |
| 92 | #if !defined(close) |
| 93 | # define close _close |
| 94 | #endif |
| 95 | #if !defined(closedir) |
| 96 | # define closedir(directory) NTCloseDirectory(directory) |
| 97 | #endif |
dirk | a35ec56 | 2016-06-05 21:21:34 +0200 | [diff] [blame] | 98 | #define MAGICKCORE_HAVE_ERF |
dirk | e591f8d | 2016-06-05 17:08:56 +0200 | [diff] [blame] | 99 | #if defined(_VISUALC_) && (_MSC_VER < 1700) |
| 100 | # define erf(x) NTErf(x) |
| 101 | #endif |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 102 | #if !defined(fdopen) |
| 103 | # define fdopen _fdopen |
| 104 | #endif |
| 105 | #if !defined(fileno) |
| 106 | # define fileno _fileno |
| 107 | #endif |
| 108 | #if !defined(fseek) && !defined(__MINGW32__) && !defined(__MINGW64__) |
| 109 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \ |
Cristy | 087a059 | 2015-08-30 16:40:35 -0400 | [diff] [blame] | 110 | !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \ |
| 111 | !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800)) |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 112 | # define fseek _fseeki64 |
| 113 | #endif |
| 114 | #endif |
| 115 | #if !defined(fstat) && !defined(__BORLANDC__) |
| 116 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \ |
Cristy | 087a059 | 2015-08-30 16:40:35 -0400 | [diff] [blame] | 117 | !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \ |
| 118 | !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800)) |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 119 | # define fstat _fstati64 |
| 120 | #else |
| 121 | # define fstat _fstat |
| 122 | #endif |
| 123 | #endif |
| 124 | #if !defined(fsync) |
| 125 | # define fsync _commit |
| 126 | #endif |
| 127 | #if !defined(ftell) && !defined(__MINGW32__) && !defined(__MINGW64__) |
| 128 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \ |
Cristy | 087a059 | 2015-08-30 16:40:35 -0400 | [diff] [blame] | 129 | !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \ |
| 130 | !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800)) |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 131 | # define ftell _ftelli64 |
| 132 | #endif |
| 133 | #endif |
| 134 | #if !defined(ftruncate) |
| 135 | # define ftruncate(file,length) NTTruncateFile(file,length) |
| 136 | #endif |
| 137 | #if !defined(getcwd) |
| 138 | # define getcwd _getcwd |
| 139 | #endif |
| 140 | #if !defined(getpid) |
| 141 | # define getpid _getpid |
| 142 | #endif |
| 143 | #if !defined(hypot) |
| 144 | # define hypot _hypot |
| 145 | #endif |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 146 | #if !defined(isatty) |
| 147 | # define isatty _isatty |
| 148 | #endif |
| 149 | #if !defined(locale_t) |
| 150 | #define locale_t _locale_t |
| 151 | #endif |
| 152 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \ |
Cristy | 087a059 | 2015-08-30 16:40:35 -0400 | [diff] [blame] | 153 | !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \ |
| 154 | !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800)) |
cristy | 1b8a131 | 2014-06-17 00:22:22 +0000 | [diff] [blame] | 155 | #if !defined(lseek) |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 156 | # define lseek _lseeki64 |
cristy | 1b8a131 | 2014-06-17 00:22:22 +0000 | [diff] [blame] | 157 | #endif |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 158 | #else |
cristy | 1b8a131 | 2014-06-17 00:22:22 +0000 | [diff] [blame] | 159 | #if !defined(lseek) |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 160 | # define lseek _lseek |
| 161 | #endif |
cristy | 1b8a131 | 2014-06-17 00:22:22 +0000 | [diff] [blame] | 162 | #endif |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 163 | #if !defined(MAGICKCORE_LTDL_DELEGATE) |
| 164 | #if !defined(lt_dlclose) |
| 165 | # define lt_dlclose(handle) NTCloseLibrary(handle) |
| 166 | #endif |
| 167 | #if !defined(lt_dlerror) |
| 168 | # define lt_dlerror() NTGetLibraryError() |
| 169 | #endif |
| 170 | #if !defined(lt_dlexit) |
| 171 | # define lt_dlexit() NTExitLibrary() |
| 172 | #endif |
| 173 | #if !defined(lt_dlinit) |
| 174 | # define lt_dlinit() NTInitializeLibrary() |
| 175 | #endif |
| 176 | #if !defined(lt_dlopen) |
| 177 | # define lt_dlopen(filename) NTOpenLibrary(filename) |
| 178 | #endif |
| 179 | #if !defined(lt_dlsetsearchpath) |
| 180 | # define lt_dlsetsearchpath(path) NTSetSearchPath(path) |
| 181 | #endif |
| 182 | #if !defined(lt_dlsym) |
| 183 | # define lt_dlsym(handle,name) NTGetLibrarySymbol(handle,name) |
| 184 | #endif |
| 185 | #endif |
| 186 | #if !defined(mkdir) |
| 187 | # define mkdir _mkdir |
| 188 | #endif |
| 189 | #if !defined(mmap) |
| 190 | # define mmap(address,length,protection,access,file,offset) \ |
| 191 | NTMapMemory(address,length,protection,access,file,offset) |
| 192 | #endif |
| 193 | #if !defined(msync) |
| 194 | # define msync(address,length,flags) NTSyncMemory(address,length,flags) |
| 195 | #endif |
| 196 | #if !defined(munmap) |
| 197 | # define munmap(address,length) NTUnmapMemory(address,length) |
| 198 | #endif |
| 199 | #if !defined(opendir) |
| 200 | # define opendir(directory) NTOpenDirectory(directory) |
| 201 | #endif |
| 202 | #if !defined(open) |
| 203 | # define open _open |
| 204 | #endif |
| 205 | #if !defined(pclose) |
| 206 | # define pclose _pclose |
| 207 | #endif |
| 208 | #if !defined(popen) |
| 209 | # define popen _popen |
| 210 | #endif |
| 211 | #if !defined(fprintf_l) |
| 212 | #define fprintf_l _fprintf_s_l |
| 213 | #endif |
| 214 | #if !defined(read) |
dirk | b0d783f | 2014-08-31 10:48:05 +0000 | [diff] [blame] | 215 | # define read(fd,buffer,count) _read(fd,buffer,(unsigned int) count) |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 216 | #endif |
| 217 | #if !defined(readdir) |
| 218 | # define readdir(directory) NTReadDirectory(directory) |
| 219 | #endif |
| 220 | #if !defined(seekdir) |
| 221 | # define seekdir(directory,offset) NTSeekDirectory(directory,offset) |
| 222 | #endif |
| 223 | #if !defined(setmode) |
| 224 | # define setmode _setmode |
| 225 | #endif |
| 226 | #if !defined(spawnvp) |
| 227 | # define spawnvp _spawnvp |
| 228 | #endif |
| 229 | #if !defined(strtod_l) |
| 230 | #define strtod_l _strtod_l |
| 231 | #endif |
| 232 | #if !defined(stat) && !defined(__BORLANDC__) |
| 233 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \ |
Cristy | 087a059 | 2015-08-30 16:40:35 -0400 | [diff] [blame] | 234 | !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \ |
| 235 | !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800)) |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 236 | # define stat _stati64 |
| 237 | #else |
| 238 | # define stat _stat |
| 239 | #endif |
| 240 | #endif |
| 241 | #if !defined(strcasecmp) |
| 242 | # define strcasecmp _stricmp |
| 243 | #endif |
| 244 | #if !defined(strncasecmp) |
| 245 | # define strncasecmp _strnicmp |
| 246 | #endif |
| 247 | #if !defined(sysconf) |
| 248 | # define sysconf(name) NTSystemConfiguration(name) |
| 249 | #endif |
| 250 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \ |
Cristy | 087a059 | 2015-08-30 16:40:35 -0400 | [diff] [blame] | 251 | !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \ |
| 252 | !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800)) |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 253 | # define tell _telli64 |
| 254 | #else |
| 255 | # define tell _tell |
| 256 | #endif |
| 257 | #if !defined(telldir) |
| 258 | # define telldir(directory) NTTellDirectory(directory) |
| 259 | #endif |
| 260 | #if !defined(tempnam) |
| 261 | # define tempnam _tempnam_s |
| 262 | #endif |
cristy | c330609 | 2015-02-28 22:57:28 +0000 | [diff] [blame] | 263 | #if !defined(umask) |
| 264 | # define umask _umask |
| 265 | #endif |
cristy | 4d1b5d4 | 2015-02-22 00:30:57 +0000 | [diff] [blame] | 266 | #if !defined(unlink) |
| 267 | # define unlink _unlink |
| 268 | #endif |
Cristy | 4bb3ba9 | 2016-04-24 14:28:07 -0400 | [diff] [blame] | 269 | #if !defined(utime) |
| 270 | # define utime _utime |
| 271 | #endif |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 272 | #if !defined(vfprintf_l) |
| 273 | #define vfprintf_l _vfprintf_l |
| 274 | #endif |
| 275 | #if !defined(vsnprintf) |
| 276 | #if !defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER < 1500) |
| 277 | #define vsnprintf _vsnprintf |
| 278 | #endif |
| 279 | #endif |
| 280 | #if !defined(vsnprintf_l) |
| 281 | #define vsnprintf_l _vsnprintf_l |
| 282 | #endif |
| 283 | #if !defined(write) |
dirk | b0d783f | 2014-08-31 10:48:05 +0000 | [diff] [blame] | 284 | # define write(fd,buffer,count) _write(fd,buffer,(unsigned int) count) |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 285 | #endif |
| 286 | #if !defined(wstat) && !defined(__BORLANDC__) |
| 287 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \ |
Cristy | 087a059 | 2015-08-30 16:40:35 -0400 | [diff] [blame] | 288 | !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \ |
| 289 | !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800)) |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 290 | # define wstat _wstati64 |
| 291 | #else |
| 292 | # define wstat _wstat |
| 293 | #endif |
| 294 | #endif |
| 295 | |
cristy | 1db8adc | 2014-02-21 17:33:48 +0000 | [diff] [blame] | 296 | #if defined(__BORLANDC__) |
| 297 | #undef _O_RANDOM |
| 298 | #define _O_RANDOM 0 |
| 299 | #undef _O_SEQUENTIAL |
| 300 | #define _O_SEQUENTIAL 0 |
| 301 | #undef _O_SHORT_LIVED |
| 302 | #define _O_SHORT_LIVED 0 |
| 303 | #undef _O_TEMPORARY |
| 304 | #define _O_TEMPORARY 0 |
| 305 | #endif |
| 306 | |
| 307 | #undef gettimeofday |
| 308 | |
cristy | 2c5fc27 | 2012-02-22 01:27:46 +0000 | [diff] [blame] | 309 | typedef struct _GhostInfo |
| 310 | GhostInfo_; |
cristy | daeba5e | 2011-10-13 17:32:44 +0000 | [diff] [blame] | 311 | |
| 312 | extern MagickExport char |
| 313 | **NTArgvToUTF8(const int argc,wchar_t **); |
| 314 | |
cristy | 2c5fc27 | 2012-02-22 01:27:46 +0000 | [diff] [blame] | 315 | extern MagickExport const GhostInfo_ |
cristy | daeba5e | 2011-10-13 17:32:44 +0000 | [diff] [blame] | 316 | *NTGhostscriptDLLVectors(void); |
| 317 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 318 | extern MagickExport void |
cristy | 417d845 | 2011-10-13 17:09:49 +0000 | [diff] [blame] | 319 | NTErrorHandler(const ExceptionType,const char *,const char *), |
dirk | 27496b9 | 2015-11-23 21:04:09 +0100 | [diff] [blame] | 320 | NTGhostscriptUnLoadDLL(void), |
cristy | 417d845 | 2011-10-13 17:09:49 +0000 | [diff] [blame] | 321 | NTWarningHandler(const ExceptionType,const char *,const char *); |
cristy | 2c5fc27 | 2012-02-22 01:27:46 +0000 | [diff] [blame] | 322 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 323 | |
| 324 | #if defined(__cplusplus) || defined(c_plusplus) |
| 325 | } |
cristy | 2c5fc27 | 2012-02-22 01:27:46 +0000 | [diff] [blame] | 326 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 327 | |
cristy | 2c5fc27 | 2012-02-22 01:27:46 +0000 | [diff] [blame] | 328 | #endif |