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