]> pd.if.org Git - pdclib/blob - platform/example/internals/_PDCLIB_config.h
Porting current working set from CVS.
[pdclib] / platform / example / internals / _PDCLIB_config.h
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* Internal PDCLib configuration <_PDCLIB_config.h>
6    (Generic Template)
7
8    This file is part of the Public Domain C Library (PDCLib).
9    Permission is granted to use, modify, and / or redistribute at will.
10 */
11
12 /* -------------------------------------------------------------------------- */
13 /* Misc                                                                       */
14 /* -------------------------------------------------------------------------- */
15
16 /* The character (sequence) your platform uses as newline.                    */
17 #define _PDCLIB_endl "\n"
18
19 /* exit() can signal success to the host environment by the value of zero or  */
20 /* the constant EXIT_SUCCESS. Failure is signaled by EXIT_FAILURE. Note that  */
21 /* any other return value is "implementation-defined", i.e. your environment  */
22 /* is not required to handle it gracefully. Set your definitions here.        */
23 #define _PDCLIB_SUCCESS 0
24 #define _PDCLIB_FAILURE -1
25
26 /* qsort() in <stdlib.h> requires a function that swaps two memory areas.     */
27 /* Below is a naive implementation that can be improved significantly for     */
28 /* specific platforms, e.g. by swapping int instead of char.                  */
29 #define _PDCLIB_memswp( i, j, size ) char tmp; do { tmp = *i; *i++ = *j; *j++ = tmp; } while ( --size );
30
31 /* Define this to some compiler directive that can be written after the       */
32 /* parameter list of a function declaration to indicate the function does     */
33 /* never return. If your compiler does not support such a directive, define   */
34 /* to nothing. (This is to avoid warnings with the exit functions under GCC.) */
35 #define _PDCLIB_NORETURN __attribute__(( noreturn ))
36
37 /* -------------------------------------------------------------------------- */
38 /* Integers                                                                   */
39 /* -------------------------------------------------------------------------- */
40 /* Assuming 8-bit char, two's-complement architecture here. 'short' being     */
41 /* 16 bit, 'int' being either 16, 32 or 64 bit, 'long' being either 32 or 64  */
42 /* bit (but 64 bit only if 'int' is 32 bit), and 'long long' being 64 bit if  */
43 /* 'long' is not, 64 or 128 bit otherwise.                                    */
44 /* Author is quite willing to support other systems but would like to hear of */
45 /* interest in such support and details on the to-be-supported architecture   */
46 /* first, before going to lengths about it.                                   */
47 /* -------------------------------------------------------------------------- */
48
49 /* Comment out (or delete) the line below if your 'char' type is unsigned.    */
50 #define _PDCLIB_CHAR_SIGNED 1
51
52 /* Width of the integer types short, int, long, and long long, in bytes.      */
53 /* SHRT == 2, INT >= SHRT, LONG >= INT >= 4, LLONG >= LONG - check your       */
54 /* compiler manuals.                                                          */
55 #define _PDCLIB_SHRT_BYTES  2
56 #define _PDCLIB_INT_BYTES   4
57 #define _PDCLIB_LONG_BYTES  4
58 #define _PDCLIB_LLONG_BYTES 8
59
60 /* <stdlib.h> defines the div() function family that allows taking quotient   */
61 /* and remainder of an integer division in one operation. Many platforms      */
62 /* support this in hardware / opcode, and the standard permits ordering of    */
63 /* the return structure in any way to fit the hardware. That is why those     */
64 /* structs can be configured here.                                            */
65
66 struct _PDCLIB_div_t
67 {
68     int quot;
69     int rem;
70 };
71
72 struct _PDCLIB_ldiv_t
73 {
74     long int quot;
75     long int rem;
76 };
77
78 struct _PDCLIB_lldiv_t
79 {
80     long long int quot;
81     long long int rem;
82 };
83
84 /* -------------------------------------------------------------------------- */
85 /* <stdint.h> defines a set of integer types that are of a minimum width, and */
86 /* "usually fastest" on the system. (If, for example, accessing a single char */
87 /* requires the CPU to access a complete int and then mask out the char, the  */
88 /* "usually fastest" type of at least 8 bits would be int, not char.)         */
89 /* If you do not have information on the relative performance of the types,   */
90 /* the standard allows you to define any type that meets minimum width and    */
91 /* signedness requirements.                                                   */
92 /* The defines below are just configuration for the real typedefs and limit   */
93 /* definitions done in <_PDCLIB_int.h>. The uppercase define shall be either  */
94 /* SHRT, INT, LONG, or LLONG (telling which values to use for the *_MIN and   */
95 /* *_MAX limits); the lowercase define either short, int, long, or long long  */
96 /* (telling the actual type to use).                                          */
97 /* If you require a non-standard datatype to define the "usually fastest"     */
98 /* types, PDCLib as-is doesn't support that. Please contact the author with   */
99 /* details on your platform in that case, so support can be added.            */
100 /* -------------------------------------------------------------------------- */
101
102 #define _PDCLIB_FAST8 INT
103 #define _PDCLIB_fast8 int
104
105 #define _PDCLIB_FAST16 INT
106 #define _PDCLIB_fast16 int
107
108 #define _PDCLIB_FAST32 INT
109 #define _PDCLIB_fast32 int
110
111 #define _PDCLIB_FAST64 LLONG
112 #define _PDCLIB_fast64 long long
113
114 /* -------------------------------------------------------------------------- */
115 /* What follows are a couple of "special" typedefs and their limits. Again,   */
116 /* the actual definition of the limits is done in <_PDCLIB_int.h>, and the    */
117 /* defines here are merely "configuration". See above for details.            */
118 /* -------------------------------------------------------------------------- */
119
120 /* The result type of substracting two pointers */
121 #define _PDCLIB_ptrdiff int
122 #define _PDCLIB_PTRDIFF INT
123
124 /* An integer type that can be accessed as atomic entity (think asynchronous
125    interrupts). The type itself is not defined in a freestanding environment,
126    but its limits are. (Don't ask.)
127 */
128 #define _PDCLIB_SIG_ATOMIC INT
129
130 /* Result type of the 'sizeof' operator (must be unsigned) */
131 #define _PDCLIB_size unsigned int
132 #define _PDCLIB_SIZE UINT
133
134 /* Large enough an integer to hold all character codes of the largest supported
135    locale.
136 */
137 #define _PDCLIB_wchar unsigned short 
138 #define _PDCLIB_WCHAR USHRT
139
140 #define _PDCLIB_intptr int
141 #define _PDCLIB_INTPTR INT
142
143 /* Largest supported integer type. Implementation note: see _PDCLIB_atomax(). */
144 #define _PDCLIB_intmax long long int
145 #define _PDCLIB_INTMAX LLINT
146 /* You are also required to state the literal suffix for the intmax type      */
147 #define _PDCLIB_INTMAX_LITERAL ll
148
149 /* -------------------------------------------------------------------------- */
150 /* Floating Point                                                             */
151 /* -------------------------------------------------------------------------- */
152
153 /* Whether the implementation rounds toward zero (0), to nearest (1), toward
154    positive infinity (2), or toward negative infinity (3). (-1) signifies
155    indeterminable rounding, any other value implementation-specific rounding.
156 */
157 #define _PDCLIB_FLT_ROUNDS -1
158
159 /* Whether the implementation uses exact-width precision (0), promotes float
160    to double (1), or promotes float and double to long double (2). (-1)
161    signifies indeterminable behaviour, any other value implementation-specific
162    behaviour.
163 */
164 #define _PDCLIB_FLT_EVAL_METHOD -1
165
166 /* "Number of the decimal digits (n), such that any floating-point number in the
167    widest supported floating type with p(max) radix (b) digits can be rounded to
168    a floating-point number with (n) decimal digits and back again without change
169    to the value p(max) log(10)b if (b) is a power of 10, [1 + p(max) log(10)b]
170    otherwise."
171    64bit IEC 60559 double format (53bit mantissa) is DECIMAL_DIG 17.
172    80bit IEC 60559 double-extended format (64bit mantissa) is DECIMAL_DIG 21.
173 */
174 #define _PDCLIB_DECIMAL_DIG 17
175
176 /* -------------------------------------------------------------------------- */
177 /* Platform-dependent macros defined by the standard headers.                 */
178 /* -------------------------------------------------------------------------- */
179
180 /* The offsetof macro
181    Contract: Expand to an integer constant expression of type size_t, which
182    represents the offset in bytes to the structure member from the beginning
183    of the structure. If the specified member is a bitfield, behaviour is
184    undefined.
185    There is no standard-compliant way to do this.
186    This implementation casts an integer zero to 'pointer to type', and then
187    takes the address of member. This is undefined behaviour but should work on
188    most compilers.
189 */
190 #define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) )
191
192 /* Variable Length Parameter List Handling (<stdarg.h>)
193    The macros defined by <stdarg.h> are highly dependent on the calling
194    conventions used, and you probably have to replace them with builtins of
195    your compiler. The following generic implementation works only for pure
196    stack-based architectures, and only if arguments are aligned to pointer
197    type. Credits to Michael Moody, who contributed this to the Public Domain.
198 */
199
200 /* Internal helper macro. va_round is not part of <stdarg.h>. */
201 #define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) )
202
203 typedef char * _PDCLIB_va_list;
204 #define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) )
205 #define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 )
206 #define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 )
207 #define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 )
208
209 /* -------------------------------------------------------------------------- */
210 /* OS "glue", part 1                                                          */
211 /* These are values and data type definitions that you would have to adapt to */
212 /* the capabilities and requirements of your OS.                              */
213 /* The actual *functions* of the OS interface are declared in _PDCLIB_glue.h. */
214 /* -------------------------------------------------------------------------- */
215
216 /* Memory management */
217
218 /* Set this to the page size of your OS. If your OS does not support paging, set
219    to an appropriate value. (Too small, and malloc() will call the kernel too
220    often. Too large, and you will waste memory.
221 */
222 #define _PDCLIB_PAGESIZE 4096
223
224 /* Set this to the minimum memory node size. Any malloc() for a smaller siz
225    will be satisfied by a malloc() of this size instead.
226 */
227 #define _PDCLIB_MINALLOC 8
228
229 /* I/O */
230
231 /* The unique file descriptor returned by _PDCLIB_open(). */
232 typedef int _PDCLIB_fd_t;
233
234 /* A type in which to store file offsets. See fgetpos() / fsetpos(). */
235 typedef struct
236 {
237     int position;
238     int parse_state;
239 } _PDCLIB_fpos_t;
240
241 /* The mode flags used in calls to _PDCLIB_open(). */
242 enum _PDCLIB_iomode_e
243 {
244     _PDCLIB_io_read     = 1,
245     _PDCLIB_io_write    = 2,
246     _PDCLIB_io_append   = 4,
247     _PDCLIB_io_create   = 8,
248     _PDCLIB_io_truncate = 16,
249 };