blob: f758d926aee6df2e9fae3a3496768b178f2f7424 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
cristy7e41fe82010-12-04 23:12:08 +00002 Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization
cristy3ed852e2009-09-05 21:47:34 +00003 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)
22extern "C" {
23#endif
24
cristy4c08aed2011-07-01 19:47:50 +000025#include "MagickCore/delegate.h"
26#include "MagickCore/delegate-private.h"
27#include "MagickCore/exception.h"
cristy3ed852e2009-09-05 21:47:34 +000028
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)
cristy66f9c3c2011-08-13 17:12:28 +000078#if defined(_VISUALC_) && (_MSC_VER >= 1400)
cristy38d73d62011-05-19 01:55:37 +000079# define access(path,mode) _access_s(path,mode)
cristy3ed852e2009-09-05 21:47:34 +000080#endif
cristy66f9c3c2011-08-13 17:12:28 +000081#endif
cristy3ed852e2009-09-05 21:47:34 +000082#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
cristy9538f232011-03-29 15:07:55 +000097#if !defined(fseek) && !defined(__MINGW32__)
cristy32be6cf2011-03-29 14:53:14 +000098#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
cristy785c45f2011-03-29 14:55:11 +000099 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
cristy7f317702011-02-18 20:40:28 +0000100# define fseek _fseeki64
cristy9538f232011-03-29 15:07:55 +0000101#endif
cristy3ed852e2009-09-05 21:47:34 +0000102#endif
103#if !defined(fstat) && !defined(__BORLANDC__)
cristy0157aea2010-04-24 21:12:18 +0000104#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
cristy785c45f2011-03-29 14:55:11 +0000105 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
cristy3ed852e2009-09-05 21:47:34 +0000106# define fstat _fstati64
107#else
108# define fstat _fstat
109#endif
110#endif
111#if !defined(fsync)
112# define fsync _commit
113#endif
cristy9538f232011-03-29 15:07:55 +0000114#if !defined(ftell) && !defined(__MINGW32__)
cristy32be6cf2011-03-29 14:53:14 +0000115#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
cristy785c45f2011-03-29 14:55:11 +0000116 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
cristy7f317702011-02-18 20:40:28 +0000117# define ftell _ftelli64
cristy9538f232011-03-29 15:07:55 +0000118#endif
cristy3ed852e2009-09-05 21:47:34 +0000119#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
cristyaef5ccb2011-05-20 14:43:41 +0000138#if !defined(locale_t)
139#define locale_t _locale_t
140#endif
cristyecfd7242011-02-18 20:23:57 +0000141#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
cristy785c45f2011-03-29 14:55:11 +0000142 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
cristyecfd7242011-02-18 20:23:57 +0000143# define lseek _lseeki64
cristyf9a253e2011-03-29 15:10:42 +0000144#else
145# define lseek _lseek
cristyecfd7242011-02-18 20:23:57 +0000146#endif
cristy3ed852e2009-09-05 21:47:34 +0000147#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
cristyb51dff52011-05-19 16:55:47 +0000195#if !defined(fprintf_l)
cristyb51dff52011-05-19 16:55:47 +0000196#define fprintf_l _fprintf_s_l
197#endif
cristy3ed852e2009-09-05 21:47:34 +0000198#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
cristy98e91bd2010-01-12 01:11:42 +0000210#if !defined(spawnvp)
211# define spawnvp _spawnvp
212#endif
cristyaef5ccb2011-05-20 14:43:41 +0000213#if !defined(strtod_l)
214#define strtod_l _strtod_l
215#endif
cristy3ed852e2009-09-05 21:47:34 +0000216#if !defined(stat) && !defined(__BORLANDC__)
cristy0157aea2010-04-24 21:12:18 +0000217#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
cristyad09dad2011-03-30 21:50:41 +0000218 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
cristy3ed852e2009-09-05 21:47:34 +0000219# 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
cristyecfd7242011-02-18 20:23:57 +0000233#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
cristyad09dad2011-03-30 21:50:41 +0000234 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
cristyecfd7242011-02-18 20:23:57 +0000235# define tell _telli64
cristyf9a253e2011-03-29 15:10:42 +0000236#else
237# define tell _tell
cristyecfd7242011-02-18 20:23:57 +0000238#endif
cristy3ed852e2009-09-05 21:47:34 +0000239#if !defined(telldir)
240# define telldir(directory) NTTellDirectory(directory)
241#endif
242#if !defined(tempnam)
cristy38d73d62011-05-19 01:55:37 +0000243# define tempnam _tempnam_s
cristy3ed852e2009-09-05 21:47:34 +0000244#endif
cristy5d0cd952011-05-19 21:21:41 +0000245#if !defined(vfprintf_l)
cristyaef5ccb2011-05-20 14:43:41 +0000246#define vfprintf_l _vfprintf_l
cristy5d0cd952011-05-19 21:21:41 +0000247#endif
cristy3ed852e2009-09-05 21:47:34 +0000248#if !defined(vsnprintf)
cristyaef5ccb2011-05-20 14:43:41 +0000249#if !defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER < 1500)
250#define vsnprintf _vsnprintf
cristy38d73d62011-05-19 01:55:37 +0000251#endif
252#endif
253#if !defined(vsnprintf_l)
cristyaef5ccb2011-05-20 14:43:41 +0000254#define vsnprintf_l _vsnprintf_l
cristy3ed852e2009-09-05 21:47:34 +0000255#endif
256#if !defined(write)
257# define write _write
258#endif
259#if !defined(wstat) && !defined(__BORLANDC__)
cristy0157aea2010-04-24 21:12:18 +0000260#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(Windows95) && \
cristyad09dad2011-03-30 21:50:41 +0000261 !(defined(_MSC_VER) && (_MSC_VER < 1400)) && (__MSVCRT_VERSION__ < 0x800)
cristy3ed852e2009-09-05 21:47:34 +0000262# define wstat _wstati64
263#else
264# define wstat _wstat
265#endif
266#endif
267
cristy0157aea2010-04-24 21:12:18 +0000268#if defined(_MT) && defined(MAGICKCORE_WINDOWS_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000269# 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
cristy40e22a82011-09-08 13:47:19 +0000285#undef gettimeofday
286
cristy3ed852e2009-09-05 21:47:34 +0000287#if !defined(XS_VERSION)
288struct dirent
289{
290 char
291 d_name[2048];
292
293 int
294 d_namlen;
295};
296
297typedef 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
312typedef 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
cristy9acb8642010-04-24 17:12:04 +0000328#if !defined(__MINGW32__)
cristy6d71f8d2010-02-28 00:46:02 +0000329struct timezone
330{
331 int
332 tz_minuteswest,
333 tz_dsttime;
334};
cristy9acb8642010-04-24 17:12:04 +0000335#endif
cristy6d71f8d2010-02-28 00:46:02 +0000336
cristy3ed852e2009-09-05 21:47:34 +0000337typedef UINT
338 (CALLBACK *LPFNDLLFUNC1)(DWORD,UINT);
339
340typedef UINT
341 (CALLBACK *LPFNDLLFUNC2)(NTMEMORYSTATUSEX *);
342
343#endif
344
cristy3ed852e2009-09-05 21:47:34 +0000345#if defined(MAGICKCORE_BZLIB_DELEGATE)
346# if defined(_WIN32)
347# define BZ_IMPORT 1
348# endif
349#endif
350
351extern MagickExport char
cristy66f9c3c2011-08-13 17:12:28 +0000352 *NTGetLastError(void),
353 **NTArgvToUTF8(const int argc,wchar_t **);
cristy3ed852e2009-09-05 21:47:34 +0000354
cristydefb3f02009-09-10 02:18:35 +0000355extern MagickExport const GhostInfo
cristy3ed852e2009-09-05 21:47:34 +0000356 *NTGhostscriptDLLVectors(void);
357
358#if !defined(MAGICKCORE_LTDL_DELEGATE)
359extern MagickExport const char
360 *NTGetLibraryError(void);
361#endif
362
363#if !defined(XS_VERSION)
364extern MagickExport const char
365 *NTGetLibraryError(void);
366
367extern MagickExport DIR
368 *NTOpenDirectory(const char *);
369
370extern MagickExport double
371 NTElapsedTime(void),
372 NTUserTime(void);
373
374extern MagickExport int
375 Exit(int),
cristy2d97aa92011-09-08 00:05:29 +0000376#if !defined(__MINGW32__)
377 gettimeofday(struct timeval *,struct timezone *),
378#endif
cristy139c6842011-09-08 01:38:55 +0000379 IsWindows95(void),
cristy3ed852e2009-09-05 21:47:34 +0000380 NTCloseDirectory(DIR *),
381 NTCloseLibrary(void *),
382 NTControlHandler(void),
383 NTExitLibrary(void),
384 NTTruncateFile(int,off_t),
385 NTGhostscriptDLL(char *,int),
386 NTGhostscriptEXE(char *,int),
387 NTGhostscriptFonts(char *,int),
388 NTGhostscriptLoadDLL(void),
389 NTGhostscriptUnLoadDLL(void),
390 NTInitializeLibrary(void),
391 NTSetSearchPath(const char *),
392 NTSyncMemory(void *,size_t,int),
393 NTUnmapMemory(void *,size_t),
394 NTSystemCommand(const char *);
395
cristybb503372010-05-27 20:51:26 +0000396extern MagickExport ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000397 NTSystemConfiguration(int),
398 NTTellDirectory(DIR *);
399
400extern MagickExport MagickBooleanType
401 NTGatherRandomData(const size_t,unsigned char *),
402 NTGetExecutionPath(char *,const size_t),
403 NTGetModulePath(const char *,char *),
404 NTReportEvent(const char *,const MagickBooleanType),
405 NTReportException(const char *,const MagickBooleanType);
406
407extern MagickExport struct dirent
408 *NTReadDirectory(DIR *);
409
410extern MagickExport unsigned char
411 *NTRegistryKeyLookup(const char *),
412 *NTResourceToBlob(const char *);
413
414extern MagickExport void
415 NTErrorHandler(const ExceptionType,const char *,const char *),
416 *NTGetLibrarySymbol(void *,const char *),
417 *NTMapMemory(char *,size_t,int,int,int,MagickOffsetType),
418 *NTOpenLibrary(const char *),
cristybb503372010-05-27 20:51:26 +0000419 NTSeekDirectory(DIR *,ssize_t),
cristy3ed852e2009-09-05 21:47:34 +0000420 NTWarningHandler(const ExceptionType,const char *,const char *);
421
422#endif /* !XS_VERSION */
423
424#if defined(__cplusplus) || defined(c_plusplus)
425}
426#endif /* !C++ */
427
428#endif /* !_MAGICKCORE_NT_BASE_H */