/src/wxwidgets/include/wx/wxcrtbase.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Name: wx/wxcrtbase.h |
3 | | * Purpose: Type-safe ANSI and Unicode builds compatible wrappers for |
4 | | * CRT functions |
5 | | * Author: Joel Farley, Ove Kaaven |
6 | | * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee |
7 | | * Created: 1998/06/12 |
8 | | * Copyright: (c) 1998-2006 wxWidgets dev team |
9 | | * Licence: wxWindows licence |
10 | | */ |
11 | | |
12 | | /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */ |
13 | | |
14 | | #ifndef _WX_WXCRTBASE_H_ |
15 | | #define _WX_WXCRTBASE_H_ |
16 | | |
17 | | /* ------------------------------------------------------------------------- |
18 | | headers and missing declarations |
19 | | ------------------------------------------------------------------------- */ |
20 | | |
21 | | #include "wx/chartype.h" |
22 | | |
23 | | /* |
24 | | Standard headers we need here. |
25 | | |
26 | | NB: don't include any wxWidgets headers here because almost all of them |
27 | | include this one! |
28 | | |
29 | | NB2: User code should include wx/crt.h instead of including this |
30 | | header directly. |
31 | | |
32 | | */ |
33 | | |
34 | | #include <stdio.h> |
35 | | #include <string.h> |
36 | | #include <ctype.h> |
37 | | #include <wctype.h> |
38 | | #include <time.h> |
39 | | |
40 | | #if defined(__WINDOWS__) |
41 | | #include <io.h> |
42 | | #endif |
43 | | |
44 | | #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS |
45 | | char *strtok_r(char *, const char *, char **); |
46 | | #endif |
47 | | |
48 | | /* |
49 | | Traditional MinGW doesn't declare isascii() in strict ANSI mode and we can't |
50 | | declare it here ourselves as it's an inline function, so use our own |
51 | | replacement instead. |
52 | | */ |
53 | | #ifndef isascii |
54 | | #if defined(wxNEEDS_STRICT_ANSI_WORKAROUNDS) |
55 | | #define wxNEED_ISASCII |
56 | | #endif |
57 | | #endif /* isascii */ |
58 | | |
59 | | #ifdef wxNEED_ISASCII |
60 | | inline int isascii(int c) { return (unsigned)c < 0x80; } |
61 | | |
62 | | // Avoid further (re)definitions of it. |
63 | | #define isascii isascii |
64 | | #endif |
65 | | |
66 | | /* string.h functions */ |
67 | | |
68 | | #ifdef wxNEED_STRDUP |
69 | | WXDLLIMPEXP_BASE char *strdup(const char* s); |
70 | | #endif |
71 | | |
72 | | |
73 | | /* ------------------------------------------------------------------------- |
74 | | UTF-8 locale handling |
75 | | ------------------------------------------------------------------------- */ |
76 | | |
77 | | #ifdef __cplusplus |
78 | | /* flag indicating whether the current locale uses UTF-8 or not; must be |
79 | | updated every time the locale is changed! */ |
80 | | #if wxUSE_UTF8_LOCALE_ONLY |
81 | | #define wxLocaleIsUtf8 true |
82 | | #else |
83 | | extern WXDLLIMPEXP_BASE bool wxLocaleIsUtf8; |
84 | | #endif |
85 | | /* function used to update the flag: */ |
86 | | extern WXDLLIMPEXP_BASE void wxUpdateLocaleIsUtf8(); |
87 | | #endif /* __cplusplus */ |
88 | | |
89 | | |
90 | | /* ------------------------------------------------------------------------- |
91 | | string.h |
92 | | ------------------------------------------------------------------------- */ |
93 | | |
94 | | #define wxCRT_StrcatA strcat |
95 | 0 | #define wxCRT_StrchrA strchr |
96 | | #define wxCRT_StrcmpA strcmp |
97 | | #define wxCRT_StrcpyA strcpy |
98 | | #define wxCRT_StrcspnA strcspn |
99 | 7.98k | #define wxCRT_StrlenA strlen |
100 | | #define wxCRT_StrncatA strncat |
101 | | #define wxCRT_StrncmpA strncmp |
102 | | #define wxCRT_StrncpyA strncpy |
103 | | #define wxCRT_StrpbrkA strpbrk |
104 | | #define wxCRT_StrrchrA strrchr |
105 | | #define wxCRT_StrspnA strspn |
106 | | #define wxCRT_StrstrA strstr |
107 | | |
108 | | #define wxCRT_StrcatW wcscat |
109 | 0 | #define wxCRT_StrchrW wcschr |
110 | | #define wxCRT_StrcmpW wcscmp |
111 | 0 | #define wxCRT_StrcpyW wcscpy |
112 | | #define wxCRT_StrcspnW wcscspn |
113 | | #define wxCRT_StrncatW wcsncat |
114 | | #define wxCRT_StrncmpW wcsncmp |
115 | 0 | #define wxCRT_StrncpyW wcsncpy |
116 | 0 | #define wxCRT_StrpbrkW wcspbrk |
117 | | #define wxCRT_StrrchrW wcsrchr |
118 | | #define wxCRT_StrspnW wcsspn |
119 | 0 | #define wxCRT_StrstrW wcsstr |
120 | | |
121 | | #define wxCRT_StrcollA strcoll |
122 | | #define wxCRT_StrxfrmA strxfrm |
123 | | |
124 | | #define wxCRT_StrcollW wcscoll |
125 | | #define wxCRT_StrxfrmW wcsxfrm |
126 | | |
127 | | /* Almost all compilers have strdup(), but VC++ and MinGW call it _strdup(). |
128 | | And we need to declare it manually for MinGW in strict ANSI mode. */ |
129 | | #if defined(__VISUALC__) |
130 | | #define wxCRT_StrdupA _strdup |
131 | | #elif defined(__MINGW32__) |
132 | | wxDECL_FOR_STRICT_MINGW32(char*, _strdup, (const char *)) |
133 | | #define wxCRT_StrdupA _strdup |
134 | | #else |
135 | 0 | #define wxCRT_StrdupA strdup |
136 | | #endif |
137 | | |
138 | | /* Windows compilers provide _wcsdup() except for (old) Cygwin */ |
139 | | #if defined(__WINDOWS__) && !defined(__CYGWIN__) |
140 | | wxDECL_FOR_STRICT_MINGW32(wchar_t*, _wcsdup, (const wchar_t*)) |
141 | | #define wxCRT_StrdupW _wcsdup |
142 | | #elif defined(HAVE_WCSDUP) |
143 | | #define wxCRT_StrdupW wcsdup |
144 | | #endif |
145 | | |
146 | | #ifdef wxHAVE_TCHAR_SUPPORT |
147 | | /* we surely have wchar_t if we have TCHAR have wcslen() */ |
148 | | #ifndef HAVE_WCSLEN |
149 | | #define HAVE_WCSLEN |
150 | | #endif |
151 | | #endif /* wxHAVE_TCHAR_SUPPORT */ |
152 | | |
153 | | #ifdef HAVE_WCSLEN |
154 | 4.11k | #define wxCRT_StrlenW wcslen |
155 | | #endif |
156 | | |
157 | 0 | #define wxCRT_StrtodA strtod |
158 | | #define wxCRT_StrtolA strtol |
159 | | #define wxCRT_StrtoulA strtoul |
160 | | |
161 | | #ifdef __ANDROID__ // these functions are broken on android |
162 | | |
163 | | WXDLLIMPEXP_BASE double android_wcstod(const wchar_t *nptr, wchar_t **endptr); |
164 | | WXDLLIMPEXP_BASE long android_wcstol(const wchar_t *nptr, wchar_t **endptr, int base); |
165 | | WXDLLIMPEXP_BASE unsigned long android_wcstoul(const wchar_t *nptr, wchar_t **endptr, int base); |
166 | | |
167 | | #define wxCRT_StrtodW android_wcstod |
168 | | #define wxCRT_StrtolW android_wcstol |
169 | | #define wxCRT_StrtoulW android_wcstoul |
170 | | #else |
171 | 0 | #define wxCRT_StrtodW wcstod |
172 | | #define wxCRT_StrtolW wcstol |
173 | | #define wxCRT_StrtoulW wcstoul |
174 | | #endif |
175 | | |
176 | | #ifdef __VISUALC__ |
177 | | #define wxCRT_StrtollA _strtoi64 |
178 | | #define wxCRT_StrtoullA _strtoui64 |
179 | | #define wxCRT_StrtollW _wcstoi64 |
180 | | #define wxCRT_StrtoullW _wcstoui64 |
181 | | #else |
182 | | wxDECL_FOR_STRICT_MINGW32(long long, strtoll, (const char*, char**, int)) |
183 | | wxDECL_FOR_STRICT_MINGW32(unsigned long long, strtoull, (const char*, char**, int)) |
184 | | |
185 | | #define wxCRT_StrtollA strtoll |
186 | | #define wxCRT_StrtoullA strtoull |
187 | | #define wxCRT_StrtollW wcstoll |
188 | | #define wxCRT_StrtoullW wcstoull |
189 | | #endif |
190 | | |
191 | | /* |
192 | | Only MSVC provides strnlen() and wcsnlen() functions under Windows. |
193 | | */ |
194 | | #ifdef __VISUALC__ |
195 | | #ifndef HAVE_STRNLEN |
196 | | #define HAVE_STRNLEN |
197 | | #endif |
198 | | #ifndef HAVE_WCSNLEN |
199 | | #define HAVE_WCSNLEN |
200 | | #endif |
201 | | #endif |
202 | | |
203 | | #ifdef HAVE_STRNLEN |
204 | 0 | #define wxCRT_StrnlenA strnlen |
205 | | #endif |
206 | | |
207 | | #ifdef HAVE_WCSNLEN |
208 | | /* |
209 | | When using MinGW, wcsnlen() is not declared, but is still found by |
210 | | configure -- just declare it in this case as it seems better to use it |
211 | | if it's available (see https://sourceforge.net/p/mingw/bugs/2332/) |
212 | | */ |
213 | | wxDECL_FOR_MINGW32_ALWAYS(size_t, wcsnlen, (const wchar_t*, size_t)) |
214 | | |
215 | | #define wxCRT_StrnlenW wcsnlen |
216 | | #endif |
217 | | |
218 | | /* define wxCRT_StricmpA/W and wxCRT_StrnicmpA/W for various compilers */ |
219 | | #if defined(__VISUALC__) || defined(__MINGW32__) |
220 | | /* |
221 | | Due to MinGW 5.3 bug (https://sourceforge.net/p/mingw/bugs/2322/), |
222 | | _stricmp() and _strnicmp() are not declared in its standard headers |
223 | | when compiling without optimizations. Work around this by always |
224 | | declaring them ourselves (notice that if/when this bug were fixed, we'd |
225 | | still need to use wxDECL_FOR_STRICT_MINGW32() for them here. |
226 | | */ |
227 | | wxDECL_FOR_MINGW32_ALWAYS(int, _stricmp, (const char*, const char*)) |
228 | | wxDECL_FOR_MINGW32_ALWAYS(int, _strnicmp, (const char*, const char*, size_t)) |
229 | | |
230 | | #define wxCRT_StricmpA _stricmp |
231 | | #define wxCRT_StrnicmpA _strnicmp |
232 | | #elif defined(__UNIX__) |
233 | | #define wxCRT_StricmpA strcasecmp |
234 | | #define wxCRT_StrnicmpA strncasecmp |
235 | | /* #else -- use wxWidgets implementation */ |
236 | | #endif |
237 | | |
238 | | #ifdef __VISUALC__ |
239 | | #define wxCRT_StricmpW _wcsicmp |
240 | | #define wxCRT_StrnicmpW _wcsnicmp |
241 | | #elif defined(__UNIX__) |
242 | | #ifdef HAVE_WCSCASECMP |
243 | | #define wxCRT_StricmpW wcscasecmp |
244 | | #endif |
245 | | #ifdef HAVE_WCSNCASECMP |
246 | | #define wxCRT_StrnicmpW wcsncasecmp |
247 | | #endif |
248 | | /* #else -- use wxWidgets implementation */ |
249 | | #endif |
250 | | |
251 | | #ifdef HAVE_STRTOK_R |
252 | | #define wxCRT_StrtokA(str, sep, last) strtok_r(str, sep, last) |
253 | | #endif |
254 | | /* FIXME-UTF8: detect and use wcstok() if available for wxCRT_StrtokW */ |
255 | | |
256 | | /* these are extern "C" because they are used by regex lib: */ |
257 | | #ifdef __cplusplus |
258 | | extern "C" { |
259 | | #endif |
260 | | |
261 | | #ifndef wxCRT_StrlenW |
262 | | WXDLLIMPEXP_BASE size_t wxCRT_StrlenW(const wchar_t *s); |
263 | | #endif |
264 | | |
265 | | #ifndef wxCRT_StrncmpW |
266 | | WXDLLIMPEXP_BASE int wxCRT_StrncmpW(const wchar_t *s1, const wchar_t *s2, size_t n); |
267 | | #endif |
268 | | |
269 | | #ifdef __cplusplus |
270 | | } |
271 | | #endif |
272 | | |
273 | | #ifndef wxCRT_StrcatW |
274 | | WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcatW(wchar_t *dest, const wchar_t *src); |
275 | | #endif |
276 | | |
277 | | #ifndef wxCRT_StrchrW |
278 | | WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrchrW(const wchar_t *s, wchar_t c); |
279 | | #endif |
280 | | |
281 | | #ifndef wxCRT_StrcmpW |
282 | | WXDLLIMPEXP_BASE int wxCRT_StrcmpW(const wchar_t *s1, const wchar_t *s2); |
283 | | #endif |
284 | | |
285 | | #ifndef wxCRT_StrcollW |
286 | | WXDLLIMPEXP_BASE int wxCRT_StrcollW(const wchar_t *s1, const wchar_t *s2); |
287 | | #endif |
288 | | |
289 | | #ifndef wxCRT_StrcpyW |
290 | | WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcpyW(wchar_t *dest, const wchar_t *src); |
291 | | #endif |
292 | | |
293 | | #ifndef wxCRT_StrcspnW |
294 | | WXDLLIMPEXP_BASE size_t wxCRT_StrcspnW(const wchar_t *s, const wchar_t *reject); |
295 | | #endif |
296 | | |
297 | | #ifndef wxCRT_StrncatW |
298 | | WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncatW(wchar_t *dest, const wchar_t *src, size_t n); |
299 | | #endif |
300 | | |
301 | | #ifndef wxCRT_StrncpyW |
302 | | WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncpyW(wchar_t *dest, const wchar_t *src, size_t n); |
303 | | #endif |
304 | | |
305 | | #ifndef wxCRT_StrpbrkW |
306 | | WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrpbrkW(const wchar_t *s, const wchar_t *accept); |
307 | | #endif |
308 | | |
309 | | #ifndef wxCRT_StrrchrW |
310 | | WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrrchrW(const wchar_t *s, wchar_t c); |
311 | | #endif |
312 | | |
313 | | #ifndef wxCRT_StrspnW |
314 | | WXDLLIMPEXP_BASE size_t wxCRT_StrspnW(const wchar_t *s, const wchar_t *accept); |
315 | | #endif |
316 | | |
317 | | #ifndef wxCRT_StrstrW |
318 | | WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrstrW(const wchar_t *haystack, const wchar_t *needle); |
319 | | #endif |
320 | | |
321 | | #ifndef wxCRT_StrtodW |
322 | | WXDLLIMPEXP_BASE double wxCRT_StrtodW(const wchar_t *nptr, wchar_t **endptr); |
323 | | #endif |
324 | | |
325 | | #ifndef wxCRT_StrtolW |
326 | | WXDLLIMPEXP_BASE long int wxCRT_StrtolW(const wchar_t *nptr, wchar_t **endptr, int base); |
327 | | #endif |
328 | | |
329 | | #ifndef wxCRT_StrtoulW |
330 | | WXDLLIMPEXP_BASE unsigned long int wxCRT_StrtoulW(const wchar_t *nptr, wchar_t **endptr, int base); |
331 | | #endif |
332 | | |
333 | | #ifndef wxCRT_StrxfrmW |
334 | | WXDLLIMPEXP_BASE size_t wxCRT_StrxfrmW(wchar_t *dest, const wchar_t *src, size_t n); |
335 | | #endif |
336 | | |
337 | | #ifndef wxCRT_StrdupA |
338 | | WXDLLIMPEXP_BASE char *wxCRT_StrdupA(const char *psz); |
339 | | #endif |
340 | | |
341 | | #ifndef wxCRT_StrdupW |
342 | | WXDLLIMPEXP_BASE wchar_t *wxCRT_StrdupW(const wchar_t *pwz); |
343 | | #endif |
344 | | |
345 | | #ifndef wxCRT_StricmpA |
346 | | WXDLLIMPEXP_BASE int wxCRT_StricmpA(const char *psz1, const char *psz2); |
347 | | #endif |
348 | | |
349 | | #ifndef wxCRT_StricmpW |
350 | | WXDLLIMPEXP_BASE int wxCRT_StricmpW(const wchar_t *psz1, const wchar_t *psz2); |
351 | | #endif |
352 | | |
353 | | #ifndef wxCRT_StrnicmpA |
354 | | WXDLLIMPEXP_BASE int wxCRT_StrnicmpA(const char *psz1, const char *psz2, size_t len); |
355 | | #endif |
356 | | |
357 | | #ifndef wxCRT_StrnicmpW |
358 | | WXDLLIMPEXP_BASE int wxCRT_StrnicmpW(const wchar_t *psz1, const wchar_t *psz2, size_t len); |
359 | | #endif |
360 | | |
361 | | #ifndef wxCRT_StrtokA |
362 | | WXDLLIMPEXP_BASE char *wxCRT_StrtokA(char *psz, const char *delim, char **save_ptr); |
363 | | #endif |
364 | | |
365 | | #ifndef wxCRT_StrtokW |
366 | | WXDLLIMPEXP_BASE wchar_t *wxCRT_StrtokW(wchar_t *psz, const wchar_t *delim, wchar_t **save_ptr); |
367 | | #endif |
368 | | |
369 | | /* supply strtoll and strtoull, if needed */ |
370 | | #ifdef wxLongLong_t |
371 | | #ifndef wxCRT_StrtollA |
372 | | WXDLLIMPEXP_BASE wxLongLong_t wxCRT_StrtollA(const char* nptr, |
373 | | char** endptr, |
374 | | int base); |
375 | | WXDLLIMPEXP_BASE wxULongLong_t wxCRT_StrtoullA(const char* nptr, |
376 | | char** endptr, |
377 | | int base); |
378 | | #endif |
379 | | #ifndef wxCRT_StrtollW |
380 | | WXDLLIMPEXP_BASE wxLongLong_t wxCRT_StrtollW(const wchar_t* nptr, |
381 | | wchar_t** endptr, |
382 | | int base); |
383 | | WXDLLIMPEXP_BASE wxULongLong_t wxCRT_StrtoullW(const wchar_t* nptr, |
384 | | wchar_t** endptr, |
385 | | int base); |
386 | | #endif |
387 | | #endif /* wxLongLong_t */ |
388 | | |
389 | | |
390 | | /* ------------------------------------------------------------------------- |
391 | | stdio.h |
392 | | ------------------------------------------------------------------------- */ |
393 | | |
394 | | #if defined(__UNIX__) || defined(__WXMAC__) |
395 | | #define wxMBFILES 1 |
396 | | #else |
397 | | #define wxMBFILES 0 |
398 | | #endif |
399 | | |
400 | | |
401 | | /* these functions are only needed in the form used for filenames (i.e. char* |
402 | | on Unix, wchar_t* on Windows), so we don't need to use A/W suffix: */ |
403 | | #if wxMBFILES /* ANSI filenames */ |
404 | | |
405 | 0 | #define wxCRT_Fopen fopen |
406 | | #define wxCRT_Freopen freopen |
407 | 0 | #define wxCRT_Remove remove |
408 | 0 | #define wxCRT_Rename rename |
409 | | |
410 | | #else /* Unicode filenames */ |
411 | | wxDECL_FOR_STRICT_MINGW32(FILE*, _wfopen, (const wchar_t*, const wchar_t*)) |
412 | | wxDECL_FOR_STRICT_MINGW32(FILE*, _wfreopen, (const wchar_t*, const wchar_t*, FILE*)) |
413 | | wxDECL_FOR_STRICT_MINGW32(int, _wrename, (const wchar_t*, const wchar_t*)) |
414 | | wxDECL_FOR_STRICT_MINGW32(int, _wremove, (const wchar_t*)) |
415 | | |
416 | | #define wxCRT_Rename _wrename |
417 | | #define wxCRT_Remove _wremove |
418 | | #define wxCRT_Fopen _wfopen |
419 | | #define wxCRT_Freopen _wfreopen |
420 | | |
421 | | #endif /* wxMBFILES/!wxMBFILES */ |
422 | | |
423 | | #define wxCRT_PutsA puts |
424 | | #define wxCRT_FputsA fputs |
425 | 0 | #define wxCRT_FgetsA fgets |
426 | | #define wxCRT_FputcA fputc |
427 | | #define wxCRT_FgetcA fgetc |
428 | | #define wxCRT_UngetcA ungetc |
429 | | |
430 | | #ifdef wxHAVE_TCHAR_SUPPORT |
431 | | #define wxCRT_PutsW _putws |
432 | | #define wxCRT_FputsW fputws |
433 | | #define wxCRT_FputcW fputwc |
434 | | #endif |
435 | | #ifdef HAVE_FPUTWS |
436 | 0 | #define wxCRT_FputsW fputws |
437 | | #endif |
438 | | #ifdef HAVE_PUTWS |
439 | | #define wxCRT_PutsW putws |
440 | | #endif |
441 | | #ifdef HAVE_FPUTWC |
442 | | #define wxCRT_FputcW fputwc |
443 | | #endif |
444 | | #define wxCRT_FgetsW fgetws |
445 | | |
446 | | #ifndef wxCRT_PutsW |
447 | | WXDLLIMPEXP_BASE int wxCRT_PutsW(const wchar_t *ws); |
448 | | #endif |
449 | | |
450 | | #ifndef wxCRT_FputsW |
451 | | WXDLLIMPEXP_BASE int wxCRT_FputsW(const wchar_t *ch, FILE *stream); |
452 | | #endif |
453 | | |
454 | | #ifndef wxCRT_FputcW |
455 | | WXDLLIMPEXP_BASE int wxCRT_FputcW(wchar_t wc, FILE *stream); |
456 | | #endif |
457 | | |
458 | | /* |
459 | | NB: tmpnam() is unsafe and thus is not wrapped! |
460 | | Use other wxWidgets facilities instead: |
461 | | wxFileName::CreateTempFileName, wxTempFile, or wxTempFileOutputStream |
462 | | */ |
463 | | #define wxTmpnam(x) wxTmpnam_is_insecure_use_wxTempFile_instead |
464 | | |
465 | 0 | #define wxCRT_PerrorA perror |
466 | | #ifdef wxHAVE_TCHAR_SUPPORT |
467 | | #define wxCRT_PerrorW _wperror |
468 | | #endif |
469 | | |
470 | | /* ------------------------------------------------------------------------- |
471 | | stdlib.h |
472 | | ------------------------------------------------------------------------- */ |
473 | | |
474 | 0 | #define wxCRT_GetenvA getenv |
475 | | #ifdef wxHAVE_TCHAR_SUPPORT |
476 | | #define wxCRT_GetenvW _wgetenv |
477 | | #endif |
478 | | |
479 | | #ifndef wxCRT_GetenvW |
480 | | WXDLLIMPEXP_BASE wchar_t * wxCRT_GetenvW(const wchar_t *name); |
481 | | #endif |
482 | | |
483 | | |
484 | | #define wxCRT_SystemA system |
485 | | #ifdef wxHAVE_TCHAR_SUPPORT |
486 | | #define wxCRT_SystemW _wsystem |
487 | | #endif |
488 | | |
489 | | #define wxCRT_AtofA atof |
490 | 0 | #define wxCRT_AtoiA atoi |
491 | | #define wxCRT_AtolA atol |
492 | | |
493 | | #if defined(wxHAVE_TCHAR_SUPPORT) |
494 | | wxDECL_FOR_STRICT_MINGW32(int, _wtoi, (const wchar_t*)) |
495 | | wxDECL_FOR_STRICT_MINGW32(long, _wtol, (const wchar_t*)) |
496 | | |
497 | | #define wxCRT_AtoiW _wtoi |
498 | | #define wxCRT_AtolW _wtol |
499 | | /* _wtof doesn't exist */ |
500 | | #else |
501 | | #ifndef __VMS |
502 | 0 | #define wxCRT_AtofW(s) wcstod(s, nullptr) |
503 | | #endif |
504 | 0 | #define wxCRT_AtolW(s) wcstol(s, nullptr, 10) |
505 | | /* wcstoi doesn't exist */ |
506 | | #endif |
507 | | |
508 | | /* ------------------------------------------------------------------------- |
509 | | time.h |
510 | | ------------------------------------------------------------------------- */ |
511 | | |
512 | | #define wxCRT_StrftimeA strftime |
513 | | #ifdef __SGI__ |
514 | | /* |
515 | | IRIX provides not one but two versions of wcsftime(): XPG4 one which |
516 | | uses "const char*" for the third parameter and so can't be used and the |
517 | | correct, XPG5, one. Unfortunately we can't just define _XOPEN_SOURCE |
518 | | high enough to get XPG5 version as this undefines other symbols which |
519 | | make other functions we use unavailable (see <standards.h> for gory |
520 | | details). So just declare the XPG5 version ourselves, we're extremely |
521 | | unlikely to ever be compiled on a system without it. But if we ever do, |
522 | | a configure test would need to be added for it (and _MIPS_SYMBOL_PRESENT |
523 | | should be used to check for its presence during run-time, i.e. it would |
524 | | probably be simpler to just always use our own wxCRT_StrftimeW() below |
525 | | if it does ever become a problem). |
526 | | */ |
527 | | #ifdef __cplusplus |
528 | | extern "C" |
529 | | #endif |
530 | | size_t |
531 | | _xpg5_wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm * ); |
532 | | #define wxCRT_StrftimeW _xpg5_wcsftime |
533 | | #else |
534 | | /* |
535 | | Assume it's always available under non-Unix systems as this does seem |
536 | | to be the case for now. And under Unix we trust configure to detect it |
537 | | (except for SGI special case above). |
538 | | */ |
539 | | #if defined(HAVE_WCSFTIME) || !defined(__UNIX__) |
540 | 0 | #define wxCRT_StrftimeW wcsftime |
541 | | #endif |
542 | | #endif |
543 | | |
544 | | #ifndef wxCRT_StrftimeW |
545 | | WXDLLIMPEXP_BASE size_t wxCRT_StrftimeW(wchar_t *s, size_t max, |
546 | | const wchar_t *fmt, |
547 | | const struct tm *tm); |
548 | | #endif |
549 | | |
550 | | |
551 | | |
552 | | /* ------------------------------------------------------------------------- |
553 | | ctype.h |
554 | | ------------------------------------------------------------------------- */ |
555 | | |
556 | 0 | #define wxCRT_IsalnumW(c) iswalnum(c) |
557 | 0 | #define wxCRT_IsalphaW(c) iswalpha(c) |
558 | | #define wxCRT_IscntrlW(c) iswcntrl(c) |
559 | 0 | #define wxCRT_IsdigitW(c) iswdigit(c) |
560 | | #define wxCRT_IsgraphW(c) iswgraph(c) |
561 | | #define wxCRT_IslowerW(c) iswlower(c) |
562 | | #define wxCRT_IsprintW(c) iswprint(c) |
563 | 0 | #define wxCRT_IspunctW(c) iswpunct(c) |
564 | 0 | #define wxCRT_IsspaceW(c) iswspace(c) |
565 | | #define wxCRT_IsupperW(c) iswupper(c) |
566 | | #define wxCRT_IsxdigitW(c) iswxdigit(c) |
567 | | |
568 | | #ifdef __GLIBC__ |
569 | | #if (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0) |
570 | | /* /usr/include/wctype.h incorrectly declares translations */ |
571 | | /* tables which provokes tons of compile-time warnings -- try */ |
572 | | /* to correct this */ |
573 | | #define wxCRT_TolowerW(wc) towctrans((wc), (wctrans_t)__ctype_tolower) |
574 | | #define wxCRT_ToupperW(wc) towctrans((wc), (wctrans_t)__ctype_toupper) |
575 | | #else /* !glibc 2.0 */ |
576 | 0 | #define wxCRT_TolowerW towlower |
577 | 0 | #define wxCRT_ToupperW towupper |
578 | | #endif |
579 | | #else /* !__GLIBC__ */ |
580 | | /* There is a bug in MSVC RTL: toxxx() functions don't do anything |
581 | | with signed chars < 0, so "fix" it here. */ |
582 | | #define wxCRT_TolowerW(c) towlower((wxUChar)(wxChar)(c)) |
583 | | #define wxCRT_ToupperW(c) towupper((wxUChar)(wxChar)(c)) |
584 | | #endif /* __GLIBC__/!__GLIBC__ */ |
585 | | |
586 | | /* The Android platform, as of 2014, only support most wide-char function with |
587 | | the exception of multi-byte encoding/decoding functions & wsprintf/wsscanf |
588 | | See android-ndk-r9d/docs/STANDALONE-TOOLCHAIN.html (section 7.2) |
589 | | In fact, mbstowcs/wcstombs are defined and compile, but don't work correctly |
590 | | */ |
591 | | |
592 | | #if defined(__WXQT__) && defined(__ANDROID__) |
593 | | #define wxNEED_WX_MBSTOWCS |
594 | | #undef HAVE_WCSRTOMBS |
595 | | // TODO: use Qt built-in required functionality |
596 | | #endif |
597 | | |
598 | | #if defined(wxNEED_WX_MBSTOWCS) && defined(__ANDROID__) |
599 | | #warning "Custom mb/wchar conv. only works for ASCII, see Android NDK notes" |
600 | | WXDLLIMPEXP_BASE size_t android_mbstowcs(wchar_t *, const char *, size_t); |
601 | | WXDLLIMPEXP_BASE size_t android_wcstombs(char *, const wchar_t *, size_t); |
602 | | #define wxMbstowcs android_mbstowcs |
603 | | #define wxWcstombs android_wcstombs |
604 | | #else |
605 | | #define wxMbstowcs mbstowcs |
606 | | #define wxWcstombs wcstombs |
607 | | #endif |
608 | | |
609 | | |
610 | | /* ------------------------------------------------------------------------- |
611 | | wx wrappers for CRT functions in both char* and wchar_t* versions |
612 | | ------------------------------------------------------------------------- */ |
613 | | |
614 | | #ifdef __cplusplus |
615 | | |
616 | | /* NB: this belongs to wxcrt.h and not this header, but it makes life easier |
617 | | * for buffer.h which must be included before string.h, which is required |
618 | | * by wxcrt.h, to have them here: */ |
619 | | |
620 | | /* safe version of strlen() (returns 0 if passed null pointer) */ |
621 | 7.98k | inline size_t wxStrlen(const char *s) { return s ? wxCRT_StrlenA(s) : 0; } |
622 | 4.10k | inline size_t wxStrlen(const wchar_t *s) { return s ? wxCRT_StrlenW(s) : 0; } |
623 | | #ifndef wxWCHAR_T_IS_WXCHAR16 |
624 | | WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar16 *s ); |
625 | | #endif |
626 | | #ifndef wxWCHAR_T_IS_WXCHAR32 |
627 | | WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar32 *s ); |
628 | | #endif |
629 | 8 | #define wxWcslen wxCRT_StrlenW |
630 | | |
631 | | #define wxStrdupA wxCRT_StrdupA |
632 | | #define wxStrdupW wxCRT_StrdupW |
633 | 0 | inline char* wxStrdup(const char *s) { return wxCRT_StrdupA(s); } |
634 | 0 | inline wchar_t* wxStrdup(const wchar_t *s) { return wxCRT_StrdupW(s); } |
635 | | #ifndef wxWCHAR_T_IS_WXCHAR16 |
636 | | WXDLLIMPEXP_BASE wxChar16* wxStrdup(const wxChar16* s); |
637 | | #endif |
638 | | #ifndef wxWCHAR_T_IS_WXCHAR32 |
639 | | WXDLLIMPEXP_BASE wxChar32* wxStrdup(const wxChar32* s); |
640 | | #endif |
641 | | |
642 | | #endif /* __cplusplus */ |
643 | | |
644 | | #endif /* _WX_WXCRTBASE_H_ */ |