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