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