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 #define CS_EXPORT_SYM_DLL __declspec(dllexport) 00024 #define CS_IMPORT_SYM_DLL __declspec(dllimport) 00025 00026 #ifdef CS_BUILD_SHARED_LIBS 00027 #define CS_EXPORT_SYM CS_EXPORT_SYM_DLL 00028 #define CS_IMPORT_SYM CS_IMPORT_SYM_DLL 00029 #else 00030 #define CS_EXPORT_SYM 00031 #define CS_IMPORT_SYM 00032 #endif // CS_BUILD_SHARED_LIBS 00033 00034 #if defined(CS_COMPILER_MSVC) 00035 #pragma warning(disable:4244) // conversion from 'double' to 'float' 00036 #pragma warning(disable:4250) // '...' inherits '..' via dominance 00037 #pragma warning(disable:4251) /* 'identifier' : class 'type' needs to have 00038 * dll-interface to be used by clients of 00039 * class 'type2' */ 00040 #pragma warning(disable:4275) /* non – DLL-interface class 'identifier' 00041 * used as base for DLL-interface class 00042 * 'identifier' */ 00043 #pragma warning(disable:4290) // C++ exception specification ignored 00044 #pragma warning(disable:4312) /* 'variable' : conversion from 'type' to 00045 * 'type' of greater size */ 00046 #pragma warning(disable:4345) /* VC7.1: an object of POD type constructed 00047 * with an initializer of the form () will 00048 * be default-initialized */ 00049 #pragma warning(disable:4355) // 'this' used in base member initializer list 00050 00051 00052 #pragma inline_depth (255) 00053 #pragma inline_recursion (on) 00054 #pragma auto_inline (on) 00055 00056 #define CS_FORCEINLINE __forceinline 00057 00058 #pragma intrinsic (memset, memcpy, memcmp) 00059 #pragma intrinsic (strcpy, strcmp, strlen, strcat) 00060 #pragma intrinsic (abs, fabs) 00061 #pragma intrinsic (_byteswap_ushort, _byteswap_ulong, _byteswap_uint64) 00062 00063 #if _MSC_VER >= 1400 00064 /* Work around an apparent incompatibility between VC8's intrin.h and 00065 * the Windows SDK 6.0's winnt.h - _interlockedbittestandset and 00066 * _interlockedbittestandreset have slightly different prototypes. 00067 * Go Microsoft! 00068 */ 00069 #define _interlockedbittestandset workaround_header_bug_1 00070 #define _interlockedbittestandreset workaround_header_bug_2 00071 #include <intrin.h> 00072 #undef _interlockedbittestandset 00073 #undef _interlockedbittestandreset 00074 #else 00075 extern "C" long _InterlockedCompareExchange (long volatile *, long, long); 00076 extern "C" long _InterlockedDecrement (long volatile *); 00077 extern "C" long _InterlockedExchange (long volatile *, long); 00078 extern "C" long _InterlockedIncrement (long volatile *); 00079 00080 extern "C" unsigned char _BitScanForward (unsigned long* Index, unsigned long Mask); 00081 extern "C" unsigned char _BitScanReverse (unsigned long* Index, unsigned long Mask); 00082 #endif 00083 #pragma intrinsic (_InterlockedCompareExchange) 00084 #pragma intrinsic (_InterlockedDecrement) 00085 #pragma intrinsic (_InterlockedExchange) 00086 #pragma intrinsic (_InterlockedIncrement) 00087 #pragma intrinsic (_BitScanForward) 00088 #pragma intrinsic (_BitScanReverse) 00089 00090 #define CS_HAVE_BITSCAN_INTRINSICS 00091 00092 #if defined(__CRYSTAL_SPACE__) && !defined(CS_DEBUG) 00093 #pragma code_seg("CSpace") // Just for fun :) 00094 // However, doing this in debug builds prevents Edit & Continue from 00095 // functioning properly :/ 00096 #endif 00097 00098 // VC8 quirks 00099 #if (_MSC_VER >= 1400) 00100 // Also note quirk in csconfig.h 00101 00102 // Nothing else atm. 00103 #endif 00104 #endif 00105 00106 #ifndef WINVER 00107 #define WINVER 0x0500 00108 #endif 00109 00110 #ifndef _WIN32_WINNT 00111 #define _WIN32_WINNT 0x0500 00112 #endif 00113 00114 00115 // So many things require this. IF you have an issue with something defined 00116 // in it then undef that def here. 00117 00118 #if defined(CS_COMPILER_GCC) 00119 00120 // From the w32api header files: 00121 00122 #if defined(__i686__) && !defined(_M_IX86) 00123 #define _M_IX86 600 00124 #elif defined(__i586__) && !defined(_M_IX86) 00125 #define _M_IX86 500 00126 #elif defined(__i486__) && !defined(_M_IX86) 00127 #define _M_IX86 400 00128 #elif defined(__i386__) && !defined(_M_IX86) 00129 #define _M_IX86 300 00130 #endif 00131 #if defined(_M_IX86) && !defined(_X86_) 00132 #define _X86_ 00133 #endif 00134 00135 #ifdef __GNUC__ 00136 #ifndef NONAMELESSUNION 00137 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) 00138 #define _ANONYMOUS_UNION __extension__ 00139 #define _ANONYMOUS_STRUCT __extension__ 00140 #else 00141 #if defined(__cplusplus) 00142 #define _ANONYMOUS_UNION __extension__ 00143 #endif /* __cplusplus */ 00144 #endif /* __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) */ 00145 #endif /* NONAMELESSUNION */ 00146 #endif /* __GNUC__ */ 00147 00148 #ifndef _ANONYMOUS_UNION 00149 #define _ANONYMOUS_UNION 00150 #define _UNION_NAME(x) x 00151 #define DUMMYUNIONNAME u 00152 #define DUMMYUNIONNAME2 u2 00153 #define DUMMYUNIONNAME3 u3 00154 #define DUMMYUNIONNAME4 u4 00155 #define DUMMYUNIONNAME5 u5 00156 #define DUMMYUNIONNAME6 u6 00157 #define DUMMYUNIONNAME7 u7 00158 #define DUMMYUNIONNAME8 u8 00159 #else 00160 #define _UNION_NAME(x) 00161 #define DUMMYUNIONNAME 00162 #define DUMMYUNIONNAME2 00163 #define DUMMYUNIONNAME3 00164 #define DUMMYUNIONNAME4 00165 #define DUMMYUNIONNAME5 00166 #define DUMMYUNIONNAME6 00167 #define DUMMYUNIONNAME7 00168 #define DUMMYUNIONNAME8 00169 #endif 00170 #ifndef _ANONYMOUS_STRUCT 00171 #define _ANONYMOUS_STRUCT 00172 #define _STRUCT_NAME(x) x 00173 #define DUMMYSTRUCTNAME s 00174 #define DUMMYSTRUCTNAME2 s2 00175 #define DUMMYSTRUCTNAME3 s3 00176 #else 00177 #define _STRUCT_NAME(x) 00178 #define DUMMYSTRUCTNAME 00179 #define DUMMYSTRUCTNAME2 00180 #define DUMMYSTRUCTNAME3 00181 #endif 00182 00183 #else 00184 00185 #if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && \ 00186 defined(_M_IX86) 00187 #define _X86_ 00188 #endif 00189 00190 #if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && \ 00191 defined(_M_AMD64) 00192 #define _AMD64_ 00193 #endif 00194 00195 #if !defined(_X86_) && !defined(_M_IX86) && !defined(_AMD64_) && \ 00196 defined(_M_IA64) && !defined(_IA64_) 00197 #define _IA64_ 00198 #endif 00199 00200 #endif 00201 00202 #ifndef __CYGWIN32__ 00203 #include <excpt.h> 00204 #endif 00205 #include <stdarg.h> 00206 #include <windef.h> 00207 #include <winbase.h> 00208 #include <winreg.h> 00209 #include <malloc.h> 00210 #include <sys/types.h> 00211 #include <sys/stat.h> 00212 #ifdef CS_HAVE_SYS_PARAM_H 00213 #include <sys/param.h> 00214 #endif 00215 #ifndef __CYGWIN32__ 00216 #include <direct.h> 00217 #endif 00218 00219 00220 #ifndef WINGDIAPI 00221 #define WINGDIAPI DECLSPEC_IMPORT 00222 #endif 00223 00224 /* 00225 LONG_PTR is used in the Win32 canvases, but it's only defined in newer 00226 Platform or DirectX SDKs (in BaseTsd.h). 00227 Ergo, on older SDKs, we have to define it ourselves. One indicator for the 00228 presence of LONG_PTR seems to be if the __int3264 macro is #defined. 00229 So, if it's not, we define LONG_PTR. 00230 */ 00231 #ifndef __int3264 00232 typedef LONG LONG_PTR; 00233 typedef ULONG ULONG_PTR; 00234 typedef DWORD DWORD_PTR; 00235 #endif 00236 00237 #if defined(_DEBUG) || defined(CS_DEBUG) 00238 #include <assert.h> 00239 #ifndef CS_DEBUG 00240 #define CS_DEBUG 00241 #endif 00242 00243 #if defined(CS_COMPILER_MSVC) 00244 #include <crtdbg.h> 00245 00246 #if defined(CS_EXTENSIVE_MEMDEBUG) 00247 #define malloc(size) \ 00248 _malloc_dbg ((size), _NORMAL_BLOCK, __FILE__, __LINE__) 00249 #define free(ptr) _free_dbg ((ptr), _NORMAL_BLOCK) 00250 #define realloc(ptr, size) \ 00251 _realloc_dbg ((ptr), (size), _NORMAL_BLOCK, __FILE__, __LINE__) 00252 #define calloc(num, size) \ 00253 _calloc_dbg ((num), (size), _NORMAL_BLOCK, __FILE__, __LINE__) 00254 00255 // heap consistency check is on by default, leave it 00256 #define CS_WIN32_MSVC_DEBUG_GOOP \ 00257 _CrtSetDbgFlag ( \ 00258 _CrtSetDbgFlag (_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF) 00259 #else 00260 // turn heap consistency check off 00261 #define CS_WIN32_MSVC_DEBUG_GOOP \ 00262 _CrtSetDbgFlag ( \ 00263 (_CrtSetDbgFlag (_CRTDBG_REPORT_FLAG) & ~_CRTDBG_ALLOC_MEM_DF) | \ 00264 _CRTDBG_LEAK_CHECK_DF) 00265 #endif 00266 #endif 00267 00268 #endif 00269 00270 #ifdef CS_WIN32_MSVC_DEBUG_GOOP 00271 #define CS_INITIALIZE_PLATFORM_APPLICATION CS_WIN32_MSVC_DEBUG_GOOP 00272 #endif 00273 00274 // The 2D graphics driver used by software renderer on this platform 00275 #define CS_SOFTWARE_2D_DRIVER "crystalspace.graphics2d.directdraw" 00276 #define CS_OPENGL_2D_DRIVER "crystalspace.graphics2d.glwin32" 00277 00278 // The sound driver 00279 #define CS_SOUND_DRIVER "crystalspace.sound.driver.waveout" 00280 #define CS_SNDSYS_DRIVER "crystalspace.sndsys.software.driver.directsound" 00281 00282 // SCF symbol export facility. 00283 #ifndef CS_STATIC_LINKED 00284 // No need to export the symbols when statically linking into one big binary. 00285 # undef CS_EXPORTED_FUNCTION 00286 # define CS_EXPORTED_FUNCTION extern "C" __declspec(dllexport) 00287 #endif 00288 00289 #if defined (CS_COMPILER_BCC) 00290 # define strcasecmp stricmp 00291 # define strncasecmp strnicmp 00292 #endif 00293 00294 #if defined (CS_COMPILER_MSVC) 00295 # define strcasecmp _stricmp 00296 # define strncasecmp _strnicmp 00297 # define snprintf _snprintf 00298 #endif 00299 00300 #if defined (CS_COMPILER_MSVC) 00301 # if defined(_MSC_VER) && (_MSC_VER < 1300) 00302 # include <assert.h> 00303 static inline longlong strtoll(char const* s, char** sN, int base) 00304 { 00305 assert(sN == 0); 00306 assert(base == 10); 00307 return _atoi64(s); 00308 } 00309 # else 00310 # define strtoll _strtoi64 00311 # endif 00312 #endif 00313 00314 // Maximal path length 00315 #ifndef CS_MAXPATHLEN 00316 # ifdef _MAX_FNAME 00317 # define CS_MAXPATHLEN _MAX_FNAME 00318 # else 00319 # define CS_MAXPATHLEN 260 /* not 256 */ 00320 # endif 00321 #endif 00322 #define CS_PATH_DELIMITER ';' 00323 #define CS_PATH_SEPARATOR '\\' 00324 00325 #if defined (__CYGWIN32__) 00326 # define CS_MKDIR(path) mkdir(path, 0755) 00327 #else 00328 # define CS_MKDIR(path) _mkdir(path) 00329 #endif 00330 00331 // Directory read functions, file access, etc. 00332 #include <io.h> 00333 #ifndef F_OK 00334 # define F_OK 0 00335 #endif 00336 #ifndef R_OK 00337 # define R_OK 2 00338 #endif 00339 #ifndef W_OK 00340 # define W_OK 4 00341 #endif 00342 00343 #define CS_PROVIDES_EXPAND_PATH 1 00344 inline void csPlatformExpandPath(const char* /*path*/, char* /*buffer*/, 00345 int /*nbuf*/) {} 00346 00347 // Although CS_COMPILER_GCC has opendir(), readdir(), etc., we prefer the CS 00348 // versions of these functions. 00349 #define CS_WIN32_USE_CUSTOM_OPENDIR 00350 00351 #ifndef CS_WIN32_USE_CUSTOM_OPENDIR 00352 # include <dirent.h> 00353 #else 00354 struct dirent 00355 { 00356 char d_name [CS_MAXPATHLEN + 1]; // File name, 0 terminated 00357 size_t d_size; // File size (bytes) 00358 long dwFileAttributes; // File attributes (Windows-specific) 00359 }; 00360 00361 struct DIR; 00362 # ifdef CS_CRYSTALSPACE_LIB 00363 extern "C" CS_EXPORT_SYM DIR *opendir (const char *name); 00364 extern "C" CS_EXPORT_SYM dirent *readdir (DIR *dirp); 00365 extern "C" CS_EXPORT_SYM int closedir (DIR *dirp); 00366 extern "C" CS_EXPORT_SYM bool isdir (const char *path, dirent *de); 00367 # else 00368 extern "C" CS_IMPORT_SYM DIR *opendir (const char *name); 00369 extern "C" CS_IMPORT_SYM dirent *readdir (DIR *dirp); 00370 extern "C" CS_IMPORT_SYM int closedir (DIR *dirp); 00371 extern "C" CS_IMPORT_SYM bool isdir (const char *path, dirent *de); 00372 # endif // CS_BUILD_SHARED_LIBS 00373 #endif 00374 00375 #ifdef CS_COMPILER_BCC 00376 // Major hack due to pow failures in CS for Borland, removing this 00377 // causes millions of strings to print out -- Brandon Ehle 00378 #define pow(arga, argb) ( (!arga && !argb)?0:pow(arga, argb) ) 00379 // Dunno why this is in CS -- Brandon Ehle 00380 #define DEBUG_BREAK 00381 #endif 00382 00383 #if defined (CS_PROCESSOR_X86) 00384 # define CS_LITTLE_ENDIAN 00385 #else 00386 # error "Please define a suitable CS_XXX_ENDIAN macro in win32/csosdefs.h!" 00387 #endif 00388 00389 #if defined(CS_COMPILER_BCC) 00390 // The Borland C++ compiler does not accept a 'main' routine 00391 // in a program which already contains WinMain. This is a work-around. 00392 #undef main 00393 #define main csMain 00394 #endif 00395 00396 // cygwin has no _beginthread and _endthread functions 00397 #ifdef __CYGWIN32__ 00398 #ifndef _beginthread 00399 #define _beginthread(func, stack, ptr) CreateThread (0, 0, \ 00400 LPTHREAD_START_ROUTINE(func), ptr, CREATE_SUSPENDED, 0) 00401 #endif 00402 #ifndef _endthread 00403 #define _endthread() {} 00404 #endif 00405 #endif 00406 00407 // just to avoid windows.h inclusion 00408 #define csSW_SHOWNORMAL 1 00409 00410 #if defined(CS_COMPILER_GCC) && defined(__STRICT_ANSI__) 00411 // Need those... 00412 extern int _argc; 00413 extern char** _argv; 00414 #define CS_WIN32_ARGC _argc 00415 #define CS_WIN32_ARGV _argv 00416 #elif defined(CS_COMPILER_BCC) 00417 #define CS_WIN32_ARGC _argc 00418 #define CS_WIN32_ARGV _argv 00419 #else 00420 #define CS_WIN32_ARGC __argc 00421 #define CS_WIN32_ARGV __argv 00422 #endif 00423 00424 00425 #ifdef __CYGWIN32__ 00426 #if !defined(CS_IMPLEMENT_PLATFORM_APPLICATION) 00427 #define CS_IMPLEMENT_PLATFORM_APPLICATION 00428 #endif 00429 00430 #else // __CYGWIN32__ 00431 00432 /* 00433 if the EXE is compiled as a GUI app, 00434 a WinMain is needed. But if compiled 00435 as a console app it's not used but main() is 00436 instead. 00437 */ 00438 00439 #if !defined(CS_IMPLEMENT_PLATFORM_APPLICATION) 00440 #ifndef __STRICT_ANSI__ 00441 #define csMain main 00442 #else 00443 /* Work around "error: ISO C++ forbids taking address of function `::main'" 00444 * when compiling -ansi -pedantic */ 00445 #define csMain mainWithAnotherNameBecauseISOCPPForbidsIt 00446 #endif 00447 #define CS_IMPLEMENT_PLATFORM_APPLICATION \ 00448 int csMain (int argc, char* argv[]); \ 00449 int WINAPI WinMain (HINSTANCE hApp, HINSTANCE prev, LPSTR cmd, int show)\ 00450 { \ 00451 (void)hApp; \ 00452 (void)show; \ 00453 (void)prev; \ 00454 (void)cmd; \ 00455 int ret = csMain (CS_WIN32_ARGC, CS_WIN32_ARGV); \ 00456 return ret; \ 00457 } 00458 #ifdef __STRICT_ANSI__ 00459 #define main mainWithAnotherNameBecauseISOCPPForbidsIt 00460 #endif 00461 #endif // CS_IMPLEMENT_PLATFORM_APPLICATION 00462 00463 #endif // __CYGWIN32__ 00464 00465 #if !defined(CS_STATIC_LINKED) 00466 00467 #if !defined(CS_IMPLEMENT_PLATFORM_PLUGIN) 00468 #define CS_IMPLEMENT_PLATFORM_PLUGIN \ 00469 int _cs_main(int /*argc*/, char* /*argv*/[]) \ 00470 { \ 00471 return 0; \ 00472 } \ 00473 extern "C" BOOL WINAPI \ 00474 DllMain (HINSTANCE /*hinstDLL*/, DWORD /*fdwReason*/, LPVOID /*lpvReserved*/) \ 00475 { \ 00476 return TRUE; \ 00477 } \ 00478 CS_EXPORTED_FUNCTION const char* plugin_compiler() \ 00479 { \ 00480 return CS_COMPILER_NAME; \ 00481 } 00482 #endif // CS_IMPLEMENT_PLATFORM_PLUGIN 00483 00484 #endif // CS_STATIC_LINKED 00485 00486 #include "sanity.inc" 00487 00488 #endif // __CS_CSOSDEFS_H__
Generated for Crystal Space 1.4.1 by doxygen 1.7.1