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