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