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_USE_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_USE_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 #if !defined(__INTEL_COMPILER) 00053 #pragma inline_depth (255) 00054 #pragma inline_recursion (on) 00055 #pragma intrinsic (memset, memcpy, memcmp) 00056 #pragma intrinsic (strcpy, strcmp, strlen, strcat) 00057 #pragma intrinsic (abs, fabs) 00058 #pragma intrinsic (_byteswap_ushort, _byteswap_ulong, _byteswap_uint64) 00059 #endif 00060 00061 #pragma auto_inline (on) 00062 00063 #define CS_FORCEINLINE __forceinline 00064 00065 #if _MSC_VER >= 1400 00066 /* Work around an apparent incompatibility between VC8's intrin.h and 00067 * the Windows SDK 6.0's winnt.h - _interlockedbittestandset and 00068 * _interlockedbittestandreset have slightly different prototypes. 00069 * Go Microsoft! 00070 */ 00071 #define _interlockedbittestandset workaround_header_bug_1 00072 #define _interlockedbittestandreset workaround_header_bug_2 00073 #include <intrin.h> 00074 #undef _interlockedbittestandset 00075 #undef _interlockedbittestandreset 00076 #else 00077 extern "C" long _InterlockedCompareExchange (long volatile *, long, long); 00078 extern "C" long _InterlockedDecrement (long volatile *); 00079 extern "C" long _InterlockedExchange (long volatile *, long); 00080 extern "C" long _InterlockedIncrement (long volatile *); 00081 00082 extern "C" unsigned char _BitScanForward (unsigned long* Index, unsigned long Mask); 00083 extern "C" unsigned char _BitScanReverse (unsigned long* Index, unsigned long Mask); 00084 #endif 00085 #if !defined(__INTEL_COMPILER) 00086 #pragma intrinsic (_InterlockedCompareExchange) 00087 #pragma intrinsic (_InterlockedDecrement) 00088 #pragma intrinsic (_InterlockedExchange) 00089 #pragma intrinsic (_InterlockedIncrement) 00090 #pragma intrinsic (_BitScanForward) 00091 #pragma intrinsic (_BitScanReverse) 00092 #endif 00093 00094 #define CS_HAVE_BITSCAN_INTRINSICS 00095 00096 #if defined(__CRYSTAL_SPACE__) && !defined(CS_DEBUG) 00097 #pragma code_seg("CSpace") // Just for fun :) 00098 // However, doing this in debug builds prevents Edit & Continue from 00099 // functioning properly :/ 00100 #endif 00101 00102 // VC8 quirks 00103 #if (_MSC_VER >= 1400) 00104 // Also note quirk in csconfig.h 00105 00106 // Nothing else atm. 00107 #endif 00108 #endif 00109 00110 #ifndef WINVER 00111 #define WINVER 0x0500 00112 #endif 00113 00114 #ifndef _WIN32_WINNT 00115 #define _WIN32_WINNT 0x0500 00116 #endif 00117 00118 00119 // So many things require this. IF you have an issue with something defined 00120 // in it then undef that def here. 00121 00122 #if defined(CS_COMPILER_GCC) 00123 00124 // From the w32api header files: 00125 00126 #if defined(__i686__) && !defined(_M_IX86) 00127 #define _M_IX86 600 00128 #elif defined(__i586__) && !defined(_M_IX86) 00129 #define _M_IX86 500 00130 #elif defined(__i486__) && !defined(_M_IX86) 00131 #define _M_IX86 400 00132 #elif defined(__i386__) && !defined(_M_IX86) 00133 #define _M_IX86 300 00134 #endif 00135 #if defined(_M_IX86) && !defined(_X86_) 00136 #define _X86_ 00137 #endif 00138 00139 #ifdef __GNUC__ 00140 #ifndef NONAMELESSUNION 00141 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) 00142 #ifndef _ANONYMOUS_UNION 00143 #define _ANONYMOUS_UNION __extension__ 00144 #endif 00145 #ifndef _ANONYMOUS_STRUCT 00146 #define _ANONYMOUS_STRUCT __extension__ 00147 #endif 00148 #else 00149 #if defined(__cplusplus) 00150 #define _ANONYMOUS_UNION __extension__ 00151 #endif /* __cplusplus */ 00152 #endif /* __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) */ 00153 #endif /* NONAMELESSUNION */ 00154 #endif /* __GNUC__ */ 00155 00156 #ifndef _ANONYMOUS_UNION 00157 #define _ANONYMOUS_UNION 00158 #define _UNION_NAME(x) x 00159 #define DUMMYUNIONNAME u 00160 #define DUMMYUNIONNAME2 u2 00161 #define DUMMYUNIONNAME3 u3 00162 #define DUMMYUNIONNAME4 u4 00163 #define DUMMYUNIONNAME5 u5 00164 #define DUMMYUNIONNAME6 u6 00165 #define DUMMYUNIONNAME7 u7 00166 #define DUMMYUNIONNAME8 u8 00167 #else 00168 #define _UNION_NAME(x) 00169 #define DUMMYUNIONNAME 00170 #define DUMMYUNIONNAME2 00171 #define DUMMYUNIONNAME3 00172 #define DUMMYUNIONNAME4 00173 #define DUMMYUNIONNAME5 00174 #define DUMMYUNIONNAME6 00175 #define DUMMYUNIONNAME7 00176 #define DUMMYUNIONNAME8 00177 #endif 00178 #ifndef _ANONYMOUS_STRUCT 00179 #define _ANONYMOUS_STRUCT 00180 #define _STRUCT_NAME(x) x 00181 #define DUMMYSTRUCTNAME s 00182 #define DUMMYSTRUCTNAME2 s2 00183 #define DUMMYSTRUCTNAME3 s3 00184 #else 00185 #define _STRUCT_NAME(x) 00186 #define DUMMYSTRUCTNAME 00187 #define DUMMYSTRUCTNAME2 00188 #define DUMMYSTRUCTNAME3 00189 #endif 00190 00191 #else 00192 00193 #if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && \ 00194 defined(_M_IX86) 00195 #define _X86_ 00196 #endif 00197 00198 #if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && \ 00199 defined(_M_AMD64) 00200 #define _AMD64_ 00201 #endif 00202 00203 #if !defined(_X86_) && !defined(_M_IX86) && !defined(_AMD64_) && \ 00204 defined(_M_IA64) && !defined(_IA64_) 00205 #define _IA64_ 00206 #endif 00207 00208 #endif 00209 00210 #ifndef __CYGWIN32__ 00211 #include <excpt.h> 00212 #endif 00213 #include <stdarg.h> 00214 #include <windef.h> 00215 #include <winbase.h> 00216 #include <winreg.h> 00217 #include <malloc.h> 00218 #include <sys/types.h> 00219 #include <sys/stat.h> 00220 #ifdef CS_HAVE_SYS_PARAM_H 00221 #include <sys/param.h> 00222 #endif 00223 #ifndef __CYGWIN32__ 00224 #include <direct.h> 00225 #endif 00226 00227 00228 #ifndef WINGDIAPI 00229 #define WINGDIAPI DECLSPEC_IMPORT 00230 #endif 00231 00232 /* 00233 LONG_PTR is used in the Win32 canvases, but it's only defined in newer 00234 Platform or DirectX SDKs (in BaseTsd.h). 00235 Ergo, on older SDKs, we have to define it ourselves. One indicator for the 00236 presence of LONG_PTR seems to be if the __int3264 macro is #defined. 00237 So, if it's not, we define LONG_PTR. 00238 */ 00239 #ifndef __int3264 00240 typedef LONG LONG_PTR; 00241 typedef ULONG ULONG_PTR; 00242 typedef DWORD DWORD_PTR; 00243 #endif 00244 00245 #if defined(_DEBUG) || defined(CS_DEBUG) 00246 #include <assert.h> 00247 #ifndef CS_DEBUG 00248 #define CS_DEBUG 00249 #endif 00250 00251 #if defined(CS_COMPILER_MSVC) 00252 #include <crtdbg.h> 00253 00254 #if defined(CS_EXTENSIVE_MEMDEBUG) 00255 #define malloc(size) \ 00256 _malloc_dbg ((size), _NORMAL_BLOCK, __FILE__, __LINE__) 00257 #define free(ptr) _free_dbg ((ptr), _NORMAL_BLOCK) 00258 #define realloc(ptr, size) \ 00259 _realloc_dbg ((ptr), (size), _NORMAL_BLOCK, __FILE__, __LINE__) 00260 #define calloc(num, size) \ 00261 _calloc_dbg ((num), (size), _NORMAL_BLOCK, __FILE__, __LINE__) 00262 00263 // heap consistency check is on by default, leave it 00264 #define CS_WIN32_MSVC_DEBUG_GOOP \ 00265 _CrtSetDbgFlag ( \ 00266 _CrtSetDbgFlag (_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF) 00267 #else 00268 // turn heap consistency check off 00269 #define CS_WIN32_MSVC_DEBUG_GOOP \ 00270 _CrtSetDbgFlag ( \ 00271 (_CrtSetDbgFlag (_CRTDBG_REPORT_FLAG) & ~_CRTDBG_ALLOC_MEM_DF) | \ 00272 _CRTDBG_LEAK_CHECK_DF) 00273 #endif 00274 #endif 00275 00276 #endif 00277 00278 #ifdef CS_WIN32_MSVC_DEBUG_GOOP 00279 #define CS_INITIALIZE_PLATFORM_APPLICATION CS_WIN32_MSVC_DEBUG_GOOP 00280 #endif 00281 00282 // The default 2D graphics driver used by renderers on this platform. 00283 #define CS_OPENGL_2D_DRIVER "crystalspace.graphics2d.glwin32" 00284 00285 // The default sound driver used on this platform. 00286 #define CS_SNDSYS_DRIVER "crystalspace.sndsys.software.driver.directsound" 00287 00288 // SCF symbol export facility. 00289 #ifndef CS_STATIC_LINKED 00290 // No need to export the symbols when statically linking into one big binary. 00291 # undef CS_EXPORTED_FUNCTION 00292 # define CS_EXPORTED_FUNCTION extern "C" __declspec(dllexport) 00293 #endif 00294 00295 #if defined (CS_COMPILER_BCC) 00296 # define strcasecmp stricmp 00297 # define strncasecmp strnicmp 00298 #endif 00299 00300 #if defined (CS_COMPILER_MSVC) 00301 # define strcasecmp _stricmp 00302 # define strncasecmp _strnicmp 00303 # define snprintf _snprintf 00304 #endif 00305 00306 #if defined (CS_COMPILER_MSVC) 00307 # if defined(_MSC_VER) && (_MSC_VER < 1300) 00308 # include <assert.h> 00309 static inline longlong strtoll(char const* s, char** sN, int base) 00310 { 00311 assert(sN == 0); 00312 assert(base == 10); 00313 return _atoi64(s); 00314 } 00315 # else 00316 # define strtoll _strtoi64 00317 # endif 00318 #endif 00319 00320 // Maximal path length 00321 #ifndef CS_MAXPATHLEN 00322 # ifdef _MAX_FNAME 00323 # define CS_MAXPATHLEN _MAX_FNAME 00324 # else 00325 # define CS_MAXPATHLEN 260 /* not 256 */ 00326 # endif 00327 #endif 00328 #define CS_PATH_DELIMITER ';' 00329 #define CS_PATH_SEPARATOR '\\' 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_CRYSTALSPACE_LIB 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__) && !(CS_PROCESSOR_SIZE == 64) 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 2.0 by doxygen 1.6.1