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