]> granicus.if.org Git - imagemagick/blob - MagickCore/nt-base-private.h
bc7c2f4fa88c9dbd85768116f9a7f756e0c42c43
[imagemagick] / MagickCore / nt-base-private.h
1 /*
2   Copyright 1999-2012 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 private methods.
17 */
18 #ifndef _MAGICKCORE_NT_BASE_PRIVATE_H
19 #define _MAGICKCORE_NT_BASE_PRIVATE_H
20
21 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24
25 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
26
27 #include "MagickCore/delegate.h"
28 #include "MagickCore/delegate-private.h"
29 #include "MagickCore/exception.h"
30 #include "MagickCore/splay-tree.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__)
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__)
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__)
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 #undef gettimeofday
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 MagickPrivate char
355   *NTGetLastError(void);
356
357 #if !defined(MAGICKCORE_LTDL_DELEGATE)
358 extern MagickPrivate const char
359   *NTGetLibraryError(void);
360 #endif
361
362 #if !defined(XS_VERSION)
363 extern MagickPrivate const char
364   *NTGetLibraryError(void);
365
366 extern MagickPrivate DIR
367   *NTOpenDirectory(const char *);
368
369 extern MagickPrivate double
370   NTElapsedTime(void),
371   NTUserTime(void);
372
373 extern MagickPrivate int
374   Exit(int),
375 #if !defined(__MINGW32__)
376   gettimeofday(struct timeval *,struct timezone *),
377 #endif
378   IsWindows95(void),
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   NTInitializeLibrary(void),
389   NTSetSearchPath(const char *),
390   NTSyncMemory(void *,size_t,int),
391   NTUnmapMemory(void *,size_t),
392   NTSystemCommand(const char *);
393
394 extern MagickPrivate ssize_t
395   NTSystemConfiguration(int),
396   NTTellDirectory(DIR *);
397
398 extern MagickPrivate MagickBooleanType
399   NTGatherRandomData(const size_t,unsigned char *),
400   NTGetExecutionPath(char *,const size_t),
401   NTGetModulePath(const char *,char *),
402   NTReportEvent(const char *,const MagickBooleanType),
403   NTReportException(const char *,const MagickBooleanType);
404
405 extern MagickPrivate struct dirent
406   *NTReadDirectory(DIR *);
407
408 extern MagickPrivate unsigned char
409   *NTRegistryKeyLookup(const char *),
410   *NTResourceToBlob(const char *);
411
412 extern MagickPrivate void
413   *NTGetLibrarySymbol(void *,const char *),
414   *NTMapMemory(char *,size_t,int,int,int,MagickOffsetType),
415   *NTOpenLibrary(const char *),
416   NTSeekDirectory(DIR *,ssize_t);
417
418 #endif /* !XS_VERSION */
419
420 #endif /* MAGICKCORE_WINDOWS_SUPPORT */
421
422 #if defined(__cplusplus) || defined(c_plusplus)
423 }
424 #endif /* !C++ */
425
426 #endif /* !_MAGICKCORE_NT_BASE_H */