cssysdef.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 1998-2001 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 #ifdef __CS_CSSYSDEFS_H__ 00021 #error Do not include cssysdef.h from header files please! 00022 #else 00023 #define __CS_CSSYSDEFS_H__ 00024 00025 #define CSDEF_FRIEND 00026 #include "csdef.h" 00027 #undef CSDEF_FRIEND 00028 00070 /* 00071 * Pull in platform-specific overrides of the requested functionality. 00072 */ 00073 #include "csutil/csosdefs.h" 00074 00075 /* 00076 * Default definitions for requested functionality. Platform-specific 00077 * configuration files may override these. 00078 */ 00079 00083 #ifdef CS_SYSDEF_PROVIDE_TEMP 00084 # ifndef TEMP_DIR 00085 # if defined(OS_UNIX) 00086 # define TEMP_DIR "/tmp/" 00087 # else 00088 # define TEMP_DIR "" 00089 # endif 00090 # endif 00091 # ifndef TEMP_FILE 00092 # if defined(OS_UNIX) 00093 # include <unistd.h> 00095 # define TEMP_FILE "cs%lud.tmp", (unsigned long)getpid() 00096 # else 00097 00098 # define TEMP_FILE "$cs$.tmp" 00099 # endif 00100 # endif 00101 #endif // CS_SYSDEF_PROVIDE_TEMP 00102 00106 #ifdef CS_SYSDEF_PROVIDE_MKDIR 00107 # ifndef MKDIR 00108 # if defined(OS_WIN32) || (defined(OS_DOS) && !defined(COMP_GCC)) 00109 # define MKDIR(path) _mkdir (path) 00110 # else 00111 # define MKDIR(path) mkdir (path, 0755) 00112 # endif 00113 # endif 00114 #endif // CS_SYSDEF_PROVIDE_MKDIR 00115 00116 #ifdef CS_SYSDEF_PROVIDE_GETCWD 00117 # if !defined(COMP_VC) && !defined(COMP_BC) 00118 # include <unistd.h> 00119 # endif 00120 #endif // CS_SYSDEF_PROVIDE_GETCWD 00121 00122 #ifdef CS_SYSDEF_PROVIDE_DIR 00123 // For systems without opendir() 00124 // COMP_GCC has opendir, readdir 00125 # if !defined(COMP_GCC) 00126 # if defined(__NEED_OPENDIR_PROTOTYPE) 00127 struct DIR; 00128 struct dirent; 00129 extern "C" DIR *opendir (const char *name); 00130 extern "C" dirent *readdir (DIR *dirp); 00131 extern "C" int closedir (DIR *dirp); 00132 //extern "C" void seekdir (DIR *dirp, long off); 00133 //extern "C" long telldir (DIR *dirp); 00134 //extern "C" void rewinddir (DIR *dirp); 00135 # endif 00136 # endif 00137 // Generic ISDIR needed for COMP_GCC 00138 # ifdef __NEED_GENERIC_ISDIR 00139 # if defined (OS_WIN32) || defined (OS_DOS) 00140 # include <io.h> 00141 # endif 00142 # include <sys/types.h> 00143 # if !defined(OS_WIN32) 00144 # include <dirent.h> 00145 # endif 00146 # if defined(__CYGWIN32__) 00147 # include <sys/dirent.h> 00148 # endif 00149 # include <sys/stat.h> 00150 static inline bool isdir (const char *path, struct dirent *de) 00151 { 00152 char fullname [CS_MAXPATHLEN]; 00153 int pathlen = strlen (path); 00154 memcpy (fullname, path, pathlen + 1); 00155 00156 if ((pathlen) && (fullname[pathlen-1] != PATH_SEPARATOR)) 00157 { 00158 fullname[pathlen++] = PATH_SEPARATOR; 00159 fullname[pathlen] = 0; 00160 } 00161 00162 strcat (&fullname [pathlen], de->d_name); 00163 struct stat st; 00164 stat (fullname, &st); 00165 return ((st.st_mode & S_IFMT) == S_IFDIR); 00166 } 00167 # endif 00168 #endif // CS_SYSDEF_PROVIDE_DIR 00169 00170 #ifdef CS_SYSDEF_PROVIDE_UNLINK 00171 # if !defined(COMP_VC) && !defined(COMP_BC) 00172 # include <unistd.h> 00173 # endif 00174 #endif 00175 00182 #ifdef COMP_GCC 00183 // In GCC we are able to declare stack vars of dynamic size directly 00184 # define CS_ALLOC_STACK_ARRAY(type, var, size) \ 00185 type var [size] 00186 #else 00187 # include <malloc.h> 00188 # define CS_ALLOC_STACK_ARRAY(type, var, size) \ 00189 type *var = (type *)alloca ((size) * sizeof (type)) 00190 #endif 00191 00192 #ifdef CS_SYSDEF_PROVIDE_ACCESS 00193 # if !defined(COMP_VC) && !defined(COMP_BC) 00194 # include <unistd.h> 00195 # endif 00196 # ifndef F_OK 00197 # define F_OK 0 00198 # endif 00199 # ifndef R_OK 00200 # define R_OK 2 00201 # endif 00202 # ifndef W_OK 00203 # define W_OK 4 00204 # endif 00205 #endif 00206 00207 #ifdef CS_SYSDEF_PROVIDE_GETOPT 00208 # ifndef __STDC__ 00209 # define __STDC__ 1 00210 # endif 00211 # include "csutil/getopt.h" 00212 #endif 00213 00214 #ifdef CS_SYSDEF_PROVIDE_SOCKETS 00215 # ifdef __GNUC__ 00216 # warning CS_SYSDEF_PROVIDE_SOCKETS is deprecated, include cssys/sockets.h instead 00217 # endif 00218 #include "csutil/sockets.h" 00219 #endif 00220 00221 #ifdef CS_SYSDEF_PROVIDE_SELECT 00222 # include <sys/select.h> 00223 #endif 00224 00240 #define CS_HEADER_GLOBAL(X,Y) CS_HEADER_GLOBAL_COMPOSE(X,Y) 00241 #define CS_HEADER_GLOBAL_COMPOSE(X,Y) <X/Y> 00242 00255 #define CS_HEADER_LOCAL(X,Y) CS_HEADER_LOCAL_COMPOSE1(X,Y) 00256 #define CS_HEADER_LOCAL_COMPOSE1(X,Y) CS_HEADER_LOCAL_COMPOSE2(X/Y) 00257 #define CS_HEADER_LOCAL_COMPOSE2(X) #X 00258 00259 00265 #if !defined(CS_EXPORTED_FUNCTION) 00266 # define CS_EXPORTED_FUNCTION extern "C" 00267 #endif 00268 00280 #if !defined(CS_EXPORTED_NAME) 00281 # define CS_EXPORTED_NAME(Prefix, Suffix) Prefix ## Suffix 00282 #endif 00283 00284 #ifndef CS_IMPLEMENT_PLATFORM_PLUGIN 00285 # define CS_IMPLEMENT_PLATFORM_PLUGIN 00286 #endif 00287 00288 #ifndef CS_IMPLEMENT_PLATFORM_APPLICATION 00289 # define CS_IMPLEMENT_PLATFORM_APPLICATION 00290 #endif 00291 00298 #ifndef CS_INITIALIZE_PLATFORM_APPLICATION 00299 # define CS_INITIALIZE_PLATFORM_APPLICATION 00300 #endif 00301 00302 #ifndef CS_STATIC_VAR_DESTRUCTION_REGISTRAR_FUNCTION 00303 # define CS_STATIC_VAR_DESTRUCTION_REGISTRAR_FUNCTION cs_static_var_cleanup 00304 #endif 00305 00306 #ifndef CS_DECLARE_STATIC_VARIABLE_REGISTRATION 00307 # define CS_DECLARE_STATIC_VARIABLE_REGISTRATION \ 00308 void CS_STATIC_VAR_DESTRUCTION_REGISTRAR_FUNCTION (void (*p)()); 00309 #endif 00310 00311 #ifndef CS_DECLARE_STATIC_VARIABLE_CLEANUP 00312 # define CS_DECLARE_STATIC_VARIABLE_CLEANUP \ 00313 CS_DECLARE_STATIC_VARIABLE_REGISTRATION 00314 #endif 00315 00316 #ifndef CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION 00317 # define CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION \ 00318 void CS_STATIC_VAR_DESTRUCTION_REGISTRAR_FUNCTION (void (*p)()) \ 00319 { \ 00320 static void (**a)()=0; \ 00321 static int lastEntry=0; \ 00322 static int maxEntries=0; \ 00323 \ 00324 if (p) \ 00325 { \ 00326 if (lastEntry >= maxEntries) \ 00327 { \ 00328 maxEntries+=10; \ 00329 a = (void (**)())realloc (a, maxEntries*sizeof(void*)); \ 00330 } \ 00331 a[lastEntry++] = p; \ 00332 } \ 00333 else \ 00334 { \ 00335 int i; \ 00336 for (i=lastEntry-1; i >= 0; i--) \ 00337 a[i] (); \ 00338 free (a); \ 00339 } \ 00340 } 00341 #endif 00342 00343 #ifndef CS_IMPLEMENT_STATIC_VARIABLE_CLEANUP 00344 # define CS_IMPLEMENT_STATIC_VARIABLE_CLEANUP \ 00345 CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION 00346 #endif 00347 00356 #if defined(CS_STATIC_LINKED) 00357 00358 # ifndef CS_IMPLEMENT_PLUGIN 00359 # define CS_IMPLEMENT_PLUGIN \ 00360 CS_IMPLEMENT_PLATFORM_PLUGIN 00361 # endif 00362 00363 #else 00364 00365 # ifndef CS_IMPLEMENT_PLUGIN 00366 # define CS_IMPLEMENT_PLUGIN \ 00367 CS_IMPLEMENT_STATIC_VARIABLE_CLEANUP \ 00368 CS_IMPLEMENT_PLATFORM_PLUGIN 00369 # endif 00370 00371 #endif 00372 00381 #ifndef CS_IMPLEMENT_APPLICATION 00382 # define CS_IMPLEMENT_APPLICATION \ 00383 CS_IMPLEMENT_STATIC_VARIABLE_CLEANUP \ 00384 CS_IMPLEMENT_PLATFORM_APPLICATION 00385 #endif 00386 00390 #ifndef CS_REGISTER_STATIC_FOR_DESTRUCTION 00391 #define CS_REGISTER_STATIC_FOR_DESTRUCTION(getterFunc)\ 00392 CS_STATIC_VAR_DESTRUCTION_REGISTRAR_FUNCTION (getterFunc); 00393 #endif 00394 00398 #ifndef CS_STATIC_VARIABLE_CLEANUP 00399 #define CS_STATIC_VARIABLE_CLEANUP \ 00400 CS_STATIC_VAR_DESTRUCTION_REGISTRAR_FUNCTION (0); 00401 #endif 00402 00413 #ifndef CS_IMPLEMENT_STATIC_VAR_EXT 00414 #define CS_IMPLEMENT_STATIC_VAR_EXT(getterFunc,Type,initParam,kill_how) \ 00415 CS_DECLARE_STATIC_VARIABLE_REGISTRATION \ 00416 extern "C" { \ 00417 static Type* getterFunc (); \ 00418 static void getterFunc ## _kill (); \ 00419 static void getterFunc ## _kill_array (); \ 00420 void getterFunc ## _kill () \ 00421 { \ 00422 (void)getterFunc ## _kill_array; \ 00423 delete getterFunc (); \ 00424 } \ 00425 void getterFunc ## _kill_array () \ 00426 { \ 00427 (void)getterFunc ## _kill; \ 00428 delete [] getterFunc (); \ 00429 } \ 00430 Type* getterFunc () \ 00431 { \ 00432 static Type *v=0; \ 00433 if (!v) \ 00434 { \ 00435 v = new Type initParam; \ 00436 CS_REGISTER_STATIC_FOR_DESTRUCTION (getterFunc ## kill_how); \ 00437 } \ 00438 return v; \ 00439 } \ 00440 } 00441 #endif 00442 00443 #ifndef CS_IMPLEMENT_STATIC_VAR 00444 #define CS_IMPLEMENT_STATIC_VAR(getterFunc,Type,initParam) \ 00445 CS_IMPLEMENT_STATIC_VAR_EXT(getterFunc,Type,initParam,_kill) 00446 #endif 00447 00448 #ifndef CS_IMPLEMENT_STATIC_VAR_ARRAY 00449 #define CS_IMPLEMENT_STATIC_VAR_ARRAY(getterFunc,Type,initParam) \ 00450 CS_IMPLEMENT_STATIC_VAR_EXT(getterFunc,Type,initParam,_kill_array) 00451 #endif 00452 00458 #ifndef CS_DECLARE_STATIC_CLASSVAR 00459 #define CS_DECLARE_STATIC_CLASSVAR(var,getterFunc,Type) \ 00460 static Type *var; \ 00461 static Type *getterFunc (); 00462 #endif 00463 00464 #ifndef CS_DECLARE_STATIC_CLASSVAR_REF 00465 #define CS_DECLARE_STATIC_CLASSVAR_REF(var,getterFunc,Type) \ 00466 static Type *var; \ 00467 static Type &getterFunc (); 00468 #endif 00469 00479 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_EXT 00480 #define CS_IMPLEMENT_STATIC_CLASSVAR_EXT(Class,var,getterFunc,Type,initParam,kill_how) \ 00481 Type *Class::var = 0; \ 00482 extern "C" { \ 00483 static void Class ## _ ## getterFunc ## _kill (); \ 00484 static void Class ## _ ## getterFunc ## _kill_array (); \ 00485 void Class ## _ ## getterFunc ## _kill () \ 00486 { \ 00487 (void) Class ## _ ## getterFunc ## _kill_array; \ 00488 delete Class::getterFunc (); \ 00489 } \ 00490 void Class ## _ ## getterFunc ## _kill_array () \ 00491 { \ 00492 (void) Class ## _ ## getterFunc ## _kill; \ 00493 delete [] Class::getterFunc (); \ 00494 } \ 00495 } \ 00496 Type* Class::getterFunc () \ 00497 { \ 00498 if (!var) \ 00499 { \ 00500 var = new Type initParam; \ 00501 CS_DECLARE_STATIC_VARIABLE_REGISTRATION \ 00502 CS_REGISTER_STATIC_FOR_DESTRUCTION (Class ## _ ## getterFunc ## kill_how); \ 00503 } \ 00504 return var; \ 00505 } 00506 #endif 00507 00508 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR 00509 #define CS_IMPLEMENT_STATIC_CLASSVAR(Class,var,getterFunc,Type,initParam) \ 00510 CS_IMPLEMENT_STATIC_CLASSVAR_EXT(Class,var,getterFunc,Type,initParam,_kill) 00511 #endif 00512 00513 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_ARRAY 00514 #define CS_IMPLEMENT_STATIC_CLASSVAR_ARRAY(Class,var,getterFunc,Type,initParam) \ 00515 CS_IMPLEMENT_STATIC_CLASSVAR_EXT(Class,var,getterFunc,Type,initParam,_kill_array) 00516 #endif 00517 00518 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT 00519 #define CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT(Class,var,getterFunc,Type,initParam,kill_how) \ 00520 Type *Class::var = 0; \ 00521 extern "C" { \ 00522 static void Class ## _ ## getterFunc ## _kill (); \ 00523 static void Class ## _ ## getterFunc ## _kill_array (); \ 00524 void Class ## _ ## getterFunc ## _kill () \ 00525 { \ 00526 (void) Class ## _ ## getterFunc ## _kill_array; \ 00527 delete &Class::getterFunc (); \ 00528 } \ 00529 void Class ## _ ## getterFunc ## _kill_array () \ 00530 { \ 00531 (void) Class ## _ ## getterFunc ## _kill; \ 00532 delete [] &Class::getterFunc (); \ 00533 } \ 00534 } \ 00535 Type &Class::getterFunc () \ 00536 { \ 00537 if (!var) \ 00538 { \ 00539 var = new Type initParam; \ 00540 CS_DECLARE_STATIC_VARIABLE_REGISTRATION \ 00541 CS_REGISTER_STATIC_FOR_DESTRUCTION (Class ## _ ## getterFunc ## kill_how); \ 00542 } \ 00543 return *var; \ 00544 } 00545 #endif 00546 00547 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_REF 00548 #define CS_IMPLEMENT_STATIC_CLASSVAR_REF(Class,var,getterFunc,Type,initParam) \ 00549 CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT(Class,var,getterFunc,Type,initParam,_kill) 00550 #endif 00551 00552 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_REF_ARRAY 00553 #define CS_IMPLEMENT_STATIC_CLASSVAR_REF_ARRAY(Class,var,getterFunc,Type,initParam) \ 00554 CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT(Class,var,getterFunc,Type,initParam,_kill_array) 00555 #endif 00556 00557 // The following define should only be enabled if you have defined 00558 // a special version of overloaded new that accepts two additional 00559 // parameters: a (void*) pointing to the filename and an int with the 00560 // line number. This is typically used for memory debugging. 00561 // In csutil/memdebug.cpp there is a memory debugger which can (optionally) 00562 // use this feature. Note that if CS_EXTENSIVE_MEMDEBUG is enabled while 00563 // the memory debugger is not the memory debugger will still provide the 00564 // needed overloaded operators so you can leave CS_EXTENSIVE_MEMDEBUG on in 00565 // that case and the only overhead will be a little more arguments to 'new'. 00566 // Do not enable CS_EXTENSIVE_MEMDEBUG if your platform or your own code 00567 // defines its own 'new' operator, since this version will interfere with your 00568 // own. 00569 #ifndef CS_DEBUG 00570 # undef CS_EXTENSIVE_MEMDEBUG 00571 #endif 00572 #ifdef CS_EXTENSIVE_MEMDEBUG 00573 extern void* operator new (size_t s, void* filename, int line); 00574 extern void* operator new[] (size_t s, void* filename, int line); 00575 #define CS_EXTENSIVE_MEMDEBUG_NEW new ((void*)__FILE__, __LINE__) 00576 #define new CS_EXTENSIVE_MEMDEBUG_NEW 00577 #endif 00578 00579 #ifdef CS_DEBUG 00580 # if !defined (DEBUG_BREAK) 00581 # if defined (PROC_X86) 00582 # if defined (COMP_GCC) 00583 # define DEBUG_BREAK asm ("int $3") 00584 # else 00585 # define DEBUG_BREAK _asm int 3 00586 # endif 00587 # else 00588 # define DEBUG_BREAK { static int x = 0; x /= x; } 00589 # endif 00590 # endif 00591 # if !defined (CS_ASSERT) 00592 # if defined (COMP_VC) 00593 # define CS_ASSERT(x) assert(x) 00594 # else 00595 # include <stdio.h> 00596 # define CS_ASSERT(x) \ 00597 if (!(x)) \ 00598 { \ 00599 fprintf (stderr, __FILE__ ":%d: failed assertion '%s'\n",\ 00600 int(__LINE__), #x ); \ 00601 DEBUG_BREAK; \ 00602 } 00603 # endif 00604 # endif 00605 #else 00606 # undef DEBUG_BREAK 00607 # define DEBUG_BREAK 00608 # undef CS_ASSERT 00609 # define CS_ASSERT(x) 00610 #endif 00611 00612 // Check if the csosdefs.h defined either CS_LITTLE_ENDIAN or CS_BIG_ENDIAN 00613 #if !defined (CS_LITTLE_ENDIAN) && !defined (CS_BIG_ENDIAN) 00614 # error No CS_XXX_ENDIAN macro defined in your OS-specific csosdefs.h! 00615 #endif 00616 00617 /* 00618 * This is a bit of overkill but if you're sure your CPU doesn't require 00619 * strict alignment add your CPU to the !defined below to get slightly 00620 * smaller and faster code in some cases. 00621 * 00622 * @@@ In the future, this should be moved to volatile.h and determined as 00623 * part of the configuration process. 00624 */ 00625 #if !defined (PROC_X86) 00626 # define CS_STRICT_ALIGNMENT 00627 #endif 00628 00629 // Adjust some definitions contained in volatile.h 00630 #if defined (PROC_X86) && !defined (DO_NASM) 00631 # undef NO_ASSEMBLER 00632 # define NO_ASSEMBLER 00633 #endif 00634 00635 #if !defined (PROC_X86) || defined (NO_ASSEMBLER) 00636 # undef DO_MMX 00637 # undef DO_NASM 00638 #endif 00639 00640 // Use fast QInt and QRound on CPUs that are known to support it 00641 #if !defined (CS_NO_IEEE_OPTIMIZATIONS) 00642 # if !defined (CS_IEEE_DOUBLE_FORMAT) 00643 # if defined (PROC_X86) || defined (PROC_M68K) 00644 # define CS_IEEE_DOUBLE_FORMAT 00645 # endif 00646 # endif 00647 #endif 00648 00649 // gcc can perform usefull checking for printf/scanf format strings, just add 00650 // this define at the end of the function declaration 00651 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) 00652 # define CS_GNUC_PRINTF( format_idx, arg_idx) \ 00653 __attribute__((format (__printf__, format_idx, arg_idx))) 00654 # define CS_GNUC_SCANF( format_idx, arg_idx ) \ 00655 __attribute__((format (__scanf__, format_idx, arg_idx))) 00656 #else 00657 # define CS_GNUC_PRINTF( format_idx, arg_idx ) 00658 # define CS_GNUC_SCANF( format_idx, arg_idx ) 00659 #endif 00660 00661 // remove __attribute__ on non GNUC compilers 00662 #ifndef __GNUC__ 00663 #define __attribute__(x) 00664 #endif 00665 00666 // Support for alignment and packing of structures. 00667 #if !defined(CS_STRUCT_ALIGN_4BYTE_BEGIN) 00668 # if defined(__GNUC__) && defined(CS_STRICT_ALIGNMENT) 00669 # define CS_STRUCT_ALIGN_4BYTE_BEGIN 00670 # define CS_STRUCT_ALIGN_4BYTE_END __attribute__ ((aligned(4))) 00671 # else 00672 # define CS_STRUCT_ALIGN_4BYTE_BEGIN 00673 # define CS_STRUCT_ALIGN_4BYTE_END 00674 # endif 00675 #endif 00676 00677 // Macro used to define static implicit pointer conversion function. 00678 // Only use within a class declaration. 00679 #ifndef _CS_IMPLICITPTRCAST_NAME 00680 # define _CS_IMPLICITPTRCAST_NAME __ImplicitPtrCast 00681 #endif 00682 00704 #define CS_IMPLEMENT_IMPLICIT_PTR_CAST(classname) \ 00705 inline static classname* _CS_IMPLICITPTRCAST_NAME (classname* ptr) \ 00706 { \ 00707 return ptr;\ 00708 } 00709 00718 #define CS_IMPLICIT_PTR_CAST(classname, ptr) \ 00719 (classname::_CS_IMPLICITPTRCAST_NAME(ptr)) 00720 00722 extern void (*fatal_exit) (int errorcode, bool canreturn); 00723 00724 #endif // __CS_CSSYSDEFS_H__
Generated for Crystal Space by doxygen 1.2.18