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