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