Debian Codegraph @

share/libc/wchar.h

raw
1 /**************************************************************************/
2 /* */
3 /* This file is part of Frama-C. */
4 /* */
5 /* Copyright (C) 2007-2022 */
6 /* CEA (Commissariat à l'énergie atomique et aux énergies */
7 /* alternatives) */
8 /* */
9 /* you can redistribute it and/or modify it under the terms of the GNU */
10 /* Lesser General Public License as published by the Free Software */
11 /* Foundation, version 2.1. */
12 /* */
13 /* It is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU Lesser General Public License for more details. */
17 /* */
18 /* See the GNU Lesser General Public License version 2.1 */
19 /* for more details (enclosed in the file licenses/LGPLv2.1). */
20 /* */
21 /**************************************************************************/
22
23 /* ISO C: 7.25 */
24 #ifndef __FC_WCHAR_H
25 #define __FC_WCHAR_H
26
27 #include "features.h"
28 __PUSH_FC_STDLIB
29 #include "__fc_define_wchar_t.h"
30 #include "__fc_define_wint_t.h"
31 #include "__fc_define_size_t.h"
32 #include "__fc_define_file.h"
33 #include "__fc_string_axiomatic.h"
34
35 // Include <stdint.h> to retrieve definitions such as WCHAR_MIN and WINT_MAX,
36 // required by ISO C (and not necessarily respected by the glibc).
37 // Note that POSIX does not specify that all symbols in <stdint.h> can be
38 // made visible in wchar.h, but in practice this should be fine.
39 #include "stdint.h"
40
41 // ISO C requires the tag 'struct tm' (as declared in <time.h>) to be declared.
42 #include "time.h"
43
44 #include "string.h"
45
46 __BEGIN_DECLS
47
48 #ifndef WEOF
49 #define WEOF __FC_WEOF
50 #endif
51
52 /*@
53 requires valid:
54 valid_read_or_empty((char*)s, (size_t)(sizeof(wchar_t)*n))
55 || \valid_read(((unsigned char*)s)+(0..wmemchr_off(s,c,n)));
56 @ requires initialization:
57 \initialized(s+(0..n - 1))
58 || \initialized(s+(0..wmemchr_off(s,c,n)));
59 @ requires danglingness:
60 non_escaping(s, (size_t)(sizeof(wchar_t)*n))
61 || non_escaping(s, (size_t)(sizeof(wchar_t)*(wmemchr_off(s,c,n)+1)));
62 assigns \result \from s, indirect:s[0 .. n-1], indirect:c, indirect:n;
63 ensures result_null_or_inside_s:
64 \result == \null || \subset (\result, s+(0 .. n-1));
65 */
66 extern wchar_t * wmemchr(const wchar_t *s, wchar_t c, size_t n);
67
68 /*@
69 requires valid_s1: valid_read_or_empty(s1, (size_t)(sizeof(wchar_t)*n));
70 requires valid_s2: valid_read_or_empty(s2, (size_t)(sizeof(wchar_t)*n));
71 requires initialization:s1: \initialized(s1+(0..n-1));
72 requires initialization:s2: \initialized(s2+(0..n-1));
73 requires danglingness:s1: non_escaping(s1, (size_t)(sizeof(wchar_t)*n));
74 requires danglingness:s2: non_escaping(s2, (size_t)(sizeof(wchar_t)*n));
75 assigns \result \from indirect:s1[0 .. n-1], indirect:s2[0 .. n-1], indirect:n;
76 */
77 extern int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n);
78
79 /*@
80 requires valid_dest: valid_or_empty(dest, (size_t)(sizeof(wchar_t)*n));
81 requires valid_src: valid_read_or_empty(src, (size_t)(sizeof(wchar_t)*n));
82 requires separation:dest:src: \separated(dest+(0 .. n-1), src+(0 .. n-1));
83 assigns dest[0 .. n-1] \from src[0 .. n-1], indirect:src, indirect:n;
84 assigns \result \from dest;
85 ensures result_ptr: \result == dest;
86 */
87 extern wchar_t * wmemcpy(wchar_t *restrict dest, const wchar_t *restrict src, size_t n);
88
89 /*@
90 requires valid_src: \valid_read(src+(0..n-1));
91 requires valid_dest: \valid(dest+(0..n-1));
92 assigns dest[0 .. n-1] \from src[0 .. n-1], indirect:src, indirect:n;
93 assigns \result \from dest;
94 ensures result_ptr: \result == dest;
95 */
96 extern wchar_t * wmemmove(wchar_t *dest, const wchar_t *src, size_t n);
97
98 /*@
99 requires valid_wcs: \valid(wcs+(0..n-1));
100 assigns wcs[0 .. n-1] \from wc, indirect:n;
101 assigns \result \from wcs;
102 ensures result_ptr: \result == wcs;
103 ensures initialization:wcs: \initialized(wcs + (0 .. n-1));
104 ensures contents_equal_wc: \subset(wcs[0 .. n-1], wc);
105 */
106 extern wchar_t * wmemset(wchar_t *wcs, wchar_t wc, size_t n);
107
108 /*@
109 requires valid_wstring_src: valid_read_wstring(src);
110 requires valid_wstring_dest: valid_wstring(dest);
111 requires room_for_concatenation: \valid(dest+(wcslen(dest)..wcslen(dest)+wcslen(src)));
112 requires separation:\separated(dest+(0..wcslen(dest)+wcslen(src)),src+(0..wcslen(src)));
113 assigns dest[0 .. ] \from dest[0 .. ], indirect:dest, src[0 .. ], indirect:src;
114 assigns \result \from dest;
115 ensures result_ptr: \result == dest;
116 */
117 extern wchar_t * wcscat(wchar_t *restrict dest, const wchar_t *restrict src);
118
119 /*@
120 requires valid_wstring_src: valid_read_wstring(wcs);
121 assigns \result \from wcs, indirect:wcs[0 ..], indirect:wc;
122 ensures result_null_or_inside_wcs:
123 \result == \null || \subset(\result, wcs+(0..));
124 */
125 extern wchar_t * wcschr(const wchar_t *wcs, wchar_t wc);
126
127 /*@
128 requires valid_wstring_s1: valid_read_wstring(s1); // over-strong
129 requires valid_wstring_s2: valid_read_wstring(s2); // over-strong
130 assigns \result \from indirect:s1[0 .. ], indirect:s2[0 .. ];
131 */
132 extern int wcscmp(const wchar_t *s1, const wchar_t *s2);
133
134 /*@
135 requires valid_wstring_src: valid_read_wstring(src);
136 requires room_wstring: \valid(dest+(0 .. wcslen(src)));
137 requires separation:\separated(dest+(0..wcslen(src)),src+(0..wcslen(src)));
138 assigns dest[0 .. wcslen(src)] \from src[0 .. wcslen(src)], indirect:src;
139 assigns \result \from dest;
140 ensures result_ptr: \result == dest;
141 */
142 extern wchar_t * wcscpy(wchar_t *restrict dest, const wchar_t *restrict src);
143
144 /*@
145 requires valid_wstring_wcs: valid_read_wstring(wcs);
146 requires valid_wstring_accept: valid_read_wstring(accept);
147 assigns \result \from indirect:wcs[0 .. ], indirect:accept[0 .. ];
148 */
149 extern size_t wcscspn(const wchar_t *wcs, const wchar_t *accept);
150
151 // wcslcat is a BSD extension (non-C99, non-POSIX)
152 /*@
153 requires valid_nwstring_src: valid_read_nwstring(src, n);
154 requires valid_wstring_dest: valid_wstring(dest);
155 requires room_for_concatenation: \valid(dest+(wcslen(dest)..wcslen(dest)+\min(wcslen(src), n)));
156 requires separation:\separated(dest+(0..wcslen(dest)+wcslen(src)),src+(0..wcslen(src)));
157 assigns dest[0 .. ] \from dest[0 .. ], indirect:dest, src[0 .. n-1], indirect:src, indirect:n;
158 assigns \result \from indirect:dest[0 .. ], indirect:src[0 .. n-1], indirect:n;
159 */
160 extern size_t wcslcat(wchar_t *restrict dest, const wchar_t *restrict src, size_t n);
161
162 // wcslcpy is a BSD extension (non-C99, non-POSIX)
163 /*@
164 requires valid_wstring_src: valid_read_wstring(src);
165 requires room_nwstring: \valid(dest+(0 .. n));
166 requires separation:dest:src: \separated(dest+(0 .. n-1), src+(0 .. n-1));
167 assigns dest[0 .. n-1] \from src[0 .. n-1], indirect:src, indirect:n;
168 assigns \result \from indirect:dest[0 .. n-1], indirect:dest,
169 indirect:src[0 .. n-1], indirect:src, indirect:n;
170 */
171 extern size_t wcslcpy(wchar_t *dest, const wchar_t *src, size_t n);
172
173 /*@
174 requires valid_string_s: valid_read_wstring(s);
175 assigns \result \from indirect:s[0 .. wcslen(s)];
176 ensures result_is_length: \result == wcslen(s);
177 */
178 extern size_t wcslen(const wchar_t *s);
179
180 /*@
181 requires valid_nwstring_src: valid_read_nwstring(src, n);
182 requires valid_wstring_dest: valid_wstring(dest);
183 requires room_for_concatenation: \valid(dest+(wcslen(dest)..wcslen(dest)+\min(wcslen(src), n)));
184 requires separation:\separated(dest+(0..wcslen(dest)+wcslen(src)),src+(0..wcslen(src)));
185 assigns dest[0 .. ] \from dest[0 .. ], indirect:dest, src[0 .. n-1], indirect:src, indirect:n;
186 assigns \result \from dest;
187 ensures result_ptr: \result == dest;
188 */
189 extern wchar_t * wcsncat(wchar_t *restrict dest, const wchar_t *restrict src, size_t n);
190
191 /*@
192 requires valid_wstring_s1: valid_read_wstring(s1); // over-strong
193 requires valid_wstring_s2: valid_read_wstring(s2); // over-strong
194 assigns \result \from indirect:s1[0 .. n-1], indirect:s2[0 .. n-1], indirect:n;
195 */
196 extern int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n);
197
198 /*@
199 requires valid_wstring_src: valid_read_wstring(src);
200 requires room_nwstring: \valid(dest+(0 .. n-1));
201 requires separation:dest:src: \separated(dest+(0 .. n-1), src+(0 .. n-1));
202 assigns dest[0 .. n-1] \from src[0 .. n-1], indirect:src, indirect:n;
203 assigns \result \from dest;
204 ensures result_ptr: \result == dest;
205 ensures initialization: \initialized(dest+(0 .. n-1));
206 */
207 extern wchar_t * wcsncpy(wchar_t *restrict dest, const wchar_t *restrict src, size_t n);
208
209 /*@
210 requires valid_wstring_wcs: valid_read_wstring(wcs);
211 requires valid_wstring_accept: valid_read_wstring(accept);
212 assigns \result \from wcs, indirect:wcs[0 .. ], indirect:accept[0 .. ];
213 ensures result_null_or_inside_wcs:
214 \result == \null || \subset (\result, wcs+(0 .. ));
215 */
216 extern wchar_t * wcspbrk(const wchar_t *wcs, const wchar_t *accept);
217
218 /*@
219 requires valid_wstring_wcs: valid_read_wstring(wcs);
220 assigns \result \from wcs, indirect:wcs[0 .. wcslen(wcs)], indirect:wc;
221 ensures result_null_or_inside_wcs:
222 \result == \null || \subset (\result, wcs+(0 .. ));
223 */
224 extern wchar_t * wcsrchr(const wchar_t *wcs, wchar_t wc);
225
226 /*@
227 requires valid_wstring_wcs: valid_read_wstring(wcs);
228 requires valid_wstring_accept: valid_read_wstring(accept);
229 assigns \result \from indirect:wcs[0 .. wcslen(wcs)],
230 indirect:accept[0 .. wcslen(accept)];
231 */
232 extern size_t wcsspn(const wchar_t *wcs, const wchar_t *accept);
233
234 /*@
235 requires valid_wstring_haystack: valid_read_wstring(haystack);
236 requires valid_wstring_needle: valid_read_wstring(needle);
237 assigns \result \from haystack, indirect:haystack[0 .. ], indirect:needle[0 .. ];
238 ensures result_null_or_inside_haystack:
239 \result == \null || \subset (\result, haystack+(0 .. ));
240 */
241 extern wchar_t * wcsstr(const wchar_t *haystack, const wchar_t *needle);
242
243 /*@
244 requires room_nwstring: \valid(ws+(0..n-1));
245 requires valid_stream: \valid(stream);
246 assigns ws[0..n-1] \from indirect:n, indirect:*stream;
247 assigns \result \from ws, indirect:n, indirect:*stream;
248 ensures result_null_or_same: \result == \null || \result == ws;
249 ensures terminated_string_on_success:
250 \result != \null ==> valid_wstring(ws);
251 */
252 extern wchar_t *fgetws(wchar_t * restrict ws, int n, FILE * restrict stream);
253
254 /*@
255 // Axiomatic used by the Variadic plugin to generate specifications
256 // for some functions, e.g. swprintf().
257 axiomatic wformat_length {
258 //TODO: this logic function will be extended to handle variadic formats
259 logic integer wformat_length{L}(wchar_t *format);
260 }
261 */
262
263 /*@
264 requires valid_wstring_ws1: valid_read_wstring(ws1);
265 requires valid_wstring_ws2: valid_read_wstring(ws2);
266 assigns \result \from indirect:ws1[0..], indirect:ws2[0..];
267 */
268 extern int wcscasecmp(const wchar_t *ws1, const wchar_t *ws2);
269
270 /* It is unclear whether these are more often in wchar.h or stdio.h */
271
272 extern int fwprintf(FILE * stream, const wchar_t * format, ...);
273
274 extern int swprintf(wchar_t * ws, size_t n, const wchar_t * format, ...);
275
276 extern int wprintf(const wchar_t * format, ...);
277
278
279 extern int wscanf(const wchar_t * format, ...);
280
281 extern int fwscanf(FILE * stream, const wchar_t * format, ...);
282
283 extern int swscanf(const wchar_t * str, const wchar_t * format, ...);
284
285 #ifndef __mbstate_t_defined
286 typedef struct __fc_mbstate_t { int __count; char __value[4]; } mbstate_t;
287 #define __mbstate_t_defined
288 #endif
289
290 __END_DECLS
291
292 __POP_FC_STDLIB
293 #endif