P99
p99_libc.h
Go to the documentation of this file.
1 /* This may look like nonsense, but it really is -*- mode: C; coding: utf-8 -*- */
2 /* */
3 /* Except for parts copied from previous work and as explicitly stated below, */
4 /* the authors and copyright holders for this work are as follows: */
5 /* (C) copyright 2013 Bobby */
6 /* (C) copyright 2013-2014 Jens Gustedt, INRIA, France */
7 /* */
8 /* This file is free software; it is part of the P99 project. */
9 /* */
10 /* Licensed under the Apache License, Version 2.0 (the "License"); */
11 /* you may not use this file except in compliance with the License. */
12 /* You may obtain a copy of the License at */
13 /* */
14 /* http://www.apache.org/licenses/LICENSE-2.0 */
15 /* */
16 /* Unless required by applicable law or agreed to in writing, software */
17 /* distributed under the License is distributed on an "AS IS" BASIS, */
18 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
19 /* See the License for the specific language governing permissions and */
20 /* limitations under the License. */
21 /* */
22 #ifndef P99_LIBC_H
23 #define P99_LIBC_H
24 
43 #if defined(__WITH_AVRLIBC__) || defined(__AVR_LIBC_VERSION__)
44 # ifndef __AVR_LIBC_VERSION__
45 # include <avr/version.h>
46 # endif
47 /* Please drop me a line if avr libc one day supports one of the
48  features.that are protected by __AVR_LIBC_VERSION__ */
49 # define P99_AVR_LIBC_SOMEDAY (-2U)
50 # define p00_has_feature_assert_h 1
51 # define p00_has_feature_float_h 1
52 # define p00_has_feature_iso646_h 1
53 # define p00_has_feature_limits_h 1
54 # define p00_has_feature_stdarg_h 1
55 # define p00_has_feature_stdbool_h 1
56 # define p00_has_feature_stddef_h 1
57 # define p00_has_feature_stdint_h 1
58 # define p00_has_feature_ctype_h 1
59 # define p00_has_feature_errno_h 1
60 # define p00_has_feature_stdio_h 1
61 # define p00_has_feature_stdlib_h 1
62 # define p00_has_feature_string_h 1
63 # define p00_has_feature_math_h 1
64 # define p00_has_feature_setjmp_h 1
65 # define P99_CSIN_BUG
66 /* tgmath.h broken in avr-gcc, tries to include unavailable complex.h. */
67 # if (__AVR_LIBC_VERSION__ > P99_AVR_LIBC_SOMEDAY)
68 # undef p00_has_feature_tgmath_h
69 # endif
70 # if __STDC_HOSTED__
71 /* C99 requires this C11 has this conditionally */
72 # if (__AVR_LIBC_VERSION__ > P99_AVR_LIBC_SOMEDAY)
73 # ifndef __STDC_NO_COMPLEX__
74 # define p00_has_feature_complex_h 1
75 # undef P99_CSIN_BUG
76 # endif
77 # endif
78 # if (__AVR_LIBC_VERSION__ > P99_AVR_LIBC_SOMEDAY)
79 # define p00_has_feature_fenv_h 1
80 # endif
81 # define p00_has_feature_inttypes_h 1
82 # if (__AVR_LIBC_VERSION__ > P99_AVR_LIBC_SOMEDAY)
83 # define p00_has_feature_locale_h 1
84 # endif
85 # if (__AVR_LIBC_VERSION__ > P99_AVR_LIBC_SOMEDAY)
86 # define p00_has_feature_signal_h 1
87 # endif
88 /* tgmath.h should be given on the compiler level */
89 # if (__AVR_LIBC_VERSION__ > P99_AVR_LIBC_SOMEDAY)
90 # define p00_has_feature_time_h 1
91 # endif
92 # if (__AVR_LIBC_VERSION__ > P99_AVR_LIBC_SOMEDAY)
93 # define p00_has_feature_wchar_h 1
94 # endif
95 # if (__AVR_LIBC_VERSION__ > P99_AVR_LIBC_SOMEDAY)
96 # define p00_has_feature_wctype_h 1
97 # endif
98 # endif
99 
100 #else
101 /* This is what a standard conforming C library must provide. */
102 # define p00_has_feature_float_h 1
103 # define p00_has_feature_iso646_h 1
104 # define p00_has_feature_limits_h 1
105 # define p00_has_feature_stdarg_h 1
106 # define p00_has_feature_stdbool_h 1
107 # define p00_has_feature_stddef_h 1
108 # define p00_has_feature_stdint_h 1
109 # if __STDC_HOSTED__
110 # define p00_has_feature_assert_h 1
111 /* C99 requires this C11 has this conditionally */
112 # ifndef __STDC_NO_COMPLEX__
113 # define p00_has_feature_complex_h 1
114 # endif
115 # define p00_has_feature_ctype_h 1
116 # define p00_has_feature_errno_h 1
117 # define p00_has_feature_fenv_h 1
118 # define p00_has_feature_inttypes_h 1
119 # define p00_has_feature_locale_h 1
120 # define p00_has_feature_math_h 1
121 # define p00_has_feature_setjmp_h 1
122 # define p00_has_feature_signal_h 1
123 # define p00_has_feature_stdio_h 1
124 # define p00_has_feature_stdlib_h 1
125 # define p00_has_feature_string_h 1
126 /* tgmath.h should be given on the compiler level */
127 # define p00_has_feature_time_h 1
128 # define p00_has_feature_wchar_h 1
129 # define p00_has_feature_wctype_h 1
130 # endif
131 #endif
132 
133 
134 #if p99_has_feature(float_h)
135 # include <float.h>
136 #endif
137 /* For a conforming compiler, this should now have been defined. Set
138  it to "indeterminable" otherwise. */
139 #ifndef FLT_EVAL_METHOD
140 # define FLT_EVAL_METHOD (-1)
141 #endif
142 #if p99_has_feature(iso646_h)
143 # include <iso646.h>
144 #endif
145 #if p99_has_feature(limits_h)
146 # include <limits.h>
147 #endif
148 #if p99_has_feature(stdarg_h)
149 # include <stdarg.h>
150 #endif
151 #if p99_has_feature(stdbool_h)
152 # include <stdbool.h>
153 #endif
154 #if p99_has_feature(stddef_h)
155 # include <stddef.h>
156 #endif
157 #if p99_has_feature(stdint_h)
158 # include <stdint.h>
159 #endif
160 
161 /* This is defined in some header file since C11. Since C11 allows to
162  repeat typedefs as long as they resolve to the same type, this can
163  be done at any place. */
164 typedef size_t rsize_t;
165 
166 #ifndef RSIZE_MAX
167 /* This is the recommended practice if there is no other value
168  available. */
169 # define RSIZE_MAX (SIZE_MAX >> 1)
170 #endif
171 
172 #if p99_has_feature(assert_h)
173 # include <assert.h>
174 #endif
175 #if p99_has_feature(wchar_h)
176 # include <wchar.h>
177 #endif
178 #if p99_has_feature(wctype_h)
179 # include <wctype.h>
180 #endif
181 
182 /* Look for C11 features that are typically provided by a C library
183  and not by the compiler itself */
184 #ifdef __GLIBC__
185 # if __GLIBC_PREREQ(2, 19)
186 # define p00_has_feature_aligned_alloc 1
187 # define p00_has_extension_aligned_alloc 1
188 # define p00_has_feature_uchar_h 1
189 # else
190 # define p00_has_feature_uchar_h 0
191 # define __STDC_NO_THREADS__ 1
192 # endif
193 #endif
194 
195 #if __STDC_VERSION__ > 201100L
196 # define p00_has_feature_stdalign_h 1
197 # define p00_has_feature_stdnoreturn_h 1
198 # ifndef __STDC_NO_ATOMICS__
199 # define p00_has_feature_stdatomic_h 1
200 # endif
201 # ifndef __STDC_NO_THREADS__
202 # define p00_has_feature_threads_h 1
203 # endif
204 #endif
205 
206 
207 /* implement emulation of some C11 features */
208 #if p99_has_feature(stdalign_h)
209 # include <stdalign.h>
210 #endif
211 #if p99_has_feature(stdnoreturn_h)
212 # include <stdnoreturn.h>
213 #endif
214 /* end C11 emulation support */
215 
216 #if p99_has_feature(uchar_h)
217 # include <uchar.h>
218 #else
219 /* Define the unicode character types directly. */
220 typedef uint_least16_t char16_t;
221 typedef uint_least32_t char32_t;
222 #endif /* uchar */
223 
224 
225 #endif
rsize_t
size_t rsize_t
Definition: p99_libc.h:164
char32_t
uint_least32_t char32_t
Definition: p99_libc.h:221
char16_t
uint_least16_t char16_t
Definition: p99_libc.h:220