Main Page   Class Hierarchy   Compound List   File List   Compound Members  

cssysdef.h

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 
00029 /*
00030     This include file should be included from every source file.
00031     Just before #include directive it can contain several #define's
00032     that specify what the source file requires.
00033 
00034     The following variables can be defined:
00035 
00036     #define CS_SYSDEF_PROVIDE_CASE
00037       Define the UPPERCASE() and LOWERCASE() macros.
00038 
00039     #define CS_SYSDEF_PROVIDE_PATH
00040       Include definition of PATH_SEPARATOR character, MAXPATHLEN and
00041       APPEND_SLASH macros.
00042 
00043     #define CS_SYSDEF_PROVIDE_MKDIR
00044       Include definition for MKDIR()
00045 
00046     #define CS_SYSDEF_PROVIDE_GETCWD
00047       Include definition for getcwd()
00048 
00049     #define CS_SYSDEF_PROVIDE_TEMP
00050       Include definitions for TEMP_DIR and TEMP_FILE.
00051 
00052     #define CS_SYSDEF_PROVIDE_DIR
00053       Include definitions required for opendir(), readdir(), closedir()
00054       and isdir().
00055  
00056     #define CS_SYSDEF_PROVIDE_UNLINK
00057       Include definitions required for unlink()
00058 
00059     #define CS_SYSDEF_PROVIDE_ACCESS
00060       Include definitions required for access()
00061 
00062     #define CS_SYSDEF_PROVIDE_ALLOCA
00063       Include definition for alloca() and ALLOC_STACK_ARRAY()
00064 
00065     #define CS_SYSDEF_PROVIDE_GETOPT
00066       For getopt() and GNU getopt_long()
00067 
00068     #define CS_SYSDEF_PROVIDE_SOCKETS
00069       For TCP/IP sockets definitions.  Specifically, should define the
00070       following macros, constants, typedefs, and prototypes:
00071         inet_addr(), gethostbyname(), ntohl(), etc.
00072         socket(), listen(), bind(), etc. -- the standard socket functions
00073         csNetworkSocket -- typedef or macro for socket descriptor type
00074         struct sockaddr -- standard socket address type (and cousins)
00075         socklen_t -- typedef or macro
00076         CS_NET_SOCKET_INVALID -- value representing invalid socket
00077         CS_CLOSESOCKET -- name of function to close a socket
00078         CS_IOCTLSOCKET -- name of "ioctl" function for sockets
00079         CS_GETSOCKETERROR -- name of function or variable for socket error code
00080         
00081     #define CS_SYSDEF_PROVIDE_SELECT
00082       Includes definitions required for select(), FD_* macros, and
00083       struct timeval.
00084 
00085     The system-dependent include files can undefine some or all
00086     CS_SYSDEF_PROVIDE_xxx macros to avoid further definitions in this file.
00087     For example, if a system-dependent file defines everything needed for
00088     CS_SYSDEF_PROVIDE_GETOPT it should #undefine CS_SYSDEF_PROVIDE_GETOPT to
00089     avoid including util/gnu/getopt.h at the bottom of this file.
00090 */
00091 
00092 #if defined (CS_SYSDEF_PROVIDE_DIR) && !defined (CS_SYSDEF_PROVIDE_PATH)
00093 #  define CS_SYSDEF_PROVIDE_PATH
00094 #endif
00095 
00096 /*
00097  * Pull in platform-specific overrides of the requested functionality.
00098  */
00099 #include "cssys/csosdefs.h"
00100 
00101 /*
00102  * Default definitions for requested functionality.  Platform-specific
00103  * configuration files may override these.
00104  */
00105 
00106 #ifdef CS_SYSDEF_PROVIDE_CASE
00107 // Convert a character to upper case
00108 #  ifndef UPPERCASE
00109 #    define UPPERCASE(c) ((c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c)
00110 #  endif
00111 // Convert a character to lower case
00112 #  ifndef LOWERCASE
00113 #    define LOWERCASE(c) ((c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c)
00114 #  endif
00115 #endif // CS_SYSDEF_PROVIDE_CASE
00116 
00117 #ifdef CS_SYSDEF_PROVIDE_PATH
00118 // Path separator character
00119 #  ifndef PATH_SEPARATOR
00120 #    if defined(OS_MACOS) || defined(__CYGWIN32__)
00121 #      define PATH_SEPARATOR '/'
00122 #    elif defined(OS_OS2) || defined(OS_DOS) || defined(OS_WIN32)
00123 #      define PATH_SEPARATOR '\\'
00124 #    else
00125 #      define PATH_SEPARATOR '/'
00126 #    endif
00127 #  endif
00128 // Maximal path length
00129 #  ifndef MAXPATHLEN
00130 #    ifdef _MAX_FNAME
00131 #      define MAXPATHLEN _MAX_FNAME
00132 #    else
00133 #      define MAXPATHLEN 256
00134 #    endif
00135 #  endif
00136 #  define APPEND_SLASH(str,len)                 \
00137      if ((len)                                  \
00138       && (str[len - 1] != '/')                  \
00139       && (str[len - 1] != PATH_SEPARATOR))      \
00140      {                                          \
00141        str[len++] = PATH_SEPARATOR;             \
00142        str[len] = 0;                            \
00143      } /* endif */
00144 #endif // CS_SYSDEF_PROVIDE_PATH
00145 
00146 #ifdef CS_SYSDEF_PROVIDE_TEMP
00147 // Directory for temporary files
00148 #  ifndef TEMP_DIR
00149 #    if defined(OS_UNIX)
00150 #      define TEMP_DIR "/tmp/"
00151 #    else
00152 #      define TEMP_DIR ""
00153 #    endif
00154 #  endif
00155 // Name for temporary file
00156 #  ifndef TEMP_FILE
00157 #    if defined(OS_UNIX)
00158 #      include <unistd.h>
00159 #      define TEMP_FILE "cs%lud.tmp", (unsigned long)getpid()
00160 #    else
00161 #      define TEMP_FILE "$cs$.tmp"
00162 #    endif
00163 #  endif
00164 #endif // CS_SYSDEF_PROVIDE_TEMP
00165 
00166 #ifdef CS_SYSDEF_PROVIDE_MKDIR
00167 // How to make a directory (not entire path, only the last on the path)
00168 #  ifndef MKDIR
00169 #    if defined(OS_WIN32) || (defined(OS_DOS) && !defined(COMP_GCC))
00170 #      define MKDIR(path) _mkdir (path)
00171 #    else
00172 #      define MKDIR(path) mkdir (path, 0755)
00173 #    endif
00174 #  endif
00175 #endif // CS_SYSDEF_PROVIDE_MKDIR
00176 
00177 #ifdef CS_SYSDEF_PROVIDE_GETCWD
00178 #  if defined(OS_MACOS)
00179 #    include <unix.h>
00180 #  else
00181 #    if !defined(COMP_VC) && !defined(COMP_BC)
00182 #      include <unistd.h>
00183 #    endif
00184 #  endif
00185 #endif // CS_SYSDEF_PROVIDE_GETCWD
00186 
00187 #ifdef CS_SYSDEF_PROVIDE_DIR
00188 // For systems without opendir()
00189 // COMP_GCC has opendir, readdir 
00190 # if !defined(COMP_GCC) || defined(OS_PS2)
00191 #  if defined(__NEED_OPENDIR_PROTOTYPE) || defined(OS_PS2)
00192 #    if defined(OS_MACOS) || defined(OS_PS2)
00193        typedef char DIR;
00194        typedef struct dirent {
00195           char d_name[ MAXPATHLEN ];
00196        } dirent;
00197 #    else
00198        struct DIR;
00199        struct dirent;
00200 #    endif
00201      extern "C" DIR *opendir (const char *name);
00202      extern "C" dirent *readdir (DIR *dirp);
00203      extern "C" int closedir (DIR *dirp);
00204      //extern "C" void seekdir (DIR *dirp, long off);
00205      //extern "C" long telldir (DIR *dirp);
00206      //extern "C" void rewinddir (DIR *dirp);
00207 #  endif
00208 # endif
00209 // Generic ISDIR needed for COMP_GCC
00210 #  ifdef __NEED_GENERIC_ISDIR
00211 #    if !defined (OS_UNIX) && !defined (OS_MACOS) && !defined(OS_PS2)
00212 #      include <io.h>
00213 #    endif
00214 #    if defined(OS_MACOS)
00215 #      include <stat.h>
00216 #    else
00217 #      include <sys/types.h>
00218 #      if !defined(OS_WIN32) && !defined(OS_PS2)
00219 #        include <dirent.h>
00220 #      endif
00221 #      if defined(__CYGWIN32__)
00222 #        include <sys/dirent.h>
00223 #      endif
00224 #      include <sys/stat.h>
00225 #    endif
00226      static inline bool isdir (const char *path, struct dirent *de)
00227      {
00228        char fullname [MAXPATHLEN];
00229        int pathlen = strlen (path);
00230        memcpy (fullname, path, pathlen + 1);
00231        APPEND_SLASH (fullname, pathlen);
00232        strcat (&fullname [pathlen], de->d_name);
00233        struct stat st;
00234        stat (fullname, &st);
00235        return ((st.st_mode & S_IFMT) == S_IFDIR);
00236      }
00237 #  endif
00238 #endif // CS_SYSDEF_PROVIDE_DIR
00239 
00240 #ifdef CS_SYSDEF_PROVIDE_UNLINK
00241 #  if defined (OS_MACOS)
00242 #    include <unix.h>
00243 #  else
00244 #    if !defined(COMP_VC) && !defined(COMP_BC)
00245 #      include <unistd.h>
00246 #    endif
00247 #  endif
00248 #endif
00249 
00250 #ifdef CS_SYSDEF_PROVIDE_ALLOCA
00251 // Prototypes for dynamic stack memory allocation
00252 #  if defined (COMP_VC) || defined(COMP_BC) || \
00253      (defined(COMP_GCC) && defined(OS_WIN32))
00254 #    include <malloc.h>
00255 #  elif defined(COMP_GCC) && defined(OS_DOS)
00256 #    include <stdlib.h>
00257 #  elif defined(COMP_GCC) && defined(OS_PS2)
00258 #    include <malloc.h>
00259 #  elif defined(OS_BSD)
00260 #    include <stdlib.h>
00261 #  else
00262 #    include <alloca.h>
00263 #  endif
00264 #  if defined (COMP_GCC)
00265     // In GCC we are able to declare stack vars of dynamic size directly
00266 #    define ALLOC_STACK_ARRAY(var,type,size) \
00267        type var [size]
00268 #  else
00269 #    define ALLOC_STACK_ARRAY(var,type,size) \
00270        type *var = (type *)alloca (size * sizeof (type))
00271 #  endif
00272 #endif
00273 
00274 #ifdef CS_SYSDEF_PROVIDE_ACCESS
00275 #  if !defined (OS_MACOS) && !defined(COMP_VC) && !defined(COMP_BC)
00276 #    include <unistd.h>
00277 #  endif
00278 #  ifndef F_OK
00279 #    define F_OK 0
00280 #  endif
00281 #  ifndef R_OK
00282 #    define R_OK 2
00283 #  endif
00284 #  ifndef W_OK
00285 #    define W_OK 4
00286 #  endif
00287 #endif
00288 
00289 #ifdef CS_SYSDEF_PROVIDE_GETOPT
00290 #  ifndef __STDC__
00291 #    define __STDC__ 1
00292 #  endif
00293 #  include "cssys/getopt.h"
00294 #endif
00295 
00296 #ifdef CS_SYSDEF_PROVIDE_SOCKETS
00297 #  if !defined (OS_MACOS)
00298 #    include <unistd.h>
00299 #  endif
00300 #  include <sys/types.h>
00301 #  include <sys/socket.h>
00302 #  if defined (OS_UNIX)
00303 #    define BSD_COMP 1
00304 #    include <sys/ioctl.h>
00305 #    if !defined (OS_SOLARIS) && !defined (OS_BE)
00306 #      include <arpa/inet.h>
00307 #      include <sys/time.h>
00308 #    endif
00309 #  endif
00310 #  include <netinet/in.h>
00311 #  include <netdb.h>
00312 #  if defined (CS_USE_FAKE_SOCKLEN_TYPE)
00313      typedef int socklen_t;
00314 #  endif
00315 #  if !defined (CS_IOCTLSOCKET)
00316 #    define CS_IOCTLSOCKET ioctl
00317 #  endif
00318 #  if !defined (CS_CLOSESOCKET)
00319 #    define CS_CLOSESOCKET close
00320 #  endif
00321 #  if !defined (CS_GETSOCKETERROR)
00322 #    define CS_GETSOCKETERROR errno
00323 #  endif
00324    typedef unsigned int csNetworkSocket;
00325 #  if !defined (CS_NET_SOCKET_INVALID)
00326 #    define CS_NET_SOCKET_INVALID ((csNetworkSocket)~0)
00327 #  endif
00328 #endif
00329 
00330 #ifdef CS_SYSDEF_PROVIDE_SELECT
00331 #  include <sys/select.h>
00332 #endif
00333 
00349 #define CS_HEADER_GLOBAL(X,Y) CS_HEADER_GLOBAL_COMPOSE(X,Y)
00350 #define CS_HEADER_GLOBAL_COMPOSE(X,Y) < ## X ## / ## Y ## >
00351 
00364 #define CS_HEADER_LOCAL(X,Y) CS_HEADER_LOCAL_COMPOSE1(X,Y)
00365 #define CS_HEADER_LOCAL_COMPOSE1(X,Y) CS_HEADER_LOCAL_COMPOSE2(X ## / ## Y)
00366 #define CS_HEADER_LOCAL_COMPOSE2(X) #X
00367 
00376 #ifndef CS_IMPLEMENT_PLUGIN
00377 #  define CS_IMPLEMENT_PLUGIN
00378 #endif
00379 
00388 #ifndef CS_IMPLEMENT_APPLICATION
00389 #  define CS_IMPLEMENT_APPLICATION
00390 #endif
00391 
00392 // The following define should only be enabled if you have defined
00393 // a special version of overloaded new that accepts two additional
00394 // parameters: a (void*) pointing to the filename and an int with the
00395 // line number. This is typically used for memory debugging.
00396 // In csutil/memdebug.cpp there is a memory debugger which can (optionally)
00397 // use this feature. Note that if CS_EXTENSIVE_MEMDEBUG is enabled while
00398 // the memory debugger is not the memory debugger will still provide the
00399 // needed overloaded operators so you can leave CS_EXTENSIVE_MEMDEBUG on in
00400 // that case and the only overhead will be a little more arguments to 'new'.
00401 #ifndef CS_EXTENSIVE_MEMDEBUG
00402 #  ifdef CS_DEBUG
00403 #    define CS_EXTENSIVE_MEMDEBUG 1
00404 #  else
00405 #    define CS_EXTENSIVE_MEMDEBUG 0
00406 #  endif
00407 #endif
00408 #if CS_EXTENSIVE_MEMDEBUG
00409 extern void* operator new (size_t s, void* filename, int line);
00410 extern void* operator new[] (size_t s, void* filename, int line);
00411 #define NEW new ((void*)__FILE__, __LINE__)
00412 #define new NEW
00413 #endif
00414 
00415 #ifdef CS_DEBUG
00416 #  if !defined (DEBUG_BREAK)
00417 #    if defined (PROC_X86)
00418 #      if defined (COMP_GCC)
00419 #        define DEBUG_BREAK     asm ("int $3")
00420 #      else
00421 #        define DEBUG_BREAK     _asm int 3
00422 #      endif
00423 #    else
00424 #      define DEBUG_BREAK       { static int x = 0; x /= x; }
00425 #    endif
00426 #  endif
00427 #  if !defined (CS_ASSERT)
00428 #    if defined (COMP_VC)
00429 #      define  CS_ASSERT(x) assert(x)
00430 #    else
00431 #      include <stdio.h>
00432 #      define CS_ASSERT(x)                                              \
00433          if (!(x))                                                      \
00434          {                                                              \
00435            fprintf (stderr, __FILE__ ":%d: failed assertion '%s'\n",\
00436              int(__LINE__), #x );                                       \
00437            DEBUG_BREAK;                                                 \
00438          }
00439 #    endif
00440 #  endif
00441 #else
00442 #  undef DEBUG_BREAK
00443 #  define DEBUG_BREAK
00444 #  undef CS_ASSERT
00445 #  define CS_ASSERT(x)
00446 #endif
00447 
00448 // Check if the csosdefs.h defined either CS_LITTLE_ENDIAN or CS_BIG_ENDIAN
00449 #if !defined (CS_LITTLE_ENDIAN) && !defined (CS_BIG_ENDIAN)
00450 #  error No CS_XXX_ENDIAN macro defined in your OS-specific csosdefs.h!
00451 #endif
00452 
00453 // Adjust some definitions contained in volatile.h
00454 #if defined (PROC_X86) && !defined (DO_NASM)
00455 #  undef NO_ASSEMBLER
00456 #  define NO_ASSEMBLER
00457 #endif
00458 
00459 #if !defined (PROC_X86) || defined (NO_ASSEMBLER)
00460 #  undef DO_MMX
00461 #  undef DO_NASM
00462 #endif
00463 
00464 // Use fast QInt and QRound on CPUs that are known to support it
00465 #if !defined (CS_NO_IEEE_OPTIMIZATIONS)
00466 #  if !defined (CS_IEEE_DOUBLE_FORMAT)
00467 #    if defined (PROC_X86) || defined (PROC_M68K)
00468 #      define CS_IEEE_DOUBLE_FORMAT
00469 #    endif
00470 #  endif
00471 #endif
00472 
00474 extern void (*fatal_exit) (int errorcode, bool canreturn);
00475 
00476 #endif // __CS_CSSYSDEFS_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000