# nt-base.h

Go to the documentation of this file.

    00001 /*
    00002   Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization
    00003   dedicated to making software imaging solutions freely available.
    00004
    00005   You may not use this file except in compliance with the License.
    00006   obtain a copy of the License at
    00007
    00008     http://www.wizards-toolkit.org/script/license.php
    00009
    00010   Unless required by applicable law or agreed to in writing, software
    00011   distributed under the License is distributed on an "AS IS" BASIS,
    00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00013   See the License for the specific language governing permissions and
    00014   limitations under the License.
    00015
    00016   Windows NT utility methods for the Wizard's Toolkit.
    00017 */
    00018 #ifndef _WIZARDS_TOOLKIT_NTBASE_H
    00019 #define _WIZARDS_TOOLKIT_NTBASE_H
    00020
    00021 #if defined(__cplusplus) || defined(c_plusplus)
    00022 extern "C" {
    00023 #endif
    00024
    00025 #define WIN32_LEAN_AND_MEAN
    00026 #define VC_EXTRALEAN
    00027 #include <windows.h>
    00028 #include <winuser.h>
    00029 #include <wingdi.h>
    00030 #include <NTSecAPI.h>
    00031 #include <io.h>
    00032 #include <process.h>
    00033 #include <errno.h>
    00034 #if defined(_DEBUG)
    00035 #include <crtdbg.h>
    00036 #endif
    00037
    00038 #include <stdarg.h>
    00039 #include "wizard/exception.h"
    00040
    00041 #define PROT_READ  0x01
    00042 #define PROT_WRITE  0x02
    00043 #define MAP_SHARED  0x01
    00044 #define MAP_PRIVATE  0x02
    00045 #define MAP_ANONYMOUS  0x20
    00046 #define F_OK 0
    00047 #define R_OK 4
    00048 #define W_OK 2
    00049 #define RW_OK 6
    00050 #define _SC_PAGESIZE 1
    00051 #define _SC_PHYS_PAGES 2
    00052 #define _SC_OPEN_MAX 3
    00053 #if !defined(SSIZE_MAX)
    00054 #define SSIZE_MAX  0x7fffffffL
    00055 #endif
    00056
    00057 #if !defined(chsize)
    00058 # if defined(__BORLANDC__)
    00059 #   define chsize(file,length)  chsize(file,length)
    00060 # else
    00061 #   define chsize(file,length)  _chsize(file,length)
    00062 # endif
    00063 #endif
    00064
    00065 #if !defined(access)
    00066 #  define access(path,mode)  _access(path,mode)
    00067 #endif
    00068 #if !defined(chdir)
    00069 #  define chdir  _chdir
    00070 #endif
    00071 #if !defined(close)
    00072 #  define close  _close
    00073 #endif
    00074 #if !defined(closedir)
    00075 #  define closedir(directory)  NTCloseDirectory(directory)
    00076 #endif
    00077 #if !defined(fdopen)
    00078 #  define fdopen  _fdopen
    00079 #endif
    00080 #if !defined(fileno)
    00081 #  define fileno  _fileno
    00082 #endif
    00083 #if !defined(ftruncate)
    00084 #  define ftruncate(file,length)  NTFileTruncate(file,length)
    00085 #endif
    00086 #if !defined(getcwd)
    00087 #  define getcwd  _getcwd
    00088 #endif
    00089 #if !defined(getpid)
    00090 #  define getpid  _getpid
    00091 #endif
    00092 #if !defined(isatty)
    00093 #  define isatty _isatty
    00094 #endif
    00095 #if !defined(lt_dlclose)
    00096 #  define lt_dlclose(handle)  NTCloseLibrary(handle)
    00097 #endif
    00098 #if !defined(lt_dlerror)
    00099 #  define lt_dlerror()  NTGetLibraryError()
    00100 #endif
    00101 #if !defined(lt_dlexit)
    00102 #  define lt_dlexit()  NTExitLibrary()
    00103 #endif
    00104 #if !defined(lt_dlinit)
    00105 #  define lt_dlinit()  NTInitializeLibrary()
    00106 #endif
    00107 #if !defined(lt_dlopen)
    00108 #  define lt_dlopen(filename)  NTOpenLibrary(filename)
    00109 #endif
    00110 #if !defined(lt_dlsetsearchpath)
    00111 #  define lt_dlsetsearchpath(path)  NTSetSearchPath(path)
    00112 #endif
    00113 #if !defined(lt_dlsym)
    00114 #  define lt_dlsym(handle,name)  NTGetLibrarySymbol(handle,name)
    00115 #endif
    00116 #if !defined(mkdir)
    00117 #  define mkdir  _mkdir
    00118 #endif
    00119 #if !defined(mmap)
    00120 #  define mmap(address,length,protection,access,file,offset) \
    00121   NTMapMemory(address,length,protection,access,file,offset)
    00122 #endif
    00123 #if !defined(msync)
    00124 #  define msync(address,length,flags)  NTSyncMemory(address,length,flags)
    00125 #endif
    00126 #if !defined(munmap)
    00127 #  define munmap(address,length)  NTUnmapMemory(address,length)
    00128 #endif
    00129 #if !defined(opendir)
    00130 #  define opendir(directory)  NTOpenDirectory(directory)
    00131 #endif
    00132 #if !defined(open)
    00133 #  define open  _open
    00134 #endif
    00135 #if !defined(pclose)
    00136 #  define pclose  _pclose
    00137 #endif
    00138 #if !defined(popen)
    00139 #  define popen  _popen
    00140 #endif
    00141 #if !defined(read)
    00142 #  define read  _read
    00143 #endif
    00144 #if !defined(readdir)
    00145 #  define readdir(directory)  NTReadDirectory(directory)
    00146 #endif
    00147 #if !defined(seekdir)
    00148 #  define seekdir(directory,offset)  NTSeekDirectory(directory,offset)
    00149 #endif
    00150 #if !defined(setmode)
    00151 #  define setmode  _setmode
    00152 #endif
    00153 #if !defined(strcasecmp)
    00154 #  define strcasecmp  _strcmpi
    00155 #endif
    00156 #if !defined(strncasecmp)
    00157 #  define strncasecmp  _strnicmp
    00158 #endif
    00159 #if !defined(sysconf)
    00160 #  define sysconf(name)  NTSystemConfiguration(name)
    00161 #endif
    00162 #if !defined(telldir)
    00163 #  define telldir(directory)  NTTellDirectory(directory)
    00164 #endif
    00165 #if !defined(tempnam)
    00166 #  define tempnam  _tempnam
    00167 #endif
    00168 #if !defined(unlink)
    00169 #  define unlink  _unlink
    00170 #endif
    00171 #if !defined(vsnprintf)
    00172 #  define vsnprintf  _vsnprintf
    00173 #endif
    00174 #if !defined(write)
    00175 #  define write  _write
    00176 #endif
    00177
    00178 #if defined(_MT) && defined(__WINDOWS__)
    00179 #  define SAFE_GLOBAL  __declspec(thread)
    00180 #else
    00181 #  define SAFE_GLOBAL
    00182 #endif
    00183
    00184 #if defined(__BORLANDC__)
    00185 #undef _O_RANDOM
    00186 #define _O_RANDOM 0
    00187 #undef _O_SEQUENTIAL
    00188 #define _O_SEQUENTIAL 0
    00189 #undef _O_SHORT_LIVED
    00190 #define _O_SHORT_LIVED 0
    00191 #undef _O_TEMPORARY
    00192 #define _O_TEMPORARY 0
    00193 #endif
    00194
    00195 #if !defined(XS_VERSION)
    00196 struct dirent
    00197 {
    00198   char
    00199     d_name[2048];
    00200
    00201   int
    00202     d_namlen;
    00203 };
    00204
    00205 typedef struct _DIR
    00206 {
    00207   HANDLE
    00208     hSearch;
    00209
    00210   WIN32_FIND_DATA
    00211     Win32FindData;
    00212
    00213   BOOL
    00214     firsttime;
    00215
    00216   struct dirent
    00217     file_info;
    00218 } DIR;
    00219
    00220 typedef struct _NTMEMORYSTATUSEX
    00221 {
    00222   DWORD
    00223     dwLength,
    00224     dwMemoryLoad;
    00225
    00226   DWORDLONG
    00227     ullTotalPhys,
    00228     ullAvailPhys,
    00229     ullTotalPageFile,
    00230     ullAvailPageFile,
    00231     ullTotalVirtual,
    00232     ullAvailVirtual,
    00233     ullAvailExtendedVirtual;
    00234 } NTMEMORYSTATUSEX;
    00235
    00236 typedef UINT
    00237   (CALLBACK *LPFNDLLFUNC1)(DWORD,UINT);
    00238
    00239 typedef UINT
    00240   (CALLBACK *LPFNDLLFUNC2)(NTMEMORYSTATUSEX *);
    00241
    00242 #endif
    00243
    00244 #if !defined(ssize_t) && !defined(__MINGW32__)
    00245 typedef long ssize_t;
    00246 #endif
    00247
    00248 extern WizardExport char
    00249   *NTGetLastError(void);
    00250
    00251 #if !defined(WIZARDSTOOLKIT_LTDL_DELEGATE)
    00252 extern WizardExport const char
    00253   *NTGetLibraryError(void);
    00254 #endif
    00255
    00256 #if !defined(XS_VERSION)
    00257 extern WizardExport char
    00258   *NTRegistryKeyLookup(const char *);
    00259
    00260 extern WizardExport DIR
    00261   *NTOpenDirectory(const char *);
    00262
    00263 extern WizardExport double
    00264   NTElapsedTime(void),
    00265   NTUserTime(void);
    00266
    00267 extern WizardExport int
    00268   Exit(int),
    00269   IsWindows95(),
    00270   NTCloseDirectory(DIR *),
    00271   NTCloseLibrary(void *),
    00272   NTControlHandler(void),
    00273   NTExitLibrary(void),
    00274   NTInitializeLibrary(void),
    00275   NTSetSearchPath(const char *),
    00276   NTSyncMemory(void *,size_t,int),
    00277   NTUnmapMemory(void *,size_t),
    00278   NTSystemCommand(const char *);
    00279
    00280 extern WizardExport long
    00281   NTSystemConfiguration(int),
    00282   NTTellDirectory(DIR *);
    00283
    00284 extern WizardExport WizardBooleanType
    00285   NTGetExecutionPath(char *,const size_t),
    00286   NTGetModulePath(const char *,char *),
    00287   NTGatherRandomData(const size_t,unsigned char *),
    00288   NTReportEvent(const char *,const WizardBooleanType),
    00289   NTReportException(const char *,const WizardBooleanType);
    00290
    00291 extern WizardExport struct dirent
    00292   *NTReadDirectory(DIR *);
    00293
    00294 extern WizardExport unsigned char
    00295   *NTResourceToBlob(const char *);
    00296
    00297 extern WizardExport void
    00298   NTErrorHandler(const ExceptionType,const char *,const char *),
    00299   *NTGetLibrarySymbol(void *,const char *),
    00300   *NTMapMemory(char *,size_t,int,int,int,WizardOffsetType),
    00301   *NTOpenLibrary(const char *),
    00302   NTSeekDirectory(DIR *,long),
    00303   NTWarningHandler(const ExceptionType,const char *,const char *);
    00304
    00305 #endif /* !XS_VERSION */
    00306
    00307 #if defined(__cplusplus) || defined(c_plusplus)
    00308 }
    00309 #endif /* !C++ */
    00310
    00311 #endif /* !_WIZARDS_TOOLKIT_NTBASE_H */