]> granicus.if.org Git - imagemagick/blob - magick/nt-base.h
(no commit message)
[imagemagick] / magick / 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 "magick/delegate.h"
26 #include "magick/delegate-private.h"
27 #include "magick/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)
198 #define fprintf  _fprintf_s
199 #endif
200 #if !defined(fprintf_l)
201 #define fprintf_l  _fprintf_s_l
202 #endif
203 #if !defined(read)
204 #  define read  _read
205 #endif
206 #if !defined(readdir)
207 #  define readdir(directory)  NTReadDirectory(directory)
208 #endif
209 #if !defined(seekdir)
210 #  define seekdir(directory,offset)  NTSeekDirectory(directory,offset)
211 #endif
212 #if !defined(setmode)
213 #  define setmode  _setmode
214 #endif
215 #if !defined(spawnvp)
216 #  define spawnvp  _spawnvp
217 #endif
218 #if !defined(strtod_l)
219 #define strtod_l  _strtod_l
220 #endif
221 #if !defined(stat) && !defined(__BORLANDC__)
222 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
223   !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
224 #  define stat  _stati64
225 #else
226 #  define stat  _stat
227 #endif
228 #endif
229 #if !defined(strcasecmp)
230 #  define strcasecmp  _strcmpi
231 #endif
232 #if !defined(strncasecmp)
233 #  define strncasecmp  _strnicmp
234 #endif
235 #if !defined(sysconf)
236 #  define sysconf(name)  NTSystemConfiguration(name)
237 #endif
238 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
239   !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
240 #  define tell  _telli64
241 #else
242 #  define tell  _tell
243 #endif
244 #if !defined(telldir)
245 #  define telldir(directory)  NTTellDirectory(directory)
246 #endif
247 #if !defined(tempnam)
248 #  define tempnam  _tempnam_s
249 #endif
250 #if !defined(vfprintf_l)
251 #define vfprintf_l  _vfprintf_l
252 #endif
253 #if !defined(vsnprintf)
254 #if !defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER < 1500)
255 #define vsnprintf _vsnprintf 
256 #endif
257 #endif
258 #if !defined(vsnprintf_l)
259 #define vsnprintf_l  _vsnprintf_l
260 #endif
261 #if !defined(write)
262 #  define write  _write
263 #endif
264 #if !defined(wstat) && !defined(__BORLANDC__)
265 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
266   !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
267 #  define wstat  _wstati64
268 #else
269 #  define wstat  _wstat
270 #endif
271 #endif
272
273 #if defined(_MT) && defined(MAGICKCORE_WINDOWS_SUPPORT)
274 #  define SAFE_GLOBAL  __declspec(thread)
275 #else
276 #  define SAFE_GLOBAL
277 #endif
278
279 #if defined(__BORLANDC__)
280 #undef _O_RANDOM
281 #define _O_RANDOM 0
282 #undef _O_SEQUENTIAL
283 #define _O_SEQUENTIAL 0
284 #undef _O_SHORT_LIVED
285 #define _O_SHORT_LIVED 0
286 #undef _O_TEMPORARY
287 #define _O_TEMPORARY 0
288 #endif
289
290 #if !defined(XS_VERSION)
291 struct dirent
292 {
293   char
294     d_name[2048];
295
296   int
297     d_namlen;
298 };
299
300 typedef struct _DIR
301 {
302   HANDLE
303     hSearch;
304
305   WIN32_FIND_DATA
306     Win32FindData;
307
308   BOOL
309     firsttime;
310
311   struct dirent
312     file_info;
313 } DIR;
314
315 typedef struct _NTMEMORYSTATUSEX
316 {
317   DWORD
318     dwLength,
319     dwMemoryLoad;
320
321   DWORDLONG
322     ullTotalPhys,
323     ullAvailPhys,
324     ullTotalPageFile,
325     ullAvailPageFile,
326     ullTotalVirtual,
327     ullAvailVirtual,
328     ullAvailExtendedVirtual;
329 } NTMEMORYSTATUSEX;
330
331 #if !defined(__MINGW32__)
332 struct timezone
333 {
334   int
335     tz_minuteswest,
336     tz_dsttime;
337 };
338 #endif
339
340 typedef UINT
341   (CALLBACK *LPFNDLLFUNC1)(DWORD,UINT);
342
343 typedef UINT
344   (CALLBACK *LPFNDLLFUNC2)(NTMEMORYSTATUSEX *);
345
346 #endif
347
348 #if defined(MAGICKCORE_BZLIB_DELEGATE)
349 #  if defined(_WIN32)
350 #    define BZ_IMPORT 1
351 #  endif
352 #endif
353
354 extern MagickExport char
355   *NTGetLastError(void);
356
357 extern MagickExport const GhostInfo
358   *NTGhostscriptDLLVectors(void);
359
360 #if !defined(MAGICKCORE_LTDL_DELEGATE)
361 extern MagickExport const char
362   *NTGetLibraryError(void);
363 #endif
364
365 #if !defined(XS_VERSION)
366 extern MagickExport const char
367   *NTGetLibraryError(void);
368
369 extern MagickExport DIR
370   *NTOpenDirectory(const char *);
371
372 extern MagickExport double
373   NTElapsedTime(void),
374   NTUserTime(void);
375
376 extern MagickExport int
377   Exit(int),
378 #if !defined(__MINGW32__)
379   gettimeofday(struct timeval *,struct timezone *),
380 #endif
381   IsWindows95(),
382   NTCloseDirectory(DIR *),
383   NTCloseLibrary(void *),
384   NTControlHandler(void),
385   NTExitLibrary(void),
386   NTTruncateFile(int,off_t),
387   NTGhostscriptDLL(char *,int),
388   NTGhostscriptEXE(char *,int),
389   NTGhostscriptFonts(char *,int),
390   NTGhostscriptLoadDLL(void),
391   NTGhostscriptUnLoadDLL(void),
392   NTInitializeLibrary(void),
393   NTSetSearchPath(const char *),
394   NTSyncMemory(void *,size_t,int),
395   NTUnmapMemory(void *,size_t),
396   NTSystemCommand(const char *);
397
398 extern MagickExport ssize_t
399   NTSystemConfiguration(int),
400   NTTellDirectory(DIR *);
401
402 extern MagickExport MagickBooleanType
403   NTGatherRandomData(const size_t,unsigned char *),
404   NTGetExecutionPath(char *,const size_t),
405   NTGetModulePath(const char *,char *),
406   NTReportEvent(const char *,const MagickBooleanType),
407   NTReportException(const char *,const MagickBooleanType);
408
409 extern MagickExport struct dirent
410   *NTReadDirectory(DIR *);
411
412 extern MagickExport unsigned char
413   *NTRegistryKeyLookup(const char *),
414   *NTResourceToBlob(const char *);
415
416 extern MagickExport void
417   NTErrorHandler(const ExceptionType,const char *,const char *),
418   *NTGetLibrarySymbol(void *,const char *),
419   *NTMapMemory(char *,size_t,int,int,int,MagickOffsetType),
420   *NTOpenLibrary(const char *),
421   NTSeekDirectory(DIR *,ssize_t),
422   NTWarningHandler(const ExceptionType,const char *,const char *);
423
424 #endif /* !XS_VERSION */
425
426 #if defined(__cplusplus) || defined(c_plusplus)
427 }
428 #endif /* !C++ */
429
430 #endif /* !_MAGICKCORE_NT_BASE_H */