00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
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
00098
00099 #include "cssys/csosdefs.h"
00100
00101
00102
00103
00104
00105
00106 #ifdef CS_SYSDEF_PROVIDE_CASE
00107
00108 # ifndef UPPERCASE
00109 # define UPPERCASE(c) ((c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c)
00110 # endif
00111
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
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
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 }
00144 #endif // CS_SYSDEF_PROVIDE_PATH
00145
00146 #ifdef CS_SYSDEF_PROVIDE_TEMP
00147
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
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
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
00189
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
00205
00206
00207 # endif
00208 # endif
00209
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
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
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
00393
00394
00395
00396
00397
00398
00399
00400
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
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
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
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__