]>
Commit | Line | Data |
---|---|---|
eb9524ca VS |
1 | /* |
2 | * Name: wx/wxcrtbase.h | |
3 | * Purpose: Type-safe ANSI and Unicode builds compatible wrappers for | |
4 | * CRT functions | |
9d55bfef | 5 | * Author: Joel Farley, Ove Kaaven |
eb9524ca VS |
6 | * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee |
7 | * Created: 1998/06/12 | |
8 | * RCS-ID: $Id$ | |
9 | * Copyright: (c) 1998-2006 wxWidgets dev team | |
10 | * Licence: wxWindows licence | |
11 | */ | |
12 | ||
13 | /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */ | |
14 | ||
15 | #ifndef _WX_WXCRTBASE_H_ | |
16 | #define _WX_WXCRTBASE_H_ | |
17 | ||
18 | /* ------------------------------------------------------------------------- | |
19 | headers and missing declarations | |
20 | ------------------------------------------------------------------------- */ | |
21 | ||
22 | #include "wx/chartype.h" | |
23 | ||
24 | /* | |
25 | Standard headers we need here. | |
26 | ||
27 | NB: don't include any wxWidgets headers here because almost all of them | |
28 | include this one! | |
03647350 | 29 | |
b7d70f76 FM |
30 | NB2: User code should include wx/crt.h instead of including this |
31 | header directly. | |
32 | ||
eb9524ca VS |
33 | */ |
34 | ||
e2fc40b4 | 35 | #if !defined(__WXPALMOS5__) |
eb9524ca VS |
36 | #include <stdio.h> |
37 | #include <string.h> | |
38 | #include <ctype.h> | |
e2fc40b4 VZ |
39 | #if defined(__WXPALMOS__) |
40 | #include <wchar.h> | |
41 | #else | |
42 | #include <wctype.h> | |
43 | #endif | |
eb9524ca | 44 | #include <time.h> |
e2fc40b4 | 45 | #endif |
eb9524ca | 46 | |
d6f2a891 VZ |
47 | #if defined(__WINDOWS__) && !defined(__WXWINCE__) |
48 | #include <io.h> | |
4e0a0557 | 49 | #endif |
eb9524ca VS |
50 | |
51 | #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS | |
52 | char *strtok_r(char *, const char *, char **); | |
53 | #endif | |
54 | ||
f030eeed VZ |
55 | /* |
56 | Using -std=c++{98,0x} option with mingw32 disables most of standard | |
57 | library extensions, so we can't rely on the presence of common non-ANSI | |
58 | functions, define a special symbol to test for this. Notice that this | |
59 | doesn't need to be done for g++ under Linux where _GNU_SOURCE (which is | |
60 | defined by default) still makes all common extensions available even in | |
61 | ANSI mode. | |
62 | */ | |
63 | #if defined(__MINGW32__) && defined(__STRICT_ANSI__) | |
64 | #define __WX_STRICT_ANSI_GCC__ | |
65 | #endif | |
66 | ||
eb9524ca VS |
67 | /* |
68 | a few compilers don't have the (non standard but common) isascii function, | |
69 | define it ourselves for them | |
70 | */ | |
71 | #ifndef isascii | |
f030eeed | 72 | #if defined(__MWERKS__) || defined(__WX_STRICT_ANSI_GCC__) |
eb9524ca VS |
73 | #define wxNEED_ISASCII |
74 | #elif defined(_WIN32_WCE) | |
75 | #if _WIN32_WCE <= 211 | |
76 | #define wxNEED_ISASCII | |
77 | #endif | |
78 | #endif | |
79 | #endif /* isascii */ | |
80 | ||
81 | #ifdef wxNEED_ISASCII | |
82 | inline int isascii(int c) { return (unsigned)c < 0x80; } | |
83 | #endif | |
84 | ||
85 | #ifdef _WIN32_WCE | |
86 | #if _WIN32_WCE <= 211 | |
9a83f860 | 87 | #define isspace(c) ((c) == wxT(' ') || (c) == wxT('\t')) |
eb9524ca VS |
88 | #endif |
89 | #endif /* _WIN32_WCE */ | |
90 | ||
91 | /* string.h functions */ | |
92 | #ifndef strdup | |
93 | #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000) | |
94 | #define wxNEED_STRDUP | |
95 | #elif defined(__WXWINCE__) | |
96 | #if _WIN32_WCE <= 211 | |
97 | #define wxNEED_STRDUP | |
98 | #endif | |
99 | #endif | |
100 | #endif /* strdup */ | |
101 | ||
102 | #ifdef wxNEED_STRDUP | |
103 | WXDLLIMPEXP_BASE char *strdup(const char* s); | |
104 | #endif | |
105 | ||
106 | /* missing functions in some WinCE versions */ | |
107 | #ifdef _WIN32_WCE | |
108 | #if (_WIN32_WCE < 300) | |
109 | WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size ); | |
110 | #endif | |
111 | #endif /* _WIN32_WCE */ | |
112 | ||
113 | ||
114 | #if defined(__MWERKS__) | |
115 | /* Metrowerks only has wide char support for OS X >= 10.3 */ | |
116 | #if !defined(__DARWIN__) || \ | |
117 | (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3) | |
118 | #define wxHAVE_MWERKS_UNICODE | |
119 | #endif | |
120 | ||
121 | #ifdef wxHAVE_MWERKS_UNICODE | |
122 | #define HAVE_WPRINTF 1 | |
123 | #define HAVE_WCSRTOMBS 1 | |
124 | #define HAVE_VSWPRINTF 1 | |
125 | #endif | |
126 | #endif /* __MWERKS__ */ | |
127 | ||
128 | ||
129 | /* ------------------------------------------------------------------------- | |
130 | UTF-8 locale handling | |
131 | ------------------------------------------------------------------------- */ | |
132 | ||
133 | #ifdef __cplusplus | |
134 | #if wxUSE_UNICODE_UTF8 | |
28efe654 VS |
135 | /* flag indicating whether the current locale uses UTF-8 or not; must be |
136 | updated every time the locale is changed! */ | |
eb9524ca VS |
137 | #if wxUSE_UTF8_LOCALE_ONLY |
138 | #define wxLocaleIsUtf8 true | |
139 | #else | |
140 | extern WXDLLIMPEXP_BASE bool wxLocaleIsUtf8; | |
141 | #endif | |
28efe654 | 142 | /* function used to update the flag: */ |
eb9524ca | 143 | extern WXDLLIMPEXP_BASE void wxUpdateLocaleIsUtf8(); |
28efe654 | 144 | #else /* !wxUSE_UNICODE_UTF8 */ |
eb9524ca | 145 | inline void wxUpdateLocaleIsUtf8() {} |
28efe654 VS |
146 | #endif /* wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8 */ |
147 | #endif /* __cplusplus */ | |
eb9524ca VS |
148 | |
149 | ||
150 | /* ------------------------------------------------------------------------- | |
151 | string.h | |
152 | ------------------------------------------------------------------------- */ | |
153 | ||
154 | #define wxCRT_StrcatA strcat | |
155 | #define wxCRT_StrchrA strchr | |
156 | #define wxCRT_StrcmpA strcmp | |
eb9524ca VS |
157 | #define wxCRT_StrcpyA strcpy |
158 | #define wxCRT_StrcspnA strcspn | |
159 | #define wxCRT_StrlenA strlen | |
160 | #define wxCRT_StrncatA strncat | |
161 | #define wxCRT_StrncmpA strncmp | |
162 | #define wxCRT_StrncpyA strncpy | |
163 | #define wxCRT_StrpbrkA strpbrk | |
164 | #define wxCRT_StrrchrA strrchr | |
165 | #define wxCRT_StrspnA strspn | |
166 | #define wxCRT_StrstrA strstr | |
eb9524ca | 167 | |
410390cf VS |
168 | #define wxCRT_StrcatW wcscat |
169 | #define wxCRT_StrchrW wcschr | |
170 | #define wxCRT_StrcmpW wcscmp | |
410390cf VS |
171 | #define wxCRT_StrcpyW wcscpy |
172 | #define wxCRT_StrcspnW wcscspn | |
173 | #define wxCRT_StrncatW wcsncat | |
174 | #define wxCRT_StrncmpW wcsncmp | |
175 | #define wxCRT_StrncpyW wcsncpy | |
176 | #define wxCRT_StrpbrkW wcspbrk | |
177 | #define wxCRT_StrrchrW wcsrchr | |
178 | #define wxCRT_StrspnW wcsspn | |
179 | #define wxCRT_StrstrW wcsstr | |
d6f2a891 VZ |
180 | |
181 | /* these functions are not defined under CE, at least in VC8 CRT */ | |
e2fc40b4 | 182 | #if !defined(__WXWINCE__) && !defined(__WXPALMOS__) |
d6f2a891 VZ |
183 | #define wxCRT_StrcollA strcoll |
184 | #define wxCRT_StrxfrmA strxfrm | |
185 | ||
186 | #define wxCRT_StrcollW wcscoll | |
187 | #define wxCRT_StrxfrmW wcsxfrm | |
188 | #endif /* __WXWINCE__ */ | |
410390cf VS |
189 | |
190 | /* Almost all compiler have strdup(), but not quite all: CodeWarrior under | |
adfbce4f VZ |
191 | Mac and VC++ for Windows CE don't provide it. Another special case is gcc in |
192 | strict ANSI mode: normally it doesn't provide strdup() but MinGW does | |
193 | provide it under MSVC-compatible name so test for it before checking | |
194 | __WX_STRICT_ANSI_GCC__. */ | |
195 | #if (defined(__VISUALC__) && __VISUALC__ >= 1400) || \ | |
196 | defined(__MINGW32__) | |
410390cf | 197 | #define wxCRT_StrdupA _strdup |
f030eeed VZ |
198 | #elif !((defined(__MWERKS__) && defined(__WXMAC__)) || \ |
199 | defined(__WXWINCE__) || \ | |
200 | defined(__WX_STRICT_ANSI_GCC__)) | |
410390cf VS |
201 | #define wxCRT_StrdupA strdup |
202 | #endif | |
4691b518 | 203 | |
e78c47e3 | 204 | /* most Windows compilers provide _wcsdup() */ |
f030eeed VZ |
205 | #if defined(__WINDOWS__) && \ |
206 | !(defined(__CYGWIN__) || defined(__WX_STRICT_ANSI_GCC__)) | |
410390cf | 207 | #define wxCRT_StrdupW _wcsdup |
8a02058a | 208 | #elif defined(HAVE_WCSDUP) |
410390cf | 209 | #define wxCRT_StrdupW wcsdup |
eb9524ca VS |
210 | #endif |
211 | ||
212 | #ifdef wxHAVE_TCHAR_SUPPORT | |
213 | /* we surely have wchar_t if we have TCHAR have wcslen() */ | |
214 | #ifndef HAVE_WCSLEN | |
215 | #define HAVE_WCSLEN | |
216 | #endif | |
217 | #endif /* wxHAVE_TCHAR_SUPPORT */ | |
218 | ||
219 | #ifdef HAVE_WCSLEN | |
220 | #define wxCRT_StrlenW wcslen | |
221 | #endif | |
222 | ||
223 | #define wxCRT_StrtodA strtod | |
224 | #define wxCRT_StrtolA strtol | |
225 | #define wxCRT_StrtoulA strtoul | |
226 | #define wxCRT_StrtodW wcstod | |
227 | #define wxCRT_StrtolW wcstol | |
228 | #define wxCRT_StrtoulW wcstoul | |
229 | ||
230 | #ifdef __VISUALC__ | |
231 | #if __VISUALC__ >= 1300 && !defined(__WXWINCE__) | |
232 | #define wxCRT_StrtollA _strtoi64 | |
233 | #define wxCRT_StrtoullA _strtoui64 | |
234 | #define wxCRT_StrtollW _wcstoi64 | |
235 | #define wxCRT_StrtoullW _wcstoui64 | |
236 | #endif /* VC++ 7+ */ | |
237 | #else | |
238 | #ifdef HAVE_STRTOULL | |
239 | #define wxCRT_StrtollA strtoll | |
240 | #define wxCRT_StrtoullA strtoull | |
241 | #endif /* HAVE_STRTOULL */ | |
242 | #ifdef HAVE_WCSTOULL | |
243 | /* assume that we have wcstoull(), which is also C99, too */ | |
244 | #define wxCRT_StrtollW wcstoll | |
245 | #define wxCRT_StrtoullW wcstoull | |
246 | #endif /* HAVE_WCSTOULL */ | |
247 | #endif | |
248 | ||
951f792f VZ |
249 | /* |
250 | Only VC8 and later provide strnlen() and wcsnlen() functions under Windows | |
251 | and it's also only available starting from Windows CE 6.0 only in CE build. | |
252 | */ | |
16d2c3ea | 253 | #if wxCHECK_VISUALC_VERSION(8) && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 0x600)) |
951f792f VZ |
254 | #ifndef HAVE_STRNLEN |
255 | #define HAVE_STRNLEN | |
256 | #endif | |
257 | #ifndef HAVE_WCSNLEN | |
258 | #define HAVE_WCSNLEN | |
259 | #endif | |
260 | #endif | |
261 | ||
262 | #ifdef HAVE_STRNLEN | |
f1b63efe | 263 | #define wxCRT_StrnlenA strnlen |
7c5ac499 FM |
264 | #endif |
265 | ||
951f792f | 266 | #ifdef HAVE_WCSNLEN |
f1b63efe FM |
267 | #define wxCRT_StrnlenW wcsnlen |
268 | #endif | |
eb9524ca VS |
269 | |
270 | /* define wxCRT_StricmpA/W and wxCRT_StrnicmpA/W for various compilers */ | |
271 | ||
6689960c VZ |
272 | #if defined(__BORLANDC__) || defined(__WATCOMC__) || \ |
273 | defined(__VISAGECPP__) || \ | |
274 | defined(__EMX__) || defined(__DJGPP__) | |
275 | #define wxCRT_StricmpA stricmp | |
276 | #define wxCRT_StrnicmpA strnicmp | |
277 | #elif defined(__WXPALMOS__) | |
278 | /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This | |
279 | * quick hack should do until one can be written. | |
280 | */ | |
281 | #define wxCRT_StricmpA StrCaselessCompare | |
282 | #define wxCRT_StrnicmpA StrNCaselessCompare | |
283 | #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \ | |
284 | (defined(__MWERKS__) && defined(__INTEL__)) | |
285 | #define wxCRT_StricmpA _stricmp | |
286 | #define wxCRT_StrnicmpA _strnicmp | |
f030eeed | 287 | #elif defined(__UNIX__) || (defined(__GNUWIN32__) && !defined(__WX_STRICT_ANSI_GCC__)) |
6689960c VZ |
288 | #define wxCRT_StricmpA strcasecmp |
289 | #define wxCRT_StrnicmpA strncasecmp | |
290 | /* #else -- use wxWidgets implementation */ | |
291 | #endif | |
292 | ||
293 | #ifdef __VISUALC__ | |
294 | #define wxCRT_StricmpW _wcsicmp | |
295 | #define wxCRT_StrnicmpW _wcsnicmp | |
296 | #elif defined(__UNIX__) | |
297 | #ifdef HAVE_WCSCASECMP | |
298 | #define wxCRT_StricmpW wcscasecmp | |
eb9524ca | 299 | #endif |
6689960c VZ |
300 | #ifdef HAVE_WCSNCASECMP |
301 | #define wxCRT_StrnicmpW wcsncasecmp | |
302 | #endif | |
303 | /* #else -- use wxWidgets implementation */ | |
304 | #endif | |
eb9524ca VS |
305 | |
306 | #ifdef HAVE_STRTOK_R | |
307 | #define wxCRT_StrtokA(str, sep, last) strtok_r(str, sep, last) | |
308 | #endif | |
309 | /* FIXME-UTF8: detect and use wcstok() if available for wxCRT_StrtokW */ | |
310 | ||
311 | /* these are extern "C" because they are used by regex lib: */ | |
312 | #ifdef __cplusplus | |
313 | extern "C" { | |
314 | #endif | |
315 | ||
316 | #ifndef wxCRT_StrlenW | |
317 | WXDLLIMPEXP_BASE size_t wxCRT_StrlenW(const wchar_t *s); | |
318 | #endif | |
319 | ||
320 | #ifndef wxCRT_StrncmpW | |
321 | WXDLLIMPEXP_BASE int wxCRT_StrncmpW(const wchar_t *s1, const wchar_t *s2, size_t n); | |
322 | #endif | |
323 | ||
324 | #ifdef __cplusplus | |
325 | } | |
326 | #endif | |
327 | ||
328 | /* FIXME-UTF8: remove this once we are Unicode only */ | |
329 | #if wxUSE_UNICODE | |
330 | #define wxCRT_StrlenNative wxCRT_StrlenW | |
331 | #define wxCRT_StrncmpNative wxCRT_StrncmpW | |
332 | #define wxCRT_ToupperNative wxCRT_ToupperW | |
333 | #define wxCRT_TolowerNative wxCRT_TolowerW | |
334 | #else | |
335 | #define wxCRT_StrlenNative wxCRT_StrlenA | |
336 | #define wxCRT_StrncmpNative wxCRT_StrncmpA | |
337 | #define wxCRT_ToupperNative toupper | |
338 | #define wxCRT_TolowerNative tolower | |
339 | #endif | |
340 | ||
341 | #ifndef wxCRT_StrcatW | |
342 | WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcatW(wchar_t *dest, const wchar_t *src); | |
343 | #endif | |
344 | ||
345 | #ifndef wxCRT_StrchrW | |
346 | WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrchrW(const wchar_t *s, wchar_t c); | |
347 | #endif | |
348 | ||
349 | #ifndef wxCRT_StrcmpW | |
350 | WXDLLIMPEXP_BASE int wxCRT_StrcmpW(const wchar_t *s1, const wchar_t *s2); | |
351 | #endif | |
352 | ||
353 | #ifndef wxCRT_StrcollW | |
354 | WXDLLIMPEXP_BASE int wxCRT_StrcollW(const wchar_t *s1, const wchar_t *s2); | |
355 | #endif | |
356 | ||
357 | #ifndef wxCRT_StrcpyW | |
358 | WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcpyW(wchar_t *dest, const wchar_t *src); | |
359 | #endif | |
360 | ||
361 | #ifndef wxCRT_StrcspnW | |
362 | WXDLLIMPEXP_BASE size_t wxCRT_StrcspnW(const wchar_t *s, const wchar_t *reject); | |
363 | #endif | |
364 | ||
365 | #ifndef wxCRT_StrncatW | |
366 | WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncatW(wchar_t *dest, const wchar_t *src, size_t n); | |
367 | #endif | |
368 | ||
369 | #ifndef wxCRT_StrncpyW | |
370 | WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncpyW(wchar_t *dest, const wchar_t *src, size_t n); | |
371 | #endif | |
372 | ||
373 | #ifndef wxCRT_StrpbrkW | |
374 | WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrpbrkW(const wchar_t *s, const wchar_t *accept); | |
375 | #endif | |
376 | ||
377 | #ifndef wxCRT_StrrchrW | |
378 | WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrrchrW(const wchar_t *s, wchar_t c); | |
379 | #endif | |
380 | ||
381 | #ifndef wxCRT_StrspnW | |
382 | WXDLLIMPEXP_BASE size_t wxCRT_StrspnW(const wchar_t *s, const wchar_t *accept); | |
383 | #endif | |
384 | ||
385 | #ifndef wxCRT_StrstrW | |
386 | WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrstrW(const wchar_t *haystack, const wchar_t *needle); | |
387 | #endif | |
388 | ||
389 | #ifndef wxCRT_StrtodW | |
390 | WXDLLIMPEXP_BASE double wxCRT_StrtodW(const wchar_t *nptr, wchar_t **endptr); | |
391 | #endif | |
392 | ||
393 | #ifndef wxCRT_StrtolW | |
394 | WXDLLIMPEXP_BASE long int wxCRT_StrtolW(const wchar_t *nptr, wchar_t **endptr, int base); | |
395 | #endif | |
396 | ||
397 | #ifndef wxCRT_StrtoulW | |
398 | WXDLLIMPEXP_BASE unsigned long int wxCRT_StrtoulW(const wchar_t *nptr, wchar_t **endptr, int base); | |
399 | #endif | |
400 | ||
401 | #ifndef wxCRT_StrxfrmW | |
402 | WXDLLIMPEXP_BASE size_t wxCRT_StrxfrmW(wchar_t *dest, const wchar_t *src, size_t n); | |
403 | #endif | |
404 | ||
405 | #ifndef wxCRT_StrdupA | |
406 | WXDLLIMPEXP_BASE char *wxCRT_StrdupA(const char *psz); | |
407 | #endif | |
408 | ||
409 | #ifndef wxCRT_StrdupW | |
410 | WXDLLIMPEXP_BASE wchar_t *wxCRT_StrdupW(const wchar_t *pwz); | |
411 | #endif | |
412 | ||
413 | #ifndef wxCRT_StricmpA | |
414 | WXDLLIMPEXP_BASE int wxCRT_StricmpA(const char *psz1, const char *psz2); | |
415 | #endif | |
416 | ||
417 | #ifndef wxCRT_StricmpW | |
418 | WXDLLIMPEXP_BASE int wxCRT_StricmpW(const wchar_t *psz1, const wchar_t *psz2); | |
419 | #endif | |
420 | ||
421 | #ifndef wxCRT_StrnicmpA | |
422 | WXDLLIMPEXP_BASE int wxCRT_StrnicmpA(const char *psz1, const char *psz2, size_t len); | |
423 | #endif | |
424 | ||
425 | #ifndef wxCRT_StrnicmpW | |
426 | WXDLLIMPEXP_BASE int wxCRT_StrnicmpW(const wchar_t *psz1, const wchar_t *psz2, size_t len); | |
427 | #endif | |
428 | ||
429 | #ifndef wxCRT_StrtokA | |
430 | WXDLLIMPEXP_BASE char *wxCRT_StrtokA(char *psz, const char *delim, char **save_ptr); | |
431 | #endif | |
432 | ||
433 | #ifndef wxCRT_StrtokW | |
434 | WXDLLIMPEXP_BASE wchar_t *wxCRT_StrtokW(wchar_t *psz, const wchar_t *delim, wchar_t **save_ptr); | |
435 | #endif | |
436 | ||
437 | /* supply strtoll and strtoull, if needed */ | |
bdcb2137 VS |
438 | #ifdef wxLongLong_t |
439 | #ifndef wxCRT_StrtollA | |
440 | WXDLLIMPEXP_BASE wxLongLong_t wxCRT_StrtollA(const char* nptr, | |
441 | char** endptr, | |
442 | int base); | |
443 | WXDLLIMPEXP_BASE wxULongLong_t wxCRT_StrtoullA(const char* nptr, | |
444 | char** endptr, | |
445 | int base); | |
446 | #endif | |
447 | #ifndef wxCRT_StrtollW | |
448 | WXDLLIMPEXP_BASE wxLongLong_t wxCRT_StrtollW(const wchar_t* nptr, | |
449 | wchar_t** endptr, | |
450 | int base); | |
451 | WXDLLIMPEXP_BASE wxULongLong_t wxCRT_StrtoullW(const wchar_t* nptr, | |
452 | wchar_t** endptr, | |
453 | int base); | |
454 | #endif | |
e78c47e3 | 455 | #endif /* wxLongLong_t */ |
eb9524ca VS |
456 | |
457 | ||
458 | /* ------------------------------------------------------------------------- | |
459 | stdio.h | |
460 | ------------------------------------------------------------------------- */ | |
461 | ||
e2fc40b4 | 462 | #if defined(__UNIX__) || defined(__WXMAC__) || defined(__WXPALMOS__) |
eb9524ca VS |
463 | #define wxMBFILES 1 |
464 | #else | |
465 | #define wxMBFILES 0 | |
466 | #endif | |
467 | ||
468 | ||
469 | /* these functions are only needed in the form used for filenames (i.e. char* | |
470 | on Unix, wchar_t* on Windows), so we don't need to use A/W suffix: */ | |
28efe654 | 471 | #if wxMBFILES || !wxUSE_UNICODE /* ANSI filenames */ |
eb9524ca VS |
472 | |
473 | #define wxCRT_Fopen fopen | |
474 | #define wxCRT_Freopen freopen | |
475 | #define wxCRT_Remove remove | |
476 | #define wxCRT_Rename rename | |
477 | ||
28efe654 | 478 | #else /* Unicode filenames */ |
eb9524ca VS |
479 | /* special case: these functions are missing under Win9x with Unicows so we |
480 | have to implement them ourselves */ | |
f030eeed | 481 | #if wxUSE_UNICODE_MSLU || defined(__WX_STRICT_ANSI_GCC__) |
eb9524ca VS |
482 | WXDLLIMPEXP_BASE FILE* wxMSLU__wfopen(const wchar_t *name, const wchar_t *mode); |
483 | WXDLLIMPEXP_BASE FILE* wxMSLU__wfreopen(const wchar_t *name, const wchar_t *mode, FILE *stream); | |
484 | WXDLLIMPEXP_BASE int wxMSLU__wrename(const wchar_t *oldname, const wchar_t *newname); | |
485 | WXDLLIMPEXP_BASE int wxMSLU__wremove(const wchar_t *name); | |
486 | #define wxCRT_Fopen wxMSLU__wfopen | |
a007b626 | 487 | #define wxCRT_Freopen wxMSLU__wfreopen |
eb9524ca VS |
488 | #define wxCRT_Remove wxMSLU__wremove |
489 | #define wxCRT_Rename wxMSLU__wrename | |
490 | #else | |
d6f2a891 | 491 | /* WinCE CRT doesn't provide these functions so use our own */ |
eb9524ca | 492 | #ifdef __WXWINCE__ |
d6f2a891 VZ |
493 | WXDLLIMPEXP_BASE int wxCRT_Rename(const wchar_t *src, |
494 | const wchar_t *dst); | |
495 | WXDLLIMPEXP_BASE int wxCRT_Remove(const wchar_t *path); | |
eb9524ca | 496 | #else |
d6f2a891 | 497 | #define wxCRT_Rename _wrename |
eb9524ca VS |
498 | #define wxCRT_Remove _wremove |
499 | #endif | |
d6f2a891 VZ |
500 | #define wxCRT_Fopen _wfopen |
501 | #define wxCRT_Freopen _wfreopen | |
eb9524ca VS |
502 | #endif |
503 | ||
28efe654 | 504 | #endif /* wxMBFILES/!wxMBFILES */ |
eb9524ca VS |
505 | |
506 | #define wxCRT_PutsA puts | |
507 | #define wxCRT_FputsA fputs | |
508 | #define wxCRT_FgetsA fgets | |
509 | #define wxCRT_FputcA fputc | |
510 | #define wxCRT_FgetcA fgetc | |
511 | #define wxCRT_UngetcA ungetc | |
512 | ||
410390cf VS |
513 | #ifdef wxHAVE_TCHAR_SUPPORT |
514 | #define wxCRT_PutsW _putws | |
515 | #define wxCRT_FputsW fputws | |
516 | #define wxCRT_FputcW fputwc | |
517 | #endif | |
518 | #ifdef HAVE_FPUTWS | |
519 | #define wxCRT_FputsW fputws | |
520 | #endif | |
521 | #ifdef HAVE_PUTWS | |
522 | #define wxCRT_PutsW putws | |
523 | #endif | |
524 | #ifdef HAVE_FPUTWC | |
525 | #define wxCRT_FputcW fputwc | |
526 | #endif | |
527 | #define wxCRT_FgetsW fgetws | |
eb9524ca VS |
528 | |
529 | #ifndef wxCRT_PutsW | |
530 | WXDLLIMPEXP_BASE int wxCRT_PutsW(const wchar_t *ws); | |
531 | #endif | |
532 | ||
533 | #ifndef wxCRT_FputsW | |
534 | WXDLLIMPEXP_BASE int wxCRT_FputsW(const wchar_t *ch, FILE *stream); | |
535 | #endif | |
536 | ||
537 | #ifndef wxCRT_FputcW | |
538 | WXDLLIMPEXP_BASE int wxCRT_FputcW(wchar_t wc, FILE *stream); | |
539 | #endif | |
540 | ||
57e2b887 VS |
541 | /* |
542 | NB: tmpnam() is unsafe and thus is not wrapped! | |
543 | Use other wxWidgets facilities instead: | |
544 | wxFileName::CreateTempFileName, wxTempFile, or wxTempFileOutputStream | |
545 | */ | |
546 | #define wxTmpnam(x) wxTmpnam_is_insecure_use_wxTempFile_instead | |
eb9524ca | 547 | |
d6f2a891 VZ |
548 | /* FIXME-CE: provide our own perror() using ::GetLastError() */ |
549 | #ifndef __WXWINCE__ | |
550 | ||
eb9524ca VS |
551 | #define wxCRT_PerrorA perror |
552 | #ifdef wxHAVE_TCHAR_SUPPORT | |
553 | #define wxCRT_PerrorW _wperror | |
554 | #endif | |
555 | ||
d6f2a891 VZ |
556 | #endif /* !__WXWINCE__ */ |
557 | ||
eb9524ca VS |
558 | /* ------------------------------------------------------------------------- |
559 | stdlib.h | |
560 | ------------------------------------------------------------------------- */ | |
561 | ||
562 | /* there are no env vars at all under CE, so no _tgetenv neither */ | |
563 | #ifdef __WXWINCE__ | |
564 | /* can't define as inline function as this is a C file... */ | |
d6f2a891 VZ |
565 | #define wxCRT_GetenvA(name) (name, NULL) |
566 | #define wxCRT_GetenvW(name) (name, NULL) | |
eb9524ca VS |
567 | #else |
568 | #define wxCRT_GetenvA getenv | |
569 | #ifdef _tgetenv | |
570 | #define wxCRT_GetenvW _wgetenv | |
571 | #endif | |
572 | #endif | |
573 | ||
574 | #ifndef wxCRT_GetenvW | |
575 | WXDLLIMPEXP_BASE wchar_t * wxCRT_GetenvW(const wchar_t *name); | |
576 | #endif | |
577 | ||
578 | ||
579 | #define wxCRT_SystemA system | |
580 | /* mingw32 doesn't provide _tsystem() or _wsystem(): */ | |
581 | #if defined(_tsystem) | |
582 | #define wxCRT_SystemW _wsystem | |
583 | #endif | |
584 | ||
585 | #define wxCRT_AtofA atof | |
586 | #define wxCRT_AtoiA atoi | |
587 | #define wxCRT_AtolA atol | |
588 | ||
589 | #if defined(__MWERKS__) | |
590 | #if defined(__MSL__) | |
591 | #define wxCRT_AtofW watof | |
592 | #define wxCRT_AtoiW watoi | |
593 | #define wxCRT_AtolW watol | |
594 | /* else: use ANSI versions */ | |
595 | #endif | |
f030eeed | 596 | #elif defined(wxHAVE_TCHAR_SUPPORT) && !defined(__WX_STRICT_ANSI_GCC__) |
eb9524ca VS |
597 | #define wxCRT_AtoiW _wtoi |
598 | #define wxCRT_AtolW _wtol | |
599 | /* _wtof doesn't exist */ | |
600 | #else | |
28ffb1f2 | 601 | #ifndef __VMS |
5c15fb21 | 602 | #define wxCRT_AtofW(s) wcstod(s, NULL) |
28ffb1f2 | 603 | #endif |
eb9524ca VS |
604 | #define wxCRT_AtolW(s) wcstol(s, NULL, 10) |
605 | /* wcstoi doesn't exist */ | |
606 | #endif | |
607 | ||
608 | /* | |
609 | There are 2 unrelated problems with these functions under Mac: | |
610 | a) Metrowerks MSL CRT implements them strictly in C99 sense and | |
611 | doesn't support (very common) extension of allowing to call | |
612 | mbstowcs(NULL, ...) which makes it pretty useless as you can't | |
613 | know the size of the needed buffer | |
614 | b) OS X <= 10.2 declares and even defined these functions but | |
615 | doesn't really implement them -- they always return an error | |
616 | ||
617 | So use our own replacements in both cases. | |
618 | */ | |
619 | #if defined(__MWERKS__) && defined(__MSL__) | |
620 | #define wxNEED_WX_MBSTOWCS | |
621 | #endif | |
e2fc40b4 VZ |
622 | #if defined(__WXPALMOS__) |
623 | #define wxNEED_WX_MBSTOWCS | |
624 | #endif | |
eb9524ca VS |
625 | |
626 | #ifdef __DARWIN__ | |
26632ccd | 627 | #if !defined(__WXOSX_IPHONE__) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 |
eb9524ca VS |
628 | #define wxNEED_WX_MBSTOWCS |
629 | #endif | |
630 | #endif | |
631 | ||
632 | #ifdef wxNEED_WX_MBSTOWCS | |
633 | /* even though they are defined and "implemented", they are bad and just | |
634 | stubs so we need our own - we need these even in ANSI builds!! */ | |
635 | WXDLLIMPEXP_BASE size_t wxMbstowcs(wchar_t *, const char *, size_t); | |
636 | WXDLLIMPEXP_BASE size_t wxWcstombs(char *, const wchar_t *, size_t); | |
637 | #else | |
638 | #define wxMbstowcs mbstowcs | |
639 | #define wxWcstombs wcstombs | |
640 | #endif | |
641 | ||
642 | ||
643 | ||
644 | /* ------------------------------------------------------------------------- | |
645 | time.h | |
646 | ------------------------------------------------------------------------- */ | |
647 | ||
648 | #define wxCRT_StrftimeA strftime | |
d0204fee VZ |
649 | #ifdef __SGI__ |
650 | /* | |
651 | IRIX provides not one but two versions of wcsftime(): XPG4 one which | |
652 | uses "const char*" for the third parameter and so can't be used and the | |
653 | correct, XPG5, one. Unfortunately we can't just define _XOPEN_SOURCE | |
654 | high enough to get XPG5 version as this undefines other symbols which | |
655 | make other functions we use unavailable (see <standards.h> for gory | |
656 | details). So just declare the XPG5 version ourselves, we're extremely | |
657 | unlikely to ever be compiled on a system without it. But if we ever do, | |
658 | a configure test would need to be added for it (and _MIPS_SYMBOL_PRESENT | |
659 | should be used to check for its presence during run-time, i.e. it would | |
660 | probably be simpler to just always use our own wxCRT_StrftimeW() below | |
661 | if it does ever become a problem). | |
662 | */ | |
a89c31bb PC |
663 | #ifdef __cplusplus |
664 | extern "C" | |
665 | #endif | |
666 | size_t | |
d0204fee VZ |
667 | _xpg5_wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm * ); |
668 | #define wxCRT_StrftimeW _xpg5_wcsftime | |
669 | #else | |
e78c47e3 DS |
670 | /* |
671 | Assume it's always available under non-Unix systems with the | |
672 | exception of Palm OS, this does seem to be the case for now. And | |
673 | under Unix we trust configure to detect it (except for SGI special | |
674 | case above). | |
675 | */ | |
3931f3ec VZ |
676 | #if defined(HAVE_WCSFTIME) || \ |
677 | !(defined(__UNIX__) || defined(__WXPALMOS__)) | |
d0204fee VZ |
678 | #define wxCRT_StrftimeW wcsftime |
679 | #endif /* ! __WXPALMOS__ */ | |
680 | #endif | |
eb9524ca VS |
681 | |
682 | #ifndef wxCRT_StrftimeW | |
683 | WXDLLIMPEXP_BASE size_t wxCRT_StrftimeW(wchar_t *s, size_t max, | |
684 | const wchar_t *fmt, | |
685 | const struct tm *tm); | |
686 | #endif | |
687 | ||
688 | ||
689 | ||
690 | /* ------------------------------------------------------------------------- | |
691 | ctype.h | |
692 | ------------------------------------------------------------------------- */ | |
693 | ||
eb9524ca VS |
694 | #ifdef __WATCOMC__ |
695 | #define WXWCHAR_T_CAST(c) (wint_t)(c) | |
696 | #else | |
697 | #define WXWCHAR_T_CAST(c) c | |
698 | #endif | |
699 | ||
410390cf VS |
700 | #define wxCRT_IsalnumW(c) iswalnum(WXWCHAR_T_CAST(c)) |
701 | #define wxCRT_IsalphaW(c) iswalpha(WXWCHAR_T_CAST(c)) | |
702 | #define wxCRT_IscntrlW(c) iswcntrl(WXWCHAR_T_CAST(c)) | |
703 | #define wxCRT_IsdigitW(c) iswdigit(WXWCHAR_T_CAST(c)) | |
704 | #define wxCRT_IsgraphW(c) iswgraph(WXWCHAR_T_CAST(c)) | |
705 | #define wxCRT_IslowerW(c) iswlower(WXWCHAR_T_CAST(c)) | |
706 | #define wxCRT_IsprintW(c) iswprint(WXWCHAR_T_CAST(c)) | |
707 | #define wxCRT_IspunctW(c) iswpunct(WXWCHAR_T_CAST(c)) | |
708 | #define wxCRT_IsspaceW(c) iswspace(WXWCHAR_T_CAST(c)) | |
709 | #define wxCRT_IsupperW(c) iswupper(WXWCHAR_T_CAST(c)) | |
710 | #define wxCRT_IsxdigitW(c) iswxdigit(WXWCHAR_T_CAST(c)) | |
711 | ||
712 | #ifdef __GLIBC__ | |
713 | #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0) | |
714 | /* /usr/include/wctype.h incorrectly declares translations */ | |
715 | /* tables which provokes tons of compile-time warnings -- try */ | |
716 | /* to correct this */ | |
717 | #define wxCRT_TolowerW(wc) towctrans((wc), (wctrans_t)__ctype_tolower) | |
718 | #define wxCRT_ToupperW(wc) towctrans((wc), (wctrans_t)__ctype_toupper) | |
719 | #else /* !glibc 2.0 */ | |
720 | #define wxCRT_TolowerW towlower | |
721 | #define wxCRT_ToupperW towupper | |
722 | #endif | |
28efe654 | 723 | #else /* !__GLIBC__ */ |
410390cf VS |
724 | /* There is a bug in VC6 C RTL: toxxx() functions dosn't do anything |
725 | with signed chars < 0, so "fix" it here. */ | |
726 | #define wxCRT_TolowerW(c) towlower((wxUChar)(wxChar)(c)) | |
727 | #define wxCRT_ToupperW(c) towupper((wxUChar)(wxChar)(c)) | |
28efe654 | 728 | #endif /* __GLIBC__/!__GLIBC__ */ |
eb9524ca VS |
729 | |
730 | ||
731 | ||
732 | ||
733 | ||
734 | /* ------------------------------------------------------------------------- | |
735 | wx wrappers for CRT functions in both char* and wchar_t* versions | |
736 | ------------------------------------------------------------------------- */ | |
737 | ||
738 | #ifdef __cplusplus | |
739 | ||
740 | /* NB: this belongs to wxcrt.h and not this header, but it makes life easier | |
741 | * for buffer.h and stringimpl.h (both of which must be included before | |
742 | * string.h, which is required by wxcrt.h) to have them here: */ | |
743 | ||
744 | /* safe version of strlen() (returns 0 if passed NULL pointer) */ | |
745 | inline size_t wxStrlen(const char *s) { return s ? wxCRT_StrlenA(s) : 0; } | |
746 | inline size_t wxStrlen(const wchar_t *s) { return s ? wxCRT_StrlenW(s) : 0; } | |
676a5687 | 747 | #ifndef wxWCHAR_T_IS_WXCHAR16 |
16882c9e | 748 | WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar16 *s ); |
676a5687 RR |
749 | #endif |
750 | #ifndef wxWCHAR_T_IS_WXCHAR32 | |
16882c9e | 751 | WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar32 *s ); |
676a5687 | 752 | #endif |
eb9524ca VS |
753 | #define wxWcslen wxCRT_StrlenW |
754 | ||
755 | #define wxStrdupA wxCRT_StrdupA | |
756 | #define wxStrdupW wxCRT_StrdupW | |
757 | inline char* wxStrdup(const char *s) { return wxCRT_StrdupA(s); } | |
758 | inline wchar_t* wxStrdup(const wchar_t *s) { return wxCRT_StrdupW(s); } | |
676a5687 | 759 | #ifndef wxWCHAR_T_IS_WXCHAR16 |
16882c9e | 760 | WXDLLIMPEXP_BASE wxChar16* wxStrdup(const wxChar16* s); |
676a5687 RR |
761 | #endif |
762 | #ifndef wxWCHAR_T_IS_WXCHAR32 | |
16882c9e | 763 | WXDLLIMPEXP_BASE wxChar32* wxStrdup(const wxChar32* s); |
676a5687 | 764 | #endif |
eb9524ca VS |
765 | |
766 | #endif /* __cplusplus */ | |
767 | ||
768 | #endif /* _WX_WXCRTBASE_H_ */ |