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