]> pd.if.org Git - pdclib/blob - platform/posix/internals/_PDCLIB_config.h
ae30e0a3622f4757cc17ba8a35c7ab0573265c7a
[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 #ifdef __LP64__
125 #define _PDCLIB_FAST64 LONG
126 #define _PDCLIB_fast64 long
127 #define _PDCLIB_FAST64_CONV l
128 #else
129 #define _PDCLIB_FAST64 LLONG
130 #define _PDCLIB_fast64 long long
131 #define _PDCLIB_FAST64_CONV ll
132 #endif
133
134 /* -------------------------------------------------------------------------- */
135 /* What follows are a couple of "special" typedefs and their limits. Again,   */
136 /* the actual definition of the limits is done in <_PDCLIB_int.h>, and the    */
137 /* defines here are merely "configuration". See above for details.            */
138 /* -------------------------------------------------------------------------- */
139
140 /* The result type of substracting two pointers */
141 #define _PDCLIB_ptrdiff long
142 #define _PDCLIB_PTRDIFF LONG
143 #define _PDCLIB_PTR_CONV l
144
145 /* An integer type that can be accessed as atomic entity (think asynchronous
146    interrupts). The type itself is not defined in a freestanding environment,
147    but its limits are. (Don't ask.)
148 */
149 #define _PDCLIB_sig_atomic int
150 #define _PDCLIB_SIG_ATOMIC INT
151
152 /* Result type of the 'sizeof' operator (must be unsigned) */
153 #define _PDCLIB_size unsigned long
154 #define _PDCLIB_SIZE ULONG
155
156 /* Large enough an integer to hold all character codes of the largest supported
157    locale.
158 */
159 #define _PDCLIB_wint  int
160 #define _PDCLIB_wchar int
161 #define _PDCLIB_WCHAR INT
162
163 #define _PDCLIB_intptr long
164 #define _PDCLIB_INTPTR LONG
165
166 /* Largest supported integer type. Implementation note: see _PDCLIB_atomax(). */
167 #define _PDCLIB_intmax long long int
168 #define _PDCLIB_INTMAX LLONG
169 #define _PDCLIB_MAX_CONV ll
170 /* You are also required to state the literal suffix for the intmax type      */
171 #define _PDCLIB_INTMAX_LITERAL ll
172
173 /* <inttypes.h> defines imaxdiv(), which is equivalent to the div() function  */
174 /* family (see further above) with intmax_t as basis.                         */
175
176 struct _PDCLIB_imaxdiv_t
177 {
178     _PDCLIB_intmax quot;
179     _PDCLIB_intmax rem;
180 };
181
182 /* <time.h>: time_t
183  * The C standard doesn't define what representation of time is stored in
184  * time_t when returned by time() , but POSIX defines it to be seconds since the
185  * UNIX epoch and most appplications expect that.
186  *
187  * time_t is also used as the tv_sec member of struct timespec, which *is*
188  * defined as a linear count of seconds.
189  *
190  * time_t is defined as a "real type", so may be a floating point type, but with
191  * the presence of the nanosecond accurate struct timespec, and with the lack of
192  * any functions for manipulating more accurate values of time_t, this is
193  * probably not useful.
194  */
195 #define _PDCLIB_time  long
196
197 /* <time.h>: clock_t
198  *
199  * A count of "clock ticks", where the length of a clock tick is unspecified by
200  * the standard. The implementation is required to provide a macro,
201  * CLOCKS_PER_SEC, which is the number of "clock ticks" which corresponds to one
202  * second.
203  *
204  * clock_t may be any real type (i.e. integral or floating), and its type on
205  * various systems differs.
206  *
207  * On XSI systems, CLOCKS_PER_SEC must be defined to 1000000
208  */
209 #define _PDCLIB_clock long
210 #define _PDCLIB_CLOCKS_PER_SEC 1000000
211
212 /* <time.h>: TIME_UTC
213  *
214  * The TIME_UTC parameter is passed to the timespec_get function in order to get
215  * the system time in UTC since an implementation defined epoch (not necessarily
216  * the same as that used for time_t). That said, on POSIX the obvious
217  * implementation of timespec_get for TIME_UTC is to wrap
218  * clock_gettime(CLOCK_REALTIME, ...), which is defined as time in UTC since the
219  * same epoch.
220  *
221  * This may be any non-zero integer value.
222  */
223 #define _PDCLIB_TIME_UTC 1
224
225 /* -------------------------------------------------------------------------- */
226 /* Floating Point                                                             */
227 /* -------------------------------------------------------------------------- */
228
229 /* Whether the implementation rounds toward zero (0), to nearest (1), toward
230    positive infinity (2), or toward negative infinity (3). (-1) signifies
231    indeterminable rounding, any other value implementation-specific rounding.
232 */
233 #define _PDCLIB_FLT_ROUNDS -1
234
235 /* Whether the implementation uses exact-width precision (0), promotes float
236    to double (1), or promotes float and double to long double (2). (-1)
237    signifies indeterminable behaviour, any other value implementation-specific
238    behaviour.
239 */
240 #define _PDCLIB_FLT_EVAL_METHOD -1
241
242 /* "Number of the decimal digits (n), such that any floating-point number in the
243    widest supported floating type with p(max) radix (b) digits can be rounded to
244    a floating-point number with (n) decimal digits and back again without change
245    to the value p(max) log(10)b if (b) is a power of 10, [1 + p(max) log(10)b]
246    otherwise."
247    64bit IEC 60559 double format (53bit mantissa) is DECIMAL_DIG 17.
248    80bit IEC 60559 double-extended format (64bit mantissa) is DECIMAL_DIG 21.
249 */
250 #define _PDCLIB_DECIMAL_DIG 17
251
252 /* Floating point types
253  *
254  * PDCLib (at present) assumes IEEE 754 floating point formats
255  * The following names are used:
256  *    SINGLE:   IEEE 754 single precision (32-bit)
257  *    DOUBLE:   IEEE 754 double precision (64-bit)
258  *    EXTENDED: IEEE 754 extended precision (80-bit, as x87)
259  */
260 #define _PDCLIB_FLOAT_TYPE   SINGLE
261 #define _PDCLIB_DOUBLE_TYPE  DOUBLE
262 #define _PDCLIB_LDOUBLE_TYPE EXTENDED
263
264 /* -------------------------------------------------------------------------- */
265 /* Platform-dependent macros defined by the standard headers.                 */
266 /* -------------------------------------------------------------------------- */
267
268 /* The offsetof macro
269    Contract: Expand to an integer constant expression of type size_t, which
270    represents the offset in bytes to the structure member from the beginning
271    of the structure. If the specified member is a bitfield, behaviour is
272    undefined.
273    There is no standard-compliant way to do this.
274    This implementation casts an integer zero to 'pointer to type', and then
275    takes the address of member. This is undefined behaviour but should work on
276    most compilers.
277 */
278 #ifdef __GNUC__
279   #define _PDCLIB_offsetof( type, member ) __builtin_offsetof( type, member )
280 #else
281   #define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) )
282 #endif
283
284 /* Variable Length Parameter List Handling (<stdarg.h>)
285    The macros defined by <stdarg.h> are highly dependent on the calling
286    conventions used, and you probably have to replace them with builtins of
287    your compiler.
288 */
289
290 #ifdef __GNUC__
291   typedef __builtin_va_list _PDCLIB_va_list;
292   #define _PDCLIB_va_arg( ap, type ) (__builtin_va_arg( (ap), type ))
293   #define _PDCLIB_va_copy( dest, src ) (__builtin_va_copy( (dest), (src) ))
294   #define _PDCLIB_va_end( ap ) (__builtin_va_end( ap ) )
295   #define _PDCLIB_va_start( ap, parmN ) (__builtin_va_start( (ap), (parmN) ))
296 #elif (defined(__i386__) || defined(__i386) || defined(_M_IX86)) && !(defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64))
297   /* Internal helper macro. va_round is not part of <stdarg.h>. */
298   #define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) )
299
300   typedef char * _PDCLIB_va_list;
301   #define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) )
302   #define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 )
303   #define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 )
304   #define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 )
305 #else
306   #error Compiler/Architecture support please
307 #endif
308
309 /* -------------------------------------------------------------------------- */
310 /* OS "glue", part 1                                                          */
311 /* These are values and data type definitions that you would have to adapt to */
312 /* the capabilities and requirements of your OS.                              */
313 /* The actual *functions* of the OS interface are declared in _PDCLIB_glue.h. */
314 /* -------------------------------------------------------------------------- */
315
316 /* Memory management -------------------------------------------------------- */
317
318 /* Set this to the page size of your OS. If your OS does not support paging, set
319    to an appropriate value. (Too small, and malloc() will call the kernel too
320    often. Too large, and you will waste memory.)
321 */
322 #define _PDCLIB_MALLOC_PAGESIZE 4096
323 #define _PDCLIB_MALLOC_ALIGN 16
324 #define _PDCLIB_MALLOC_GRANULARITY 64*1024
325 #define _PDCLIB_MALLOC_TRIM_THRESHOLD 2*1024*1024
326 #define _PDCLIB_MALLOC_MMAP_THRESHOLD 256*1024
327 #define _PDCLIB_MALLOC_RELEASE_CHECK_RATE 4095
328
329 /* TODO: Better document these */
330
331 /* Locale --------------------------------------------------------------------*/
332
333 /* Locale method. See _PDCLIB_locale.h */
334 #define _PDCLIB_LOCALE_METHOD _PDCLIB_LOCALE_METHOD_TSS
335
336 /* wchar_t encoding */
337 #define _PDCLIB_WCHAR_ENCODING _PDCLIB_WCHAR_ENCODING_UCS4
338
339 /* I/O ---------------------------------------------------------------------- */
340
341 /* The default size for file buffers. Must be at least 256. */
342 #define _PDCLIB_BUFSIZ 1024
343
344 /* The minimum number of files the implementation can open simultaneously. Must
345    be at least 8. Depends largely on how the bookkeeping is done by fopen() /
346    freopen() / fclose(). The example implementation limits the number of open
347    files only by available memory.
348 */
349 #define _PDCLIB_FOPEN_MAX 8
350
351 /* Length of the longest filename the implementation guarantees to support. */
352 #define _PDCLIB_FILENAME_MAX 128
353
354 /* Maximum length of filenames generated by tmpnam(). (See tmpfile.c.) */
355 #define _PDCLIB_L_tmpnam 128
356
357 /* Number of distinct file names that can be generated by tmpnam(). */
358 #define _PDCLIB_TMP_MAX 50
359
360 /* The values of SEEK_SET, SEEK_CUR and SEEK_END, used by fseek().
361    Since at least one platform (POSIX) uses the same symbols for its own "seek"
362    function, we use whatever the host defines (if it does define them).
363 */
364 #define _PDCLIB_SEEK_SET 0
365 #define _PDCLIB_SEEK_CUR 1
366 #define _PDCLIB_SEEK_END 2
367
368 /* The number of characters that can be buffered with ungetc(). The standard
369    guarantees only one (1); anything larger would make applications relying on
370    this capability dependent on implementation-defined behaviour (not good).
371 */
372 #define _PDCLIB_UNGETCBUFSIZE 1
373
374 #endif