MagickCore  6.8.5
nt-base.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2013 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 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
26 
27 #include "magick/delegate.h"
29 #include "magick/exception.h"
30 #include "magick/geometry.h"
31 
32 #define WIN32_LEAN_AND_MEAN
33 #define VC_EXTRALEAN
34 #define _CRT_SECURE_NO_DEPRECATE 1
35 #include <windows.h>
36 #include <wchar.h>
37 #include <winuser.h>
38 #include <wingdi.h>
39 #include <io.h>
40 #include <process.h>
41 #include <errno.h>
42 #if defined(_DEBUG) && !defined(__MINGW32__) && !defined(__MINGW64__)
43 #include <crtdbg.h>
44 #endif
45 
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
70 */
71 
72 #if !defined(chsize)
73 # if defined(__BORLANDC__)
74 # define chsize(file,length) chsize(file,length)
75 # else
76 # define chsize(file,length) _chsize(file,length)
77 # endif
78 #endif
79 
80 #if !defined(access)
81 #if defined(_VISUALC_) && (_MSC_VER >= 1400)
82 # define access(path,mode) _access_s(path,mode)
83 #endif
84 #endif
85 #if !defined(chdir)
86 # define chdir _chdir
87 #endif
88 #if !defined(close)
89 # define close _close
90 #endif
91 #if !defined(closedir)
92 # define closedir(directory) NTCloseDirectory(directory)
93 #endif
94 #if !defined(fdopen)
95 # define fdopen _fdopen
96 #endif
97 #if !defined(fileno)
98 # define fileno _fileno
99 #endif
100 #if !defined(fseek) && !defined(__MINGW32__) && !defined(__MINGW64__)
101 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
102  !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
103 # define fseek _fseeki64
104 #endif
105 #endif
106 #if !defined(fstat) && !defined(__BORLANDC__)
107 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
108  !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
109 # define fstat _fstati64
110 #else
111 # define fstat _fstat
112 #endif
113 #endif
114 #if !defined(fsync)
115 # define fsync _commit
116 #endif
117 #if !defined(ftell) && !defined(__MINGW32__) && !defined(__MINGW64__)
118 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
119  !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
120 # define ftell _ftelli64
121 #endif
122 #endif
123 #if !defined(ftruncate)
124 # define ftruncate(file,length) NTTruncateFile(file,length)
125 #endif
126 #if !defined(getcwd)
127 # define getcwd _getcwd
128 #endif
129 #if !defined(getpid)
130 # define getpid _getpid
131 #endif
132 #if !defined(hypot)
133 # define hypot _hypot
134 #endif
135 #if !defined(inline)
136 # define inline __inline
137 #endif
138 #if !defined(isatty)
139 # define isatty _isatty
140 #endif
141 #if !defined(locale_t)
142 #define locale_t _locale_t
143 #endif
144 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
145  !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
146 # define lseek _lseeki64
147 #else
148 # define lseek _lseek
149 #endif
150 #if !defined(MAGICKCORE_LTDL_DELEGATE)
151 #if !defined(lt_dlclose)
152 # define lt_dlclose(handle) NTCloseLibrary(handle)
153 #endif
154 #if !defined(lt_dlerror)
155 # define lt_dlerror() NTGetLibraryError()
156 #endif
157 #if !defined(lt_dlexit)
158 # define lt_dlexit() NTExitLibrary()
159 #endif
160 #if !defined(lt_dlinit)
161 # define lt_dlinit() NTInitializeLibrary()
162 #endif
163 #if !defined(lt_dlopen)
164 # define lt_dlopen(filename) NTOpenLibrary(filename)
165 #endif
166 #if !defined(lt_dlsetsearchpath)
167 # define lt_dlsetsearchpath(path) NTSetSearchPath(path)
168 #endif
169 #if !defined(lt_dlsym)
170 # define lt_dlsym(handle,name) NTGetLibrarySymbol(handle,name)
171 #endif
172 #endif
173 #if !defined(mkdir)
174 # define mkdir _mkdir
175 #endif
176 #if !defined(mmap)
177 # define mmap(address,length,protection,access,file,offset) \
178  NTMapMemory(address,length,protection,access,file,offset)
179 #endif
180 #if !defined(msync)
181 # define msync(address,length,flags) NTSyncMemory(address,length,flags)
182 #endif
183 #if !defined(munmap)
184 # define munmap(address,length) NTUnmapMemory(address,length)
185 #endif
186 #if !defined(opendir)
187 # define opendir(directory) NTOpenDirectory(directory)
188 #endif
189 #if !defined(open)
190 # define open _open
191 #endif
192 #if !defined(pclose)
193 # define pclose _pclose
194 #endif
195 #if !defined(popen)
196 # define popen _popen
197 #endif
198 #if !defined(fprintf_l)
199 #define fprintf_l _fprintf_s_l
200 #endif
201 #if !defined(read)
202 # define read _read
203 #endif
204 #if !defined(readdir)
205 # define readdir(directory) NTReadDirectory(directory)
206 #endif
207 #if !defined(seekdir)
208 # define seekdir(directory,offset) NTSeekDirectory(directory,offset)
209 #endif
210 #if !defined(setmode)
211 # define setmode _setmode
212 #endif
213 #if !defined(spawnvp)
214 # define spawnvp _spawnvp
215 #endif
216 #if !defined(strtod_l)
217 #define strtod_l _strtod_l
218 #endif
219 #if !defined(stat) && !defined(__BORLANDC__)
220 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
221  !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
222 # define stat _stati64
223 #else
224 # define stat _stat
225 #endif
226 #endif
227 #if !defined(strcasecmp)
228 # define strcasecmp _strcmpi
229 #endif
230 #if !defined(strncasecmp)
231 # define strncasecmp _strnicmp
232 #endif
233 #if !defined(sysconf)
234 # define sysconf(name) NTSystemConfiguration(name)
235 #endif
236 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
237  !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
238 # define tell _telli64
239 #else
240 # define tell _tell
241 #endif
242 #if !defined(telldir)
243 # define telldir(directory) NTTellDirectory(directory)
244 #endif
245 #if !defined(tempnam)
246 # define tempnam _tempnam_s
247 #endif
248 #if !defined(vfprintf_l)
249 #define vfprintf_l _vfprintf_l
250 #endif
251 #if !defined(vsnprintf)
252 #if !defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER < 1500)
253 #define vsnprintf _vsnprintf
254 #endif
255 #endif
256 #if !defined(vsnprintf_l)
257 #define vsnprintf_l _vsnprintf_l
258 #endif
259 #if !defined(write)
260 # define write _write
261 #endif
262 #if !defined(wstat) && !defined(__BORLANDC__)
263 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
264  !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
265 # define wstat _wstati64
266 #else
267 # define wstat _wstat
268 #endif
269 #endif
270 
271 #if defined(_MT) && defined(MAGICKCORE_WINDOWS_SUPPORT)
272 # define SAFE_GLOBAL __declspec(thread)
273 #else
274 # define SAFE_GLOBAL
275 #endif
276 
277 #if defined(__BORLANDC__)
278 #undef _O_RANDOM
279 #define _O_RANDOM 0
280 #undef _O_SEQUENTIAL
281 #define _O_SEQUENTIAL 0
282 #undef _O_SHORT_LIVED
283 #define _O_SHORT_LIVED 0
284 #undef _O_TEMPORARY
285 #define _O_TEMPORARY 0
286 #endif
287 
288 #if !defined(XS_VERSION)
289 struct dirent
290 {
291  char
292  d_name[2048];
293 
294  int
295  d_namlen;
296 };
297 
298 typedef struct _DIR
299 {
300  HANDLE
301  hSearch;
302 
303  WIN32_FIND_DATA
304  Win32FindData;
305 
306  BOOL
307  firsttime;
308 
309  struct dirent
310  file_info;
311 } DIR;
312 
313 typedef struct _NTMEMORYSTATUSEX
314 {
315  DWORD
316  dwLength,
317  dwMemoryLoad;
318 
319  DWORDLONG
320  ullTotalPhys,
321  ullAvailPhys,
322  ullTotalPageFile,
323  ullAvailPageFile,
324  ullTotalVirtual,
325  ullAvailVirtual,
326  ullAvailExtendedVirtual;
327 } NTMEMORYSTATUSEX;
328 
329 #if !defined(__MINGW32__) && !defined(__MINGW64__)
330 struct timezone
331 {
332  int
333  tz_minuteswest,
334  tz_dsttime;
335 };
336 #endif
337 
338 typedef UINT
339  (CALLBACK *LPFNDLLFUNC1)(DWORD,UINT);
340 
341 typedef UINT
342  (CALLBACK *LPFNDLLFUNC2)(NTMEMORYSTATUSEX *);
343 
344 #endif
345 
346 #if defined(MAGICKCORE_BZLIB_DELEGATE)
347 # if defined(_WIN32)
348 # define BZ_IMPORT 1
349 # endif
350 #endif
351 
352 extern MagickExport char
353  *NTGetLastError(void),
354  **NTArgvToUTF8(const int argc,wchar_t **);
355 
356 extern MagickExport const GhostInfo
357  *NTGhostscriptDLLVectors(void);
358 
359 #if !defined(MAGICKCORE_LTDL_DELEGATE)
360 extern MagickExport const char
361  *NTGetLibraryError(void);
362 #endif
363 
364 #if !defined(XS_VERSION)
365 extern MagickExport const char
366  *NTGetLibraryError(void);
367 
368 extern MagickExport DIR
369  *NTOpenDirectory(const char *);
370 
371 extern MagickExport double
372  NTElapsedTime(void),
373  NTUserTime(void);
374 
375 extern MagickExport int
376  Exit(int),
377 #if !defined(__MINGW32__) && !defined(__MINGW64__)
378  gettimeofday(struct timeval *,struct timezone *),
379 #endif
380  IsWindows95(),
381  NTCloseDirectory(DIR *),
382  NTCloseLibrary(void *),
383  NTControlHandler(void),
384  NTExitLibrary(void),
385  NTTruncateFile(int,off_t),
386  NTGhostscriptDLL(char *,int),
387  NTGhostscriptEXE(char *,int),
388  NTGhostscriptFonts(char *,int),
389  NTGhostscriptLoadDLL(void),
390  NTGhostscriptUnLoadDLL(void),
391  NTInitializeLibrary(void),
392  NTSetSearchPath(const char *),
393  NTSyncMemory(void *,size_t,int),
394  NTUnmapMemory(void *,size_t),
395  NTSystemCommand(const char *);
396 
397 extern MagickExport ssize_t
398  NTSystemConfiguration(int),
399  NTTellDirectory(DIR *);
400 
402  NTGatherRandomData(const size_t,unsigned char *),
403  NTGetExecutionPath(char *,const size_t),
404  NTGetModulePath(const char *,char *),
405  NTReportEvent(const char *,const MagickBooleanType),
406  NTReportException(const char *,const MagickBooleanType);
407 
408 extern MagickExport struct dirent
409  *NTReadDirectory(DIR *);
410 
411 extern MagickExport unsigned char
412  *NTRegistryKeyLookup(const char *),
413  *NTResourceToBlob(const char *);
414 
415 extern MagickExport void
416  NTErrorHandler(const ExceptionType,const char *,const char *),
417  *NTGetLibrarySymbol(void *,const char *),
418  *NTMapMemory(char *,size_t,int,int,int,MagickOffsetType),
419  *NTOpenLibrary(const char *),
420  NTSeekDirectory(DIR *,ssize_t),
421  NTWarningHandler(const ExceptionType,const char *,const char *);
422 
423 #endif /* !XS_VERSION */
424 
425 #endif /* MAGICK_WINDOWS_SUPPORT */
426 
427 #if defined(__cplusplus) || defined(c_plusplus)
428 }
429 #endif /* !C++ */
430 
431 #endif /* !_MAGICKCORE_NT_BASE_H */