SystemCall run(block) can now exit the run if it returns false
[io/quag.git] / libs / basekit / source / Common.h
blob9072f679d655458918cc3027c95b564452773880
2 /*
3 docCopyright("Steve Dekorte", 2002)
4 docLicense("BSD revised")
5 docDescription("This is a header that all other source files should include.")
6 */
8 /*
9 These defines are helpful for doing OS specific checks in the code
12 #ifndef IOCOMMON_DEFINED
13 #define IOCOMMON_DEFINED 1
16 /*#define LOW_MEMORY_SYSTEM 1*/
17 #include <stdlib.h>
18 #include <string.h>
19 #include <stddef.h>
22 #if defined (__SVR4) && defined (__sun)
23 #include <inttypes.h>
24 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
25 #include <inttypes.h>
26 #elif !defined(__SYMBIAN32__) && !defined(_MSC_VER) && !defined(__NeXT__)
27 #include <stdint.h>
28 #else
29 typedef unsigned char uint8_t;
30 typedef signed char int8_t;
31 typedef unsigned short uint16_t;
32 typedef signed short int16_t;
33 typedef unsigned long uint32_t;
34 typedef signed long int32_t;
36 typedef unsigned long uint64_t;
37 typedef signed long int64_t;
39 typedef unsigned long long uint64_t;
40 typedef long long int64_t;
41 #endif
43 /* Windows stuff */
45 #if defined(WIN32) || defined(__WINS__) || defined(__MINGW32__) || defined(_MSC_VER)
46 #define inline __inline
47 #define snprintf _snprintf
48 #define usleep(x) Sleep(((x)+999)/1000)
50 #define HAS_FIBERS 1
52 #define ON_WINDOWS 1
54 // Enable fibers
55 #define _WIN32_WINNT 0x0400
57 // this also includes windows.h
58 #include <winsock2.h>
60 #if !defined(__MINGW32__)
61 #if defined(BUILDING_BASEKIT_DLL) || defined(BUILDING_IOVMALL_DLL)
62 #define BASEKIT_API __declspec(dllexport)
63 #else
64 #define BASEKIT_API __declspec(dllimport)
65 #endif
66 #else
67 #define BASEKIT_API
68 #endif
70 #ifndef _SYS_STDINT_H_
71 #include "PortableStdint.h"
72 #endif
75 #if !defined(__MINGW32__)
76 /* disable compile warnings which are always treated
77 as errors in my dev settings */
79 #pragma warning( disable : 4244 )
80 /* warning C4244: 'function' : conversion from 'double ' to 'int ', possible loss of data */
82 /*#pragma warning( disable : 4090 ) */
83 /* warning C4090: 'function' : different 'const' qualifiers */
85 /*#pragma warning( disable : 4024 )*/
86 /* warning C4024: different types for formal and actual parameter */
88 /*#pragma warning( disable : 4761 ) */
89 /* warning C4761: integral size mismatch in argument; conversion supplied */
91 /*#pragma warning( disable : 4047 ) */
92 /* warning C4047: '=' : 'char *' differs in levels of indirection from 'int ' */
93 #define ARCHITECTURE_x86 1
94 #endif
96 /* io_malloc, io_realloc, io_free undefined */
97 #if !defined(__SYMBIAN32__)
98 #include <memory.h>
100 /* strlen undefined */
101 #include <string.h>
102 #include <malloc.h> /* for calloc */
103 #endif
104 #else
106 // Not on windows so define this away
107 #define BASEKIT_API
109 #endif
112 [DBCS Enabling]
114 DBCS (Short for Double-Byte Character Set), a character set that uses two-byte (16-bit) characters. Some languages, such as Chinese, Japanese and Korean (CJK), have writing schemes with many different characters that cannot be represented with single-byte codes such as ASCII and EBCDIC.
116 In CJK world, CES (Character Encoding Scheme) and CCS (Coded Character Set) are actually different concept(one CES may contain multiple CCS).
117 For example, EUC-JP is a CES which includes CCS of ASCII and JIS X 0208 (optionally JIS X 0201 Kana and JIS X 0212).
119 In Japanese (because I am Japanese),
120 While EUC-JP and UTF-8 Map ASCII unchanged, ShiftJIS not (However ShiftJIS is de facto standard in Japan). For example, {0x95, 0x5c} represents one character. in ASCII, second byte(0x5c) is back slash character.
124 check whether double-byte character. supported only ShiftJIS.
125 if you want to use ShiftJIS characters in string literal, set compiler option -DDBCS_ENABLED=1.
128 #if DBCS_ENABLED
129 #define ismbchar(c) ISSJIS((unsigned char)c)
130 #define mbcharlen(c) 2
131 #define ISSJIS(c) ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc))
132 #else
133 #define ismbchar(c) 0
134 #define mbcharlen(c) 1
135 #endif /* DBCS_ENABLED */
137 #ifdef __cplusplus
138 extern "C" {
139 #endif
141 //#define IO_CHECK_ALLOC
143 #ifdef IO_CHECK_ALLOC
144 BASEKIT_API size_t io_memsize(void *ptr);
146 #define io_malloc(size) io_real_malloc(size, __FILE__, __LINE__)
147 BASEKIT_API void *io_real_malloc(size_t size, char *file, int line);
149 #define io_calloc(count, size) io_real_calloc(count, size, __FILE__, __LINE__)
150 BASEKIT_API void *io_real_calloc(size_t count, size_t size, char *file, int line);
152 #define io_realloc(ptr, size) io_real_realloc(ptr, size, __FILE__, __LINE__)
153 BASEKIT_API void *io_real_realloc(void *ptr, size_t newSize, char *file, int line);
155 BASEKIT_API void io_free(void *ptr);
156 BASEKIT_API void io_show_mem(char *s);
157 BASEKIT_API size_t io_maxAllocatedBytes(void);
158 BASEKIT_API void io_resetMaxAllocatedBytes(void);
159 BASEKIT_API size_t io_frees(void);
160 BASEKIT_API size_t io_allocs(void);
161 BASEKIT_API size_t io_allocatedBytes(void);
163 BASEKIT_API void io_showUnfreed(void);
164 #else
165 #define io_memsize
166 #define io_malloc malloc
167 #define io_calloc calloc
168 #define io_realloc io_freerealloc
169 #define io_free free
170 #define io_show_mem
172 #define io_maxAllocatedBytes() 0
173 #define io_frees() 0
174 #define io_allocs() 0
175 #define io_allocatedBytes() 0
176 #define io_resetMaxAllocatedBytes()
177 #endif
179 BASEKIT_API void *cpalloc(const void *p, size_t size);
180 BASEKIT_API void *io_freerealloc(void *p, size_t size);
182 #ifdef __cplusplus
184 #endif
186 #endif