blob: 3c947a0c24e18855d76fb6c3140199bfcebaa6a1 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
Cristy7ce65e72015-12-12 18:03:16 -05002 Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization
cristy3ed852e2009-09-05 21:47:34 +00003 dedicated to making software imaging solutions freely available.
cristy2c5fc272012-02-22 01:27:46 +00004
cristy3ed852e2009-09-05 21:47:34 +00005 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
cristy2c5fc272012-02-22 01:27:46 +00007
cristy3ed852e2009-09-05 21:47:34 +00008 http://www.imagemagick.org/script/license.php
cristy2c5fc272012-02-22 01:27:46 +00009
cristy3ed852e2009-09-05 21:47:34 +000010 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
cristy6398ec72013-11-28 02:00:27 +000021#include "MagickCore/exception.h"
22#include "MagickCore/geometry.h"
23
cristy3ed852e2009-09-05 21:47:34 +000024#if defined(__cplusplus) || defined(c_plusplus)
25extern "C" {
26#endif
27
cristy30603ff2011-10-07 00:43:07 +000028#if defined(MAGICKCORE_WINDOWS_SUPPORT)
cristy1db8adc2014-02-21 17:33:48 +000029
cristyd04eadc2014-02-21 18:36:36 +000030#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>
cristy9e2b6242014-03-25 11:49:41 +000040#include <malloc.h>
cristyd04eadc2014-02-21 18:36:36 +000041#if defined(_DEBUG) && !defined(__MINGW32__) && !defined(__MINGW64__)
42#include <crtdbg.h>
43#endif
44
cristy1db8adc2014-02-21 17:33:48 +000045#define PROT_READ 0x01
46#define PROT_WRITE 0x02
47#define MAP_SHARED 0x01
48#define MAP_PRIVATE 0x02
49#define MAP_ANONYMOUS 0x20
50#define F_OK 0
51#define R_OK 4
52#define W_OK 2
53#define RW_OK 6
54#define _SC_PAGESIZE 1
55#define _SC_PHYS_PAGES 2
56#define _SC_OPEN_MAX 3
57#if !defined(SSIZE_MAX)
58#define SSIZE_MAX 0x7fffffffL
59#endif
60
61/*
62 _MSC_VER values:
63 1100 MSVC 5.0
64 1200 MSVC 6.0
65 1300 MSVC 7.0 Visual C++ .NET 2002
66 1310 Visual c++ .NET 2003
67 1400 Visual C++ 2005
68 1500 Visual C++ 2008
Cristy36421ee2015-08-28 11:58:20 -040069 1600 Visual C++ 2010
70 1700 Visual C++ 2012
71 1800 Visual C++ 2013
72 1900 Visual C++ 2015
cristy1db8adc2014-02-21 17:33:48 +000073*/
74
75#if !defined(chsize)
76# if defined(__BORLANDC__)
77# define chsize(file,length) chsize(file,length)
78# else
79# define chsize(file,length) _chsize(file,length)
80# endif
81#endif
82
83#if !defined(access)
84#if defined(_VISUALC_) && (_MSC_VER >= 1400)
85# define access(path,mode) _access_s(path,mode)
86#endif
87#endif
88#if !defined(chdir)
89# define chdir _chdir
90#endif
91#if !defined(close)
92# define close _close
93#endif
94#if !defined(closedir)
95# define closedir(directory) NTCloseDirectory(directory)
96#endif
97#if !defined(fdopen)
98# define fdopen _fdopen
99#endif
100#if !defined(fileno)
101# define fileno _fileno
102#endif
103#if !defined(fseek) && !defined(__MINGW32__) && !defined(__MINGW64__)
104#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
Cristy087a0592015-08-30 16:40:35 -0400105 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \
106 !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800))
cristy1db8adc2014-02-21 17:33:48 +0000107# define fseek _fseeki64
108#endif
109#endif
110#if !defined(fstat) && !defined(__BORLANDC__)
111#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
Cristy087a0592015-08-30 16:40:35 -0400112 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \
113 !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800))
cristy1db8adc2014-02-21 17:33:48 +0000114# define fstat _fstati64
115#else
116# define fstat _fstat
117#endif
118#endif
119#if !defined(fsync)
120# define fsync _commit
121#endif
122#if !defined(ftell) && !defined(__MINGW32__) && !defined(__MINGW64__)
123#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
Cristy087a0592015-08-30 16:40:35 -0400124 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \
125 !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800))
cristy1db8adc2014-02-21 17:33:48 +0000126# define ftell _ftelli64
127#endif
128#endif
129#if !defined(ftruncate)
130# define ftruncate(file,length) NTTruncateFile(file,length)
131#endif
132#if !defined(getcwd)
133# define getcwd _getcwd
134#endif
135#if !defined(getpid)
136# define getpid _getpid
137#endif
138#if !defined(hypot)
139# define hypot _hypot
140#endif
141#if !defined(inline)
142# define inline __inline
143#endif
144#if !defined(isatty)
145# define isatty _isatty
146#endif
147#if !defined(locale_t)
148#define locale_t _locale_t
149#endif
150#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
Cristy087a0592015-08-30 16:40:35 -0400151 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \
152 !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800))
cristy1b8a1312014-06-17 00:22:22 +0000153#if !defined(lseek)
cristy1db8adc2014-02-21 17:33:48 +0000154# define lseek _lseeki64
cristy1b8a1312014-06-17 00:22:22 +0000155#endif
cristy1db8adc2014-02-21 17:33:48 +0000156#else
cristy1b8a1312014-06-17 00:22:22 +0000157#if !defined(lseek)
cristy1db8adc2014-02-21 17:33:48 +0000158# define lseek _lseek
159#endif
cristy1b8a1312014-06-17 00:22:22 +0000160#endif
cristy1db8adc2014-02-21 17:33:48 +0000161#if !defined(MAGICKCORE_LTDL_DELEGATE)
162#if !defined(lt_dlclose)
163# define lt_dlclose(handle) NTCloseLibrary(handle)
164#endif
165#if !defined(lt_dlerror)
166# define lt_dlerror() NTGetLibraryError()
167#endif
168#if !defined(lt_dlexit)
169# define lt_dlexit() NTExitLibrary()
170#endif
171#if !defined(lt_dlinit)
172# define lt_dlinit() NTInitializeLibrary()
173#endif
174#if !defined(lt_dlopen)
175# define lt_dlopen(filename) NTOpenLibrary(filename)
176#endif
177#if !defined(lt_dlsetsearchpath)
178# define lt_dlsetsearchpath(path) NTSetSearchPath(path)
179#endif
180#if !defined(lt_dlsym)
181# define lt_dlsym(handle,name) NTGetLibrarySymbol(handle,name)
182#endif
183#endif
184#if !defined(mkdir)
185# define mkdir _mkdir
186#endif
187#if !defined(mmap)
188# define mmap(address,length,protection,access,file,offset) \
189 NTMapMemory(address,length,protection,access,file,offset)
190#endif
191#if !defined(msync)
192# define msync(address,length,flags) NTSyncMemory(address,length,flags)
193#endif
194#if !defined(munmap)
195# define munmap(address,length) NTUnmapMemory(address,length)
196#endif
197#if !defined(opendir)
198# define opendir(directory) NTOpenDirectory(directory)
199#endif
200#if !defined(open)
201# define open _open
202#endif
203#if !defined(pclose)
204# define pclose _pclose
205#endif
206#if !defined(popen)
207# define popen _popen
208#endif
209#if !defined(fprintf_l)
210#define fprintf_l _fprintf_s_l
211#endif
212#if !defined(read)
dirkb0d783f2014-08-31 10:48:05 +0000213# define read(fd,buffer,count) _read(fd,buffer,(unsigned int) count)
cristy1db8adc2014-02-21 17:33:48 +0000214#endif
215#if !defined(readdir)
216# define readdir(directory) NTReadDirectory(directory)
217#endif
218#if !defined(seekdir)
219# define seekdir(directory,offset) NTSeekDirectory(directory,offset)
220#endif
221#if !defined(setmode)
222# define setmode _setmode
223#endif
224#if !defined(spawnvp)
225# define spawnvp _spawnvp
226#endif
227#if !defined(strtod_l)
228#define strtod_l _strtod_l
229#endif
230#if !defined(stat) && !defined(__BORLANDC__)
231#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
Cristy087a0592015-08-30 16:40:35 -0400232 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \
233 !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800))
cristy1db8adc2014-02-21 17:33:48 +0000234# define stat _stati64
235#else
236# define stat _stat
237#endif
238#endif
239#if !defined(strcasecmp)
240# define strcasecmp _stricmp
241#endif
242#if !defined(strncasecmp)
243# define strncasecmp _strnicmp
244#endif
245#if !defined(sysconf)
246# define sysconf(name) NTSystemConfiguration(name)
247#endif
248#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
Cristy087a0592015-08-30 16:40:35 -0400249 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \
250 !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800))
cristy1db8adc2014-02-21 17:33:48 +0000251# define tell _telli64
252#else
253# define tell _tell
254#endif
255#if !defined(telldir)
256# define telldir(directory) NTTellDirectory(directory)
257#endif
258#if !defined(tempnam)
259# define tempnam _tempnam_s
260#endif
cristyc3306092015-02-28 22:57:28 +0000261#if !defined(umask)
262# define umask _umask
263#endif
cristy4d1b5d42015-02-22 00:30:57 +0000264#if !defined(unlink)
265# define unlink _unlink
266#endif
cristy1db8adc2014-02-21 17:33:48 +0000267#if !defined(vfprintf_l)
268#define vfprintf_l _vfprintf_l
269#endif
270#if !defined(vsnprintf)
271#if !defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER < 1500)
272#define vsnprintf _vsnprintf
273#endif
274#endif
275#if !defined(vsnprintf_l)
276#define vsnprintf_l _vsnprintf_l
277#endif
278#if !defined(write)
dirkb0d783f2014-08-31 10:48:05 +0000279# define write(fd,buffer,count) _write(fd,buffer,(unsigned int) count)
cristy1db8adc2014-02-21 17:33:48 +0000280#endif
281#if !defined(wstat) && !defined(__BORLANDC__)
282#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
Cristy087a0592015-08-30 16:40:35 -0400283 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && \
284 !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ < 0x800))
cristy1db8adc2014-02-21 17:33:48 +0000285# define wstat _wstati64
286#else
287# define wstat _wstat
288#endif
289#endif
290
cristy1db8adc2014-02-21 17:33:48 +0000291#if defined(__BORLANDC__)
292#undef _O_RANDOM
293#define _O_RANDOM 0
294#undef _O_SEQUENTIAL
295#define _O_SEQUENTIAL 0
296#undef _O_SHORT_LIVED
297#define _O_SHORT_LIVED 0
298#undef _O_TEMPORARY
299#define _O_TEMPORARY 0
300#endif
301
302#undef gettimeofday
303
cristy2c5fc272012-02-22 01:27:46 +0000304typedef struct _GhostInfo
305 GhostInfo_;
cristydaeba5e2011-10-13 17:32:44 +0000306
307extern MagickExport char
308 **NTArgvToUTF8(const int argc,wchar_t **);
309
cristy2c5fc272012-02-22 01:27:46 +0000310extern MagickExport const GhostInfo_
cristydaeba5e2011-10-13 17:32:44 +0000311 *NTGhostscriptDLLVectors(void);
312
cristy3ed852e2009-09-05 21:47:34 +0000313extern MagickExport void
cristy417d8452011-10-13 17:09:49 +0000314 NTErrorHandler(const ExceptionType,const char *,const char *),
dirk27496b92015-11-23 21:04:09 +0100315 NTGhostscriptUnLoadDLL(void),
cristy417d8452011-10-13 17:09:49 +0000316 NTWarningHandler(const ExceptionType,const char *,const char *);
cristy2c5fc272012-02-22 01:27:46 +0000317#endif
cristy3ed852e2009-09-05 21:47:34 +0000318
319#if defined(__cplusplus) || defined(c_plusplus)
320}
cristy2c5fc272012-02-22 01:27:46 +0000321#endif
cristy3ed852e2009-09-05 21:47:34 +0000322
cristy2c5fc272012-02-22 01:27:46 +0000323#endif