CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

csutil/win32/csosdefs.h

00001 /*
00002     Copyright (C) 1998 by Jorrit Tyberghein
00003     Written by Andrew Zabolotny <bit@eltech.ru>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_CSOSDEFS_H__
00021 #define __CS_CSOSDEFS_H__
00022 
00023 #ifdef CS_BUILD_SHARED_LIBS
00024   #define CS_EXPORT_SYM __declspec(dllexport)
00025   #define CS_IMPORT_SYM __declspec(dllimport)
00026 #else
00027   #define CS_EXPORT_SYM
00028   #define CS_IMPORT_SYM
00029 #endif // CS_BUILD_SHARED_LIBS
00030 
00031 #if defined(COMP_VC)
00032   #pragma warning(disable:4097)   // use of xxx as synonym for a classname
00033   #pragma warning(disable:4099)   // type seen as both 'struct' and `class'
00034   #pragma warning(disable:4100)   // Use of void* as a formal function parameter
00035   #pragma warning(disable:4102)   // 'label' : unreferenced label
00036   #pragma warning(disable:4146)   // unary minus operator applied to unsigned type, result still unsigned
00037   #pragma warning(disable:4201)   // structure/ union without name. (Only relevant on MSVC 5.0)
00038   #pragma warning(disable:4244)   // conversion from 'double' to 'float'
00039   #pragma warning(disable:4251)   // class needs to have dll-interface to be used by clients
00040   #pragma warning(disable:4275)   // non-DLL-interface used as base for DLL-interface
00041   #pragma warning(disable:4291)   // no matching operator delete found
00042   #pragma warning(disable:4312)   // 'variable' : conversion from 'type' to 'type' of greater size
00043   #pragma warning(disable:4390)   // Empty control statement
00044   #pragma warning(disable:4505)   // 'function' : unreferenced local function has been removed
00045   #pragma warning(disable:4611)   // interaction between _setjmp and C++ destructors not portable
00046   #pragma warning(disable:4702)   // Unreachable Code
00047   #pragma warning(disable:4706)   // Assignment in conditional expression
00048   #pragma warning(disable:4710)   // function not inlined
00049   #pragma warning(disable:4711)   // function 'function' selected for inline expansion
00050   #pragma warning(disable:4786)   // identifier was truncated to '255' characters in the browser information (VC6)
00051   #pragma warning(disable:4800)   // Forcing value to bool
00052   #pragma warning(disable:4805)   // unsafe mix of bool and int.
00053 
00054 #if (_MSC_VER < 1300)
00055   #pragma warning(disable:4248)   // MSVC6 gives bogus "protected constructor"
00056                                   // for csHash::*Iterator, even though csHash
00057                                   // is friend.
00058   #pragma warning(disable:4503)   // 'identifier' : decorated name length exceeded, name was truncated
00059 #endif
00060 
00061   #pragma warning(default:4265)   // class has virtual functions, but destructor is not virtual
00062 
00063   #pragma inline_depth (255)
00064   #pragma inline_recursion (on)
00065   #pragma auto_inline (on)
00066 
00067   #pragma intrinsic (memset, memcpy, memcmp)
00068   #pragma intrinsic (strcpy, strcmp, strlen, strcat)
00069   #pragma intrinsic (abs, fabs)
00070 
00071   #if defined(__CRYSTAL_SPACE__) && !defined(CS_DEBUG)
00072     #pragma code_seg("CSpace")    // Just for fun :)
00073     // However, doing this in debug builds prevents Edit & Continue from
00074     // functioning properly :/
00075   #endif
00076 #endif
00077 
00078 #ifndef WINVER
00079 #define WINVER 0x0400
00080 #endif
00081 
00082 // Although MSVC6 generally supports templated functions within templated
00083 // classes, nevertheless it crashes and burns horribly when arguments to those
00084 // functions are function-pointers or functors.  In fact, such usage triggers a
00085 // slew of bugs, mostly "internal compiler error" but also several other
00086 // Worse, the bugs manifest in "random" locations throughout the project, often
00087 // in completely unrelated code.  Consequently, instruct csArray<> to avoid
00088 // such usage for MSVC6.
00089 #if defined(COMP_VC) && (_MSC_VER < 1300)
00090 #define CSARRAY_INHIBIT_TYPED_KEYS
00091 #endif
00092 
00093 // So many things require this. IF you have an issue with something defined
00094 // in it then undef that def here.
00095 
00096 #if defined(COMP_GCC)
00097 
00098 // From the w32api header files:
00099 
00100 #if defined(__i686__) && !defined(_M_IX86)
00101 #define _M_IX86 600
00102 #elif defined(__i586__) && !defined(_M_IX86)
00103 #define _M_IX86 500
00104 #elif defined(__i486__) && !defined(_M_IX86)
00105 #define _M_IX86 400
00106 #elif defined(__i386__) && !defined(_M_IX86)
00107 #define _M_IX86 300
00108 #endif
00109 #if defined(_M_IX86) && !defined(_X86_)
00110 #define _X86_
00111 #endif
00112 
00113 #ifdef __GNUC__
00114 #ifndef NONAMELESSUNION
00115 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) 
00116 #define _ANONYMOUS_UNION __extension__
00117 #define _ANONYMOUS_STRUCT __extension__
00118 #else
00119 #if defined(__cplusplus)
00120 #define _ANONYMOUS_UNION __extension__
00121 #endif /* __cplusplus */
00122 #endif /* __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) */
00123 #endif /* NONAMELESSUNION */
00124 #endif /* __GNUC__ */
00125 
00126 #ifndef _ANONYMOUS_UNION
00127 #define _ANONYMOUS_UNION
00128 #define _UNION_NAME(x) x
00129 #define DUMMYUNIONNAME  u
00130 #define DUMMYUNIONNAME2 u2
00131 #define DUMMYUNIONNAME3 u3
00132 #define DUMMYUNIONNAME4 u4
00133 #define DUMMYUNIONNAME5 u5
00134 #define DUMMYUNIONNAME6 u6
00135 #define DUMMYUNIONNAME7 u7
00136 #define DUMMYUNIONNAME8 u8
00137 #else
00138 #define _UNION_NAME(x)
00139 #define DUMMYUNIONNAME
00140 #define DUMMYUNIONNAME2
00141 #define DUMMYUNIONNAME3
00142 #define DUMMYUNIONNAME4
00143 #define DUMMYUNIONNAME5
00144 #define DUMMYUNIONNAME6
00145 #define DUMMYUNIONNAME7
00146 #define DUMMYUNIONNAME8
00147 #endif
00148 #ifndef _ANONYMOUS_STRUCT
00149 #define _ANONYMOUS_STRUCT
00150 #define _STRUCT_NAME(x) x
00151 #define DUMMYSTRUCTNAME s
00152 #define DUMMYSTRUCTNAME2 s2
00153 #define DUMMYSTRUCTNAME3 s3
00154 #else
00155 #define _STRUCT_NAME(x)
00156 #define DUMMYSTRUCTNAME
00157 #define DUMMYSTRUCTNAME2
00158 #define DUMMYSTRUCTNAME3
00159 #endif
00160 
00161 #else
00162 
00163 #if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_IX86)
00164 #define _X86_
00165 #endif
00166 
00167 #if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_AMD64)
00168 #define _AMD64_
00169 #endif
00170 
00171 #if !defined(_X86_) && !defined(_M_IX86) && !defined(_AMD64_) && defined(_M_IA64)
00172 #if !defined(_IA64_)
00173 #define _IA64_
00174 #endif 
00175 #endif
00176 
00177 #endif
00178 
00179 #ifndef __CYGWIN32__
00180 #include <excpt.h>
00181 #endif
00182 #include <stdarg.h>
00183 #include <windef.h>
00184 #include <winbase.h>
00185 #include <malloc.h>
00186 
00187 #ifndef WINGDIAPI
00188 #define WINGDIAPI DECLSPEC_IMPORT
00189 #endif
00190 
00191 #undef min
00192 #undef max
00193 #undef DeleteFile
00194 #undef Yield
00195 
00196 /*
00197   LONG_PTR is used in the Win32 canvases, but it's only defined in newer 
00198   Platform or DirectX SDKs (in BaseTsd.h).
00199   Ergo, on older SDKs, we have to define ourselves. One indicator for the
00200   presence of LONG_PTR seems to be if the __int3264 macro is #defines.
00201   So, if it's not, we define LONG_PTR.
00202  */
00203 #ifndef __int3264
00204   typedef LONG LONG_PTR;
00205 #endif
00206 
00207 #if defined(_DEBUG) || defined(CS_DEBUG)
00208   #include <assert.h>
00209   #define ASSERT(expression) assert(expression)
00210   #define VERIFY_SUCCESS(expression) assert(SUCCEEDED(expression))
00211   #define VERIFY_RESULT(expression, result) assert(expression == result)
00212   #ifndef CS_DEBUG
00213     #define CS_DEBUG
00214   #endif
00215 
00216   #undef  DEBUG_BREAK
00217   #define DEBUG_BREAK ::DebugBreak()
00218   
00219   #if defined(COMP_VC) 
00220     #include <crtdbg.h>
00221 
00222     #if defined(CS_EXTENSIVE_MEMDEBUG)
00223       #define malloc(size)      _malloc_dbg ((size), _NORMAL_BLOCK, __FILE__, __LINE__)
00224       #define free(ptr)                 _free_dbg ((ptr), _NORMAL_BLOCK)
00225       #define realloc(ptr, size)        _realloc_dbg ((ptr), (size), _NORMAL_BLOCK, __FILE__, __LINE__)
00226       #define calloc(num, size) _calloc_dbg ((num), (size), _NORMAL_BLOCK, __FILE__, __LINE__)
00227 
00228       // heap consistency check is on by default, leave it
00229       #define CS_WIN32_MSVC_DEBUG_GOOP \
00230         _CrtSetDbgFlag (_CrtSetDbgFlag (_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF)
00231     #else
00232       // turn heap consistency check off
00233       #define CS_WIN32_MSVC_DEBUG_GOOP \
00234         _CrtSetDbgFlag ((_CrtSetDbgFlag (_CRTDBG_REPORT_FLAG) & ~_CRTDBG_ALLOC_MEM_DF) | \
00235           _CRTDBG_LEAK_CHECK_DF)
00236     #endif
00237   #endif
00238 
00239 #else
00240   #define ASSERT(expression)
00241   #define VERIFY_SUCCESS(expression) expression
00242   #define VERIFY_RESULT(expression, result) expression
00243 #endif
00244 
00245 #ifdef CS_WIN32_MSVC_DEBUG_GOOP
00246   #define CS_INITIALIZE_PLATFORM_APPLICATION CS_WIN32_MSVC_DEBUG_GOOP
00247 #endif
00248 
00249 #ifdef CS_SYSDEF_PROVIDE_HARDWARE_MMIO
00250 
00251 // Defines that this platform supports hardware memory-mapped i/o
00252 #define CS_HAS_MEMORY_MAPPED_IO 1
00253 
00255 struct mmioInfo
00256 {
00258     HANDLE hMappedFile;
00259 
00261     HANDLE hFileMapping;
00262     
00264     bool close;
00265   
00267     unsigned char *data;
00268 
00270     unsigned int file_size;
00271 };
00272 
00273 #endif
00274 
00275 // The 2D graphics driver used by software renderer on this platform
00276 #define CS_SOFTWARE_2D_DRIVER "crystalspace.graphics2d.directdraw"
00277 #define CS_OPENGL_2D_DRIVER "crystalspace.graphics2d.glwin32"
00278 
00279 // The sound driver
00280 #define CS_SOUND_DRIVER "crystalspace.sound.driver.waveout"
00281 
00282 // SCF symbol export facility.
00283 #undef CS_EXPORTED_FUNCTION
00284 #define CS_EXPORTED_FUNCTION extern "C" __declspec(dllexport)
00285 
00286 #if defined (CS_SYSDEF_PROVIDE_DIR) || defined (CS_SYSDEF_PROVIDE_GETCWD) || defined (CS_SYSDEF_PROVIDE_MKDIR)
00287 #ifndef __CYGWIN32__
00288 #  include <direct.h>
00289 #endif
00290 #endif
00291 
00292 #if defined (COMP_BC)
00293 #  define strcasecmp stricmp
00294 #  define strncasecmp strnicmp
00295 #endif
00296 
00297 #if defined (COMP_VC)
00298 #  define strcasecmp _stricmp
00299 #  define strncasecmp _strnicmp
00300 #endif
00301 
00302 // Maximal path length
00303 #ifdef _MAX_FNAME
00304 #  define CS_MAXPATHLEN _MAX_FNAME
00305 #else
00306 #  define CS_MAXPATHLEN 260 /* not 256 */
00307 #endif
00308 #define PATH_SEPARATOR '\\'
00309 #define PATH_DELIMITER ';'
00310 
00311 #if defined (__CYGWIN32__) && defined(CS_SYSDEF_PROVIDE_MKDIR)
00312 #    define MKDIR(path) mkdir(path, 0755)
00313 #    undef CS_SYSDEF_PROVIDE_MKDIR
00314 #endif
00315 
00316 #ifdef CS_SYSDEF_VFS_PROVIDE_CHECK_VAR
00317   #define CS_PROVIDES_VFS_VARS 1
00318 #  ifdef CS_CSUTIL_LIB
00319   extern CS_EXPORT_SYM const char* csCheckPlatformVFSVar(const char* VarName);
00320 #  else
00321   extern CS_IMPORT_SYM const char* csCheckPlatformVFSVar(const char* VarName);
00322 #  endif // CS_CSUTIL_LIB
00323 #endif
00324 
00325 #ifdef CS_SYSDEF_PROVIDE_EXPAND_PATH
00326   #define CS_PROVIDES_EXPAND_PATH 1
00327 
00328   inline void
00329   csPlatformExpandPath(const char* path, char* buffer, int bufsize)
00330   {
00331     GetFullPathName (path, bufsize, buffer, 0);
00332   }
00333 
00334 #endif
00335 
00336 // Although COMP_GCC has opendir, readdir, CS' versions are preferred.
00337 #if defined(CS_SYSDEF_PROVIDE_DIR)
00338 // Directory read functions
00339   #define __NEED_OPENDIR_PROTOTYPE
00340   #include <io.h>
00341 
00342   // Directory entry
00343   struct dirent
00344   {
00345     char d_name [CS_MAXPATHLEN + 1]; // File name, 0 terminated
00346     size_t d_size; // File size (bytes)
00347     long dwFileAttributes; // File attributes (Windows-specific)
00348   };
00349   // Directory handle
00350   struct DIR;
00351 
00352 # ifdef CS_CSUTIL_LIB
00353   extern "C" CS_EXPORT_SYM DIR *opendir (const char *name);
00354   extern "C" CS_EXPORT_SYM dirent *readdir (DIR *dirp);
00355   extern "C" CS_EXPORT_SYM int closedir (DIR *dirp);
00356   extern "C" CS_EXPORT_SYM bool isdir (const char *path, dirent *de);
00357 # else
00358   extern "C" CS_IMPORT_SYM DIR *opendir (const char *name);
00359   extern "C" CS_IMPORT_SYM dirent *readdir (DIR *dirp);
00360   extern "C" CS_IMPORT_SYM int closedir (DIR *dirp);
00361   extern "C" CS_IMPORT_SYM bool isdir (const char *path, dirent *de);
00362 # endif // CS_BUILD_SHARED_LIBS
00363 #endif
00364 
00365 #ifdef CS_SYSDEF_PROVIDE_SOCKETS
00366 #include <winsock.h>
00367 #ifndef socklen_t
00368    typedef int socklen_t;
00369 #endif
00370    typedef SOCKET csNetworkSocket;
00371 #  define CS_NET_SOCKET_INVALID INVALID_SOCKET
00372 #  define CS_IOCTLSOCKET ioctlsocket
00373 #  define CS_CLOSESOCKET closesocket
00374 #  define EWOULDBLOCK WSAEWOULDBLOCK
00375 #  define CS_GETSOCKETERROR ::WSAGetLastError()
00376 #  undef CS_SYSDEF_PROVIDE_SOCKETS
00377 #endif
00378 
00379 #ifdef CS_SYSDEF_PROVIDE_SELECT
00380 #  undef CS_SYSDEF_PROVIDE_SELECT
00381 #endif
00382 
00383 #ifdef CS_SYSDEF_PROVIDE_ACCESS
00384 #  include <io.h>
00385 #endif
00386 
00387 #if defined (COMP_BC) || defined (__CYGWIN32__)
00388 #  define GETPID() getpid()
00389 #else
00390 #  define GETPID() _getpid()
00391 #endif
00392 
00393 #ifdef CS_SYSDEF_PROVIDE_TEMP
00394 # ifdef __CYGWIN32__
00395 #   include <unistd.h>
00396 #   define TEMP_FILE "cs%lu.tmp", (unsigned long)getpid()
00397 #   define TEMP_DIR  "/tmp"
00398 # else
00399 #   include <process.h>
00400 #   define TEMP_FILE "%x.cs", GETPID()
00401 #   define TEMP_DIR win32_tempdir()
00402    // This is the function called by TEMP_DIR macro
00403    static inline char *win32_tempdir()
00404    {
00405      char *tmp;
00406      if ((tmp = getenv ("TMP")) != 0)
00407        return tmp;
00408      if ((tmp = getenv ("TEMP")) != 0)
00409        return tmp;
00410      return "";
00411    }
00412 # endif
00413 #endif // CS_SYSDEF_PROVIDE_TEMP
00414 
00415 // Microsoft Visual C++ compiler includes a very in-efficient 'memcpy'.
00416 // This also replaces the older 'better_memcpy', which was also not as
00417 // efficient as it could be ergo... heres a better solution.
00418 #if defined(COMP_VC) && (_MSC_VER < 1300)
00419 #include <memory.h>
00420 #define memcpy fast_mem_copy
00421 static inline void* fast_mem_copy (void *dest, const void *src, int count)
00422 {
00423     __asm
00424     {
00425       mov               eax, count
00426       mov               esi, src
00427       mov               edi, dest
00428       xor               ecx, ecx
00429 
00430       // Check for 'short' moves
00431       cmp               eax, 16
00432       jl                do_short
00433                 
00434       // Move enough bytes to align 'dest'
00435       sub               ecx, edi
00436       and               ecx, 3
00437       je                skip
00438       sub               eax, ecx
00439       rep               movsb
00440 
00441       skip:
00442         mov             ecx, eax
00443         and             eax, 3
00444         shr             ecx, 2
00445         rep             movsd
00446         test    eax, eax
00447         je              end
00448 
00449       do_short:
00450         mov             ecx, eax
00451         rep             movsb
00452 
00453       end:
00454     }
00455 
00456     return dest;
00457 }
00458 #endif
00459 
00460 #ifdef COMP_BC
00461 // Major hack due to pow failures in CS for Borland, removing this
00462 // causes millions of strings to print out -- Brandon Ehle
00463 #define pow(arga, argb) ( (!arga && !argb)?0:pow(arga, argb) )
00464 // Dunno why this is in CS -- Brandon Ehle
00465 #define DEBUG_BREAK
00466 #endif
00467 
00468 #if defined (PROC_X86)
00469 #  define CS_LITTLE_ENDIAN
00470 #else
00471 #  error "Please define a suitable CS_XXX_ENDIAN macro in win32/csosdefs.h!"
00472 #endif
00473 
00474 #if defined(COMP_BC)
00475   // The Borland C++ compiler does not accept a 'main' routine
00476   // in a program which already contains WinMain. This is a work-around.
00477   #undef main
00478   #define main csMain
00479 #endif
00480 
00481 // cygwin has no _beginthread and _endthread functions
00482 #ifdef __CYGWIN32__
00483 #ifndef _beginthread
00484 #define _beginthread(func, stack, ptr)  CreateThread (0, 0, \
00485           LPTHREAD_START_ROUTINE(func), ptr, CREATE_SUSPENDED, 0)
00486 #endif
00487 #ifndef _endthread
00488 #define _endthread()  {}
00489 #endif
00490 #endif
00491 
00492 // just to avoid windows.h inclusion
00493 #define csSW_SHOWNORMAL 1
00494 
00495 #if defined(COMP_BC)
00496   #define CS_WIN32_ARGC _argc
00497   #define CS_WIN32_ARGV _argv
00498 #else
00499   #define CS_WIN32_ARGC __argc
00500   #define CS_WIN32_ARGV __argv
00501 #endif
00502 
00503 #ifdef __CYGWIN32__
00504 #if !defined(CS_IMPLEMENT_PLATFORM_APPLICATION)
00505 #define CS_IMPLEMENT_PLATFORM_APPLICATION
00506 #endif
00507 
00508 #else // __CYGWIN32__
00509 
00510 /*
00511  if the EXE is compiled as a GUI app,
00512  a WinMain is needed. But if compiled
00513  as a console app it's not used but main() is
00514  instead. 
00515  */
00516 
00517 #if !defined(CS_IMPLEMENT_PLATFORM_APPLICATION)
00518 #define CS_IMPLEMENT_PLATFORM_APPLICATION                              \
00519 int main (int argc, char* argv[]);                                     \
00520 int WINAPI WinMain (HINSTANCE hApp, HINSTANCE prev, LPSTR cmd, int show)\
00521 {                                                                      \
00522   (void)hApp;                                                          \
00523   (void)show;                                                          \
00524   (void)prev;                                                          \
00525   (void)cmd;                                                           \
00526   int ret = main(CS_WIN32_ARGC, CS_WIN32_ARGV);                        \
00527   return ret;                                                          \
00528 }
00529 #endif // CS_IMPLEMENT_PLATFORM_APPLICATION
00530 
00531 #endif // __CYGWIN32__
00532 
00533 #if !defined(CS_STATIC_LINKED)
00534 
00535 #if !defined(CS_IMPLEMENT_PLATFORM_PLUGIN)
00536 #define CS_IMPLEMENT_PLATFORM_PLUGIN                                   \
00537 int _cs_main(int argc, char* argv[])                                   \
00538 {                                                                      \
00539          return 0;                                                     \
00540 }                                                                      \
00541 extern "C" BOOL WINAPI                                                 \
00542 DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID /*lpvReserved*/)  \
00543 {                                                                      \
00544           return TRUE;                                                 \
00545 }                                                                      \
00546 CS_EXPORTED_FUNCTION const char* plugin_compiler()                     \
00547 {                                                                      \
00548          return CS_COMPILER_NAME;                                      \
00549 }
00550 #endif // CS_IMPLEMENT_PLATFORM_PLUGIN
00551 
00552 #endif // CS_STATIC_LINKED
00553 
00554 #endif // __CS_CSOSDEFS_H__

Generated for Crystal Space by doxygen 1.2.18