]> pd.if.org Git - pdclib/blob - platform/posix/internals/_PDCLIB_config.h
PDCLIB-2 PDCLIB-8: Implement mbrtowc using mbrtoc32/mbrtoc16 depending upon definitio...
[pdclib] / platform / posix / internals / _PDCLIB_config.h
1 #ifndef _PDCLIB_CONFIG_H
2 #define _PDCLIB_CONFIG_H
3
4 /* Internal PDCLib configuration <_PDCLIB_config.h>
5    (POSIX platform)
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 /* -------------------------------------------------------------------------- */
12 /* Misc                                                                       */
13 /* -------------------------------------------------------------------------- */
14
15 /* The character (sequence) your platform uses as newline.                    */
16 #define _PDCLIB_endl "\n"
17
18 /* exit() can signal success to the host environment by the value of zero or  */
19 /* the constant EXIT_SUCCESS. Failure is signaled by EXIT_FAILURE. Note that  */
20 /* any other return value is "implementation-defined", i.e. your environment  */
21 /* is not required to handle it gracefully. Set your definitions here.        */
22 #define _PDCLIB_SUCCESS 0
23 #define _PDCLIB_FAILURE -1
24
25 /* qsort() in <stdlib.h> requires a function that swaps two memory areas.     */
26 /* Below is a naive implementation that can be improved significantly for     */
27 /* specific platforms, e.g. by swapping int instead of char.                  */
28 #define _PDCLIB_memswp( i, j, size ) char tmp; do { tmp = *i; *i++ = *j; *j++ = tmp; } while ( --size );
29
30 /* The maximum value that errno can be set to. This is used to set the size   */
31 /* of the array in struct lconv (<locale.h>) holding error messages for the   */
32 /* strerror() and perror() functions. (If you change this value because you   */
33 /* are using additional errno values, you *HAVE* to provide appropriate error */
34 /* messages for *ALL* locales.)                                               */
35 /* Default is 4 (0, ERANGE, EDOM, EILSEQ).                                    */
36 #define _PDCLIB_ERRNO_MAX 4
37
38 /* -------------------------------------------------------------------------- */
39 /* Integers                                                                   */
40 /* -------------------------------------------------------------------------- */
41 /* Assuming 8-bit char, two's-complement architecture here. 'short' being     */
42 /* 16 bit, 'int' being either 16, 32 or 64 bit, 'long' being either 32 or 64  */
43 /* bit (but 64 bit only if 'int' is 32 bit), and 'long long' being 64 bit if  */
44 /* 'long' is not, 64 or 128 bit otherwise.                                    */
45 /* Author is quite willing to support other systems but would like to hear of */
46 /* interest in such support and details on the to-be-supported architecture   */
47 /* first, before going to lengths about it.                                   */
48 /* -------------------------------------------------------------------------- */
49
50 /* Comment out (or delete) the line below if your 'char' type is unsigned.    */
51 #define _PDCLIB_CHAR_SIGNED 1
52
53 /* Width of the integer types short, int, long, and long long, in bytes.      */
54 /* SHRT == 2, INT >= SHRT, LONG >= INT >= 4, LLONG >= LONG - check your       */
55 /* compiler manuals.                                                          */
56 #define _PDCLIB_SHRT_BYTES  2
57 #define _PDCLIB_INT_BYTES   4
58 #if defined(_LP64) || defined(__ILP64__)
59     #define _PDCLIB_LONG_BYTES 8
60 #else
61     #define _PDCLIB_LONG_BYTES 4
62 #endif
63 #define _PDCLIB_LLONG_BYTES 8
64
65 // Match Darwin headers
66 #define _PDCLIB_INT64_IS_LLONG
67
68 /* <stdlib.h> defines the div() function family that allows taking quotient   */
69 /* and remainder of an integer division in one operation. Many platforms      */
70 /* support this in hardware / opcode, and the standard permits ordering of    */
71 /* the return structure in any way to fit the hardware. That is why those     */
72 /* structs can be configured here.                                            */
73
74 struct _PDCLIB_div_t
75 {
76     int quot;
77     int rem;
78 };
79
80 struct _PDCLIB_ldiv_t
81 {
82     long int quot;
83     long int rem;
84 };
85
86 struct _PDCLIB_lldiv_t
87 {
88     long long int quot;
89     long long int rem;
90 };
91
92 /* -------------------------------------------------------------------------- */
93 /* <stdint.h> defines a set of integer types that are of a minimum width, and */
94 /* "usually fastest" on the system. (If, for example, accessing a single char */
95 /* requires the CPU to access a complete int and then mask out the char, the  */
96 /* "usually fastest" type of at least 8 bits would be int, not char.)         */
97 /* If you do not have information on the relative performance of the types,   */
98 /* the standard allows you to define any type that meets minimum width and    */
99 /* signedness requirements.                                                   */
100 /* The defines below are just configuration for the real typedefs and limit   */
101 /* definitions done in <_PDCLIB_int.h>. The uppercase define shall be either  */
102 /* SHRT, INT, LONG, or LLONG (telling which values to use for the *_MIN and   */
103 /* *_MAX limits); the lowercase define either short, int, long, or long long  */
104 /* (telling the actual type to use).                                          */
105 /* The third define is the length modifier used for the type in printf() and  */
106 /* scanf() functions (used in <inttypes.h>).                                  */
107 /* If you require a non-standard datatype to define the "usually fastest"     */
108 /* types, PDCLib as-is doesn't support that. Please contact the author with   */
109 /* details on your platform in that case, so support can be added.            */
110 /* -------------------------------------------------------------------------- */
111
112 #define _PDCLIB_FAST8 INT
113 #define _PDCLIB_fast8 int
114 #define _PDCLIB_FAST8_CONV
115
116 #define _PDCLIB_FAST16 INT
117 #define _PDCLIB_fast16 int
118 #define _PDCLIB_FAST16_CONV
119
120 #define _PDCLIB_FAST32 INT
121 #define _PDCLIB_fast32 int
122 #define _PDCLIB_FAST32_CONV
123
124 #define _PDCLIB_FAST64 LLONG
125 #define _PDCLIB_fast64 long long
126 #define _PDCLIB_FAST64_CONV ll
127
128 /* -------------------------------------------------------------------------- */
129 /* What follows are a couple of "special" typedefs and their limits. Again,   */
130 /* the actual definition of the limits is done in <_PDCLIB_int.h>, and the    */
131 /* defines here are merely "configuration". See above for details.            */
132 /* -------------------------------------------------------------------------- */
133
134 /* The result type of substracting two pointers */
135 #define _PDCLIB_ptrdiff long
136 #define _PDCLIB_PTRDIFF LONG
137 #define _PDCLIB_PTR_CONV l
138
139 /* An integer type that can be accessed as atomic entity (think asynchronous
140    interrupts). The type itself is not defined in a freestanding environment,
141    but its limits are. (Don't ask.)
142 */
143 #define _PDCLIB_sig_atomic int
144 #define _PDCLIB_SIG_ATOMIC INT
145
146 /* Result type of the 'sizeof' operator (must be unsigned) */
147 #define _PDCLIB_size unsigned long
148 #define _PDCLIB_SIZE ULONG
149
150 /* Large enough an integer to hold all character codes of the largest supported
151    locale.
152 */
153 #define _PDCLIB_wint  int
154 #define _PDCLIB_wchar int
155 #define _PDCLIB_WCHAR INT
156
157 #define _PDCLIB_intptr long
158 #define _PDCLIB_INTPTR LONG
159
160 /* Largest supported integer type. Implementation note: see _PDCLIB_atomax(). */
161 #define _PDCLIB_intmax long long int
162 #define _PDCLIB_INTMAX LLONG
163 #define _PDCLIB_MAX_CONV ll
164 /* You are also required to state the literal suffix for the intmax type      */
165 #define _PDCLIB_INTMAX_LITERAL ll
166
167 /* <inttypes.h> defines imaxdiv(), which is equivalent to the div() function  */
168 /* family (see further above) with intmax_t as basis.                         */
169
170 struct _PDCLIB_imaxdiv_t
171 {
172     _PDCLIB_intmax quot;
173     _PDCLIB_intmax rem;
174 };
175
176 /* <time.h>: time_t 
177  * The C standard doesn't define what representation of time is stored in 
178  * time_t when returned by time() , but POSIX defines it to be seconds since the
179  * UNIX epoch and most appplications expect that. 
180  *
181  * time_t is also used as the tv_sec member of struct timespec, which *is* 
182  * defined as a linear count of seconds.
183  *
184  * time_t is defined as a "real type", so may be a floating point type, but with
185  * the presence of the nanosecond accurate struct timespec, and with the lack of
186  * any functions for manipulating more accurate values of time_t, this is 
187  * probably not useful.
188  */
189 #define _PDCLIB_time  long
190
191 /* <time.h>: clock_t
192  *
193  * A count of "clock ticks", where the length of a clock tick is unspecified by
194  * the standard. The implementation is required to provide a macro, 
195  * CLOCKS_PER_SEC, which is the number of "clock ticks" which corresponds to one
196  * second.
197  *
198  * clock_t may be any real type (i.e. integral or floating), and its type on
199  * various systems differs. 
200  *
201  * On XSI systems, CLOCKS_PER_SEC must be defined to 1000000
202  */
203 #define _PDCLIB_clock long
204 #define _PDCLIB_CLOCKS_PER_SEC 1000000
205
206 /* <time.h>: TIME_UTC
207  *
208  * The TIME_UTC parameter is passed to the timespec_get function in order to get
209  * the system time in UTC since an implementation defined epoch (not necessarily
210  * the same as that used for time_t). That said, on POSIX the obvious 
211  * implementation of timespec_get for TIME_UTC is to wrap 
212  * clock_gettime(CLOCK_REALTIME, ...), which is defined as time in UTC since the
213  * same epoch.
214  *
215  * This may be any non-zero integer value.
216  */
217 #define _PDCLIB_TIME_UTC 1
218
219 /* -------------------------------------------------------------------------- */
220 /* Floating Point                                                             */
221 /* -------------------------------------------------------------------------- */
222
223 /* Whether the implementation rounds toward zero (0), to nearest (1), toward
224    positive infinity (2), or toward negative infinity (3). (-1) signifies
225    indeterminable rounding, any other value implementation-specific rounding.
226 */
227 #define _PDCLIB_FLT_ROUNDS -1
228
229 /* Whether the implementation uses exact-width precision (0), promotes float
230    to double (1), or promotes float and double to long double (2). (-1)
231    signifies indeterminable behaviour, any other value implementation-specific
232    behaviour.
233 */
234 #define _PDCLIB_FLT_EVAL_METHOD -1
235
236 /* "Number of the decimal digits (n), such that any floating-point number in the
237    widest supported floating type with p(max) radix (b) digits can be rounded to
238    a floating-point number with (n) decimal digits and back again without change
239    to the value p(max) log(10)b if (b) is a power of 10, [1 + p(max) log(10)b]
240    otherwise."
241    64bit IEC 60559 double format (53bit mantissa) is DECIMAL_DIG 17.
242    80bit IEC 60559 double-extended format (64bit mantissa) is DECIMAL_DIG 21.
243 */
244 #define _PDCLIB_DECIMAL_DIG 17
245
246 /* Floating point types
247  *
248  * PDCLib (at present) assumes IEEE 754 floating point formats
249  * The following names are used:
250  *    SINGLE:   IEEE 754 single precision (32-bit)
251  *    DOUBLE:   IEEE 754 double precision (64-bit)
252  *    EXTENDED: IEEE 754 extended precision (80-bit, as x87)
253  */
254 #define _PDCLIB_FLOAT_TYPE   SINGLE
255 #define _PDCLIB_DOUBLE_TYPE  DOUBLE
256 #define _PDCLIB_LDOUBLE_TYPE EXTENDED
257
258 /* -------------------------------------------------------------------------- */
259 /* Platform-dependent macros defined by the standard headers.                 */
260 /* -------------------------------------------------------------------------- */
261
262 /* The offsetof macro
263    Contract: Expand to an integer constant expression of type size_t, which
264    represents the offset in bytes to the structure member from the beginning
265    of the structure. If the specified member is a bitfield, behaviour is
266    undefined.
267    There is no standard-compliant way to do this.
268    This implementation casts an integer zero to 'pointer to type', and then
269    takes the address of member. This is undefined behaviour but should work on
270    most compilers.
271 */
272 #ifdef __GNUC__
273   #define _PDCLIB_offsetof( type, member ) __builtin_offsetof( type, member )
274 #else
275   #define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) )
276 #endif
277
278 /* Variable Length Parameter List Handling (<stdarg.h>)
279    The macros defined by <stdarg.h> are highly dependent on the calling
280    conventions used, and you probably have to replace them with builtins of
281    your compiler.
282 */
283
284 #ifdef __GNUC__
285   typedef __builtin_va_list _PDCLIB_va_list;
286   #define _PDCLIB_va_arg( ap, type ) (__builtin_va_arg( (ap), type ))
287   #define _PDCLIB_va_copy( dest, src ) (__builtin_va_copy( (dest), (src) ))
288   #define _PDCLIB_va_end( ap ) (__builtin_va_end( ap ) )
289   #define _PDCLIB_va_start( ap, parmN ) (__builtin_va_start( (ap), (parmN) ))
290 #elif (defined(__i386__) || defined(__i386) || defined(_M_IX86)) && !(defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64))
291   /* Internal helper macro. va_round is not part of <stdarg.h>. */
292   #define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) )
293
294   typedef char * _PDCLIB_va_list;
295   #define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) )
296   #define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 )
297   #define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 )
298   #define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 )
299 #else
300   #error Compiler/Architecture support please
301 #endif
302
303 /* -------------------------------------------------------------------------- */
304 /* OS "glue", part 1                                                          */
305 /* These are values and data type definitions that you would have to adapt to */
306 /* the capabilities and requirements of your OS.                              */
307 /* The actual *functions* of the OS interface are declared in _PDCLIB_glue.h. */
308 /* -------------------------------------------------------------------------- */
309
310 /* Memory management -------------------------------------------------------- */
311
312 /* Set this to the page size of your OS. If your OS does not support paging, set
313    to an appropriate value. (Too small, and malloc() will call the kernel too
314    often. Too large, and you will waste memory.)
315 */
316 #define _PDCLIB_MALLOC_PAGESIZE 4096
317 #define _PDCLIB_MALLOC_ALIGN 16
318 #define _PDCLIB_MALLOC_GRANULARITY 64*1024
319 #define _PDCLIB_MALLOC_TRIM_THRESHOLD 2*1024*1024
320 #define _PDCLIB_MALLOC_MMAP_THRESHOLD 256*1024
321 #define _PDCLIB_MALLOC_RELEASE_CHECK_RATE 4095
322
323 /* TODO: Better document these */
324
325 /* Locale --------------------------------------------------------------------*/
326
327 /* Locale method. See _PDCLIB_locale.h */
328 #define _PDCLIB_LOCALE_METHOD _PDCLIB_LOCALE_METHOD_TSS
329
330 /* wchar_t encoding */
331 #define _PDCLIB_WCHAR_ENCODING _PDCLIB_WCHAR_ENCODING_UCS4
332
333 /* I/O ---------------------------------------------------------------------- */
334
335 /* The default size for file buffers. Must be at least 256. */
336 #define _PDCLIB_BUFSIZ 1024
337
338 /* The minimum number of files the implementation can open simultaneously. Must
339    be at least 8. Depends largely on how the bookkeeping is done by fopen() /
340    freopen() / fclose(). The example implementation limits the number of open
341    files only by available memory.
342 */
343 #define _PDCLIB_FOPEN_MAX 8
344
345 /* Length of the longest filename the implementation guarantees to support. */
346 #define _PDCLIB_FILENAME_MAX 128
347
348 /* Maximum length of filenames generated by tmpnam(). (See tmpfile.c.) */
349 #define _PDCLIB_L_tmpnam 128
350
351 /* Number of distinct file names that can be generated by tmpnam(). */
352 #define _PDCLIB_TMP_MAX 50
353
354 /* The values of SEEK_SET, SEEK_CUR and SEEK_END, used by fseek().
355    Since at least one platform (POSIX) uses the same symbols for its own "seek"
356    function, we use whatever the host defines (if it does define them).
357 */
358 #define _PDCLIB_SEEK_SET 0
359 #define _PDCLIB_SEEK_CUR 1
360 #define _PDCLIB_SEEK_END 2
361
362 /* The number of characters that can be buffered with ungetc(). The standard
363    guarantees only one (1); anything larger would make applications relying on
364    this capability dependent on implementation-defined behaviour (not good).
365 */
366 #define _PDCLIB_UNGETCBUFSIZE 1
367
368 #endif