]> granicus.if.org Git - imagemagick/blob - MagickCore/nt-base.h
Clone the image->image_info structure to prevent a dangling pointer
[imagemagick] / MagickCore / nt-base.h
1 /*
2   Copyright 1999-2015 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 #include "MagickCore/exception.h"
22 #include "MagickCore/geometry.h"
23
24 #if defined(__cplusplus) || defined(c_plusplus)
25 extern "C" {
26 #endif
27
28 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
29
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>
40 #include <malloc.h>
41 #if defined(_DEBUG) && !defined(__MINGW32__) && !defined(__MINGW64__)
42 #include <crtdbg.h>
43 #endif
44
45 #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
69     1600 Visual C++ 2010
70     1700 Visual C++ 2012
71     1800 Visual C++ 2013
72     1900 Visual C++ 2015
73 */
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) && \
105   !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
106 #  define fseek  _fseeki64
107 #endif
108 #endif
109 #if !defined(fstat) && !defined(__BORLANDC__)
110 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
111   !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
112 #  define fstat  _fstati64
113 #else
114 #  define fstat  _fstat
115 #endif
116 #endif
117 #if !defined(fsync)
118 #  define fsync  _commit
119 #endif
120 #if !defined(ftell) && !defined(__MINGW32__) && !defined(__MINGW64__)
121 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
122   !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
123 #  define ftell  _ftelli64
124 #endif
125 #endif
126 #if !defined(ftruncate)
127 #  define ftruncate(file,length)  NTTruncateFile(file,length)
128 #endif
129 #if !defined(getcwd)
130 #  define getcwd  _getcwd
131 #endif
132 #if !defined(getpid)
133 #  define getpid  _getpid
134 #endif
135 #if !defined(hypot)
136 #  define hypot  _hypot
137 #endif
138 #if !defined(inline)
139 #  define inline __inline
140 #endif
141 #if !defined(isatty)
142 #  define isatty  _isatty
143 #endif
144 #if !defined(locale_t)
145 #define locale_t _locale_t
146 #endif
147 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
148   !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
149 #if !defined(lseek)
150 #  define lseek  _lseeki64
151 #endif
152 #else
153 #if !defined(lseek)
154 #  define lseek  _lseek
155 #endif
156 #endif
157 #if !defined(MAGICKCORE_LTDL_DELEGATE)
158 #if !defined(lt_dlclose)
159 #  define lt_dlclose(handle)  NTCloseLibrary(handle)
160 #endif
161 #if !defined(lt_dlerror)
162 #  define lt_dlerror()  NTGetLibraryError()
163 #endif
164 #if !defined(lt_dlexit)
165 #  define lt_dlexit()  NTExitLibrary()
166 #endif
167 #if !defined(lt_dlinit)
168 #  define lt_dlinit()  NTInitializeLibrary()
169 #endif
170 #if !defined(lt_dlopen)
171 #  define lt_dlopen(filename)  NTOpenLibrary(filename)
172 #endif
173 #if !defined(lt_dlsetsearchpath)
174 #  define lt_dlsetsearchpath(path)  NTSetSearchPath(path)
175 #endif
176 #if !defined(lt_dlsym)
177 #  define lt_dlsym(handle,name)  NTGetLibrarySymbol(handle,name)
178 #endif
179 #endif
180 #if !defined(mkdir)
181 #  define mkdir  _mkdir
182 #endif
183 #if !defined(mmap)
184 #  define mmap(address,length,protection,access,file,offset) \
185   NTMapMemory(address,length,protection,access,file,offset)
186 #endif
187 #if !defined(msync)
188 #  define msync(address,length,flags)  NTSyncMemory(address,length,flags)
189 #endif
190 #if !defined(munmap)
191 #  define munmap(address,length)  NTUnmapMemory(address,length)
192 #endif
193 #if !defined(opendir)
194 #  define opendir(directory)  NTOpenDirectory(directory)
195 #endif
196 #if !defined(open)
197 #  define open  _open
198 #endif
199 #if !defined(pclose)
200 #  define pclose  _pclose
201 #endif
202 #if !defined(popen)
203 #  define popen  _popen
204 #endif
205 #if !defined(fprintf_l)
206 #define fprintf_l  _fprintf_s_l
207 #endif
208 #if !defined(read)
209 #  define read(fd,buffer,count)  _read(fd,buffer,(unsigned int) count)
210 #endif
211 #if !defined(readdir)
212 #  define readdir(directory)  NTReadDirectory(directory)
213 #endif
214 #if !defined(seekdir)
215 #  define seekdir(directory,offset)  NTSeekDirectory(directory,offset)
216 #endif
217 #if !defined(setmode)
218 #  define setmode  _setmode
219 #endif
220 #if !defined(spawnvp)
221 #  define spawnvp  _spawnvp
222 #endif
223 #if !defined(strtod_l)
224 #define strtod_l  _strtod_l
225 #endif
226 #if !defined(stat) && !defined(__BORLANDC__)
227 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
228   !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
229 #  define stat  _stati64
230 #else
231 #  define stat  _stat
232 #endif
233 #endif
234 #if !defined(strcasecmp)
235 #  define strcasecmp  _stricmp
236 #endif
237 #if !defined(strncasecmp)
238 #  define strncasecmp  _strnicmp
239 #endif
240 #if !defined(sysconf)
241 #  define sysconf(name)  NTSystemConfiguration(name)
242 #endif
243 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
244   !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
245 #  define tell  _telli64
246 #else
247 #  define tell  _tell
248 #endif
249 #if !defined(telldir)
250 #  define telldir(directory)  NTTellDirectory(directory)
251 #endif
252 #if !defined(tempnam)
253 #  define tempnam  _tempnam_s
254 #endif
255 #if !defined(umask)
256 #  define umask  _umask
257 #endif
258 #if !defined(unlink)
259 #  define unlink  _unlink
260 #endif
261 #if !defined(vfprintf_l)
262 #define vfprintf_l  _vfprintf_l
263 #endif
264 #if !defined(vsnprintf)
265 #if !defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER < 1500)
266 #define vsnprintf _vsnprintf 
267 #endif
268 #endif
269 #if !defined(vsnprintf_l)
270 #define vsnprintf_l  _vsnprintf_l
271 #endif
272 #if !defined(write)
273 #  define write(fd,buffer,count)  _write(fd,buffer,(unsigned int) count)
274 #endif
275 #if !defined(wstat) && !defined(__BORLANDC__)
276 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
277   !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
278 #  define wstat  _wstati64
279 #else
280 #  define wstat  _wstat
281 #endif
282 #endif
283
284 #if defined(__BORLANDC__)
285 #undef _O_RANDOM
286 #define _O_RANDOM 0
287 #undef _O_SEQUENTIAL
288 #define _O_SEQUENTIAL 0
289 #undef _O_SHORT_LIVED
290 #define _O_SHORT_LIVED 0
291 #undef _O_TEMPORARY
292 #define _O_TEMPORARY 0
293 #endif
294
295 #undef gettimeofday
296
297 typedef struct _GhostInfo
298   GhostInfo_;
299
300 extern MagickExport char
301   **NTArgvToUTF8(const int argc,wchar_t **);
302
303 extern MagickExport const GhostInfo_
304   *NTGhostscriptDLLVectors(void);
305
306 extern MagickExport int
307   NTGhostscriptUnLoadDLL(void);
308
309 extern MagickExport void
310   NTErrorHandler(const ExceptionType,const char *,const char *),
311   NTWarningHandler(const ExceptionType,const char *,const char *);
312 #endif
313
314 #if defined(__cplusplus) || defined(c_plusplus)
315 }
316 #endif
317
318 #endif