]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxcrt.h
include wxchar.h from string.h in 2.8 compatibility mode to prevent lots of compilati...
[wxWidgets.git] / include / wx / wxcrt.h
1 /*
2 * Name: wx/wxcrt.h
3 * Purpose: Type-safe ANSI and Unicode builds compatible wrappers for
4 * CRT functions
5 * Author: Joel Farley, Ove Kåven
6 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
7 * Created: 1998/06/12
8 * RCS-ID: $Id$
9 * Copyright: (c) 1998-2006 wxWidgets dev team
10 * Licence: wxWindows licence
11 */
12
13 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
14
15 #ifndef _WX_WXCRT_H_
16 #define _WX_WXCRT_H_
17
18 #include "wx/chartype.h"
19
20 #include <stdio.h> /* we use FILE below */
21
22 #ifdef __cplusplus
23 #if wxUSE_UNICODE_UTF8
24 // flag indicating whether the current locale uses UTF-8 or not; must be
25 // updated every time the locale is changed!
26 #if !wxUSE_UTF8_LOCALE_ONLY
27 extern WXDLLIMPEXP_BASE bool wxLocaleIsUtf8;
28 #endif
29 // function used to update the flag:
30 extern WXDLLIMPEXP_BASE void wxUpdateLocaleIsUtf8();
31 #else // !wxUSE_UNICODE_UTF8
32 inline void wxUpdateLocaleIsUtf8() {}
33 #endif // wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8
34 #endif // __cplusplus
35
36 #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
37 char *strtok_r(char *, const char *, char **);
38 #endif
39
40
41 /*
42 Standard headers we need here.
43
44 NB: don't include any wxWidgets headers here because almost all of them include
45 this one!
46 */
47
48 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac */
49 /* and VC++ for Windows CE don't provide it */
50 #if defined(__VISUALC__) && __VISUALC__ >= 1400
51 #define wxStrdupA _strdup
52 #elif !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
53 /* use #define, not inline wrapper, as it is tested with #ifndef below */
54 #define wxStrdupA strdup
55 #endif
56
57 #if defined(__MWERKS__)
58 /* Metrowerks only has wide char support for OS X >= 10.3 */
59 #if !defined(__DARWIN__) || \
60 (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
61 #define wxHAVE_MWERKS_UNICODE
62 #endif
63
64 #ifdef wxHAVE_MWERKS_UNICODE
65 #define HAVE_WPRINTF 1
66 #define HAVE_WCSRTOMBS 1
67 #define HAVE_VSWPRINTF 1
68 #endif
69 #endif /* __MWERKS__ */
70
71 #ifdef wxHAVE_TCHAR_SUPPORT
72 /* we surely have wchar_t if we have TCHAR have wcslen() */
73 #ifndef HAVE_WCSLEN
74 #define HAVE_WCSLEN
75 #endif
76 #endif /* wxHAVE_TCHAR_SUPPORT */
77
78 /*
79 define wxFoo() function for each standard foo() function whose signature
80 (exceptionally including the return type) includes any mention of char:
81 wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
82 the same signature but with char replaced by wxChar which allows us to
83 use it in Unicode build as well
84 */
85
86 #ifdef wxHAVE_TCHAR_SUPPORT
87 #include <ctype.h>
88
89 #if defined(__WATCOMC__) && defined(UNICODE)
90 #define WXWCHAR_T_CAST(c) (wint_t)(c)
91 #else
92 #define WXWCHAR_T_CAST(c) c
93 #endif
94
95 /* ctype.h functions */
96 #define wxIsalnum(c) _istalnum(WXWCHAR_T_CAST(c))
97 #define wxIsalpha(c) _istalpha(WXWCHAR_T_CAST(c))
98 #define wxIscntrl(c) _istcntrl(WXWCHAR_T_CAST(c))
99 #define wxIsdigit(c) _istdigit(WXWCHAR_T_CAST(c))
100 #define wxIsgraph(c) _istgraph(WXWCHAR_T_CAST(c))
101 #define wxIslower(c) _istlower(WXWCHAR_T_CAST(c))
102 #define wxIsprint(c) _istprint(WXWCHAR_T_CAST(c))
103 #define wxIspunct(c) _istpunct(WXWCHAR_T_CAST(c))
104 #define wxIsspace(c) _istspace(WXWCHAR_T_CAST(c))
105 #define wxIsupper(c) _istupper(WXWCHAR_T_CAST(c))
106 #define wxIsxdigit(c) _istxdigit(WXWCHAR_T_CAST(c))
107
108 /*
109 There is a bug in VC6 C RTL: toxxx() functions dosn't do anything with
110 signed chars < 0, so "fix" it here.
111 */
112 #define wxTolower(c) _totlower((wxUChar)(wxChar)(c))
113 #define wxToupper(c) _totupper((wxUChar)(wxChar)(c))
114
115 /* locale.h functons */
116 #define wxSetlocale_ _tsetlocale
117
118 /* string.h functions */
119 #define wxStrcat _tcscat
120 #define wxStrchr _tcschr
121 #define wxStrcmp _tcscmp
122 #define wxStrcoll _tcscoll
123 #define wxStrcpy _tcscpy
124 #define wxStrcspn _tcscspn
125 #define wxStrdupW _wcsdup /* notice the 'W'! */
126 #define wxStrftime _tcsftime
127 #define wxStricmp _tcsicmp
128 #define wxStrnicmp _tcsnicmp
129 #define wxStrlen_ _tcslen /* used in wxStrlen inline function */
130 #define wxStrncat _tcsncat
131 #define wxStrncmp _tcsncmp
132 #define wxStrncpy _tcsncpy
133 #define wxStrpbrk _tcspbrk
134 #define wxStrrchr _tcsrchr
135 #define wxStrspn _tcsspn
136 #define wxStrstr _tcsstr
137 #define wxStrtod _tcstod
138 #define wxStrtol _tcstol
139 #define wxStrtoul _tcstoul
140 #ifdef __VISUALC__
141 #if __VISUALC__ >= 1300 && !defined(__WXWINCE__)
142 #define wxStrtoll _tcstoi64
143 #define wxStrtoull _tcstoui64
144 #endif /* VC++ 7+ */
145 #endif
146 #define wxStrxfrm _tcsxfrm
147
148 /* stdio.h functions */
149 #define wxFgetc _fgettc
150 #define wxFgetchar _fgettchar
151 #define wxFgets _fgetts
152 #if wxUSE_UNICODE_MSLU
153 WXDLLIMPEXP_BASE FILE * wxMSLU__tfopen(const wxChar *name, const wxChar *mode);
154
155 #define wxFopen wxMSLU__tfopen
156 #else
157 #define wxFopen _tfopen
158 #endif
159 #define wxFputc _fputtc
160 #define wxFputchar _fputtchar
161 #define wxFputs _fputts
162 #define wxFreopen _tfreopen
163 #define wxGetc _gettc
164 #define wxGetchar _gettchar
165 #define wxGets _getts
166 #define wxPerror _tperror
167 #define wxPutc(c,f) _puttc(WXWCHAR_T_CAST(c),f)
168 #define wxPutchar _puttchar
169 #define wxPuts _putts
170
171 #define wxTmpnam _ttmpnam
172 #define wxUngetc _tungetc
173
174 /* special case: these functions are missing under Win9x with Unicows so we */
175 /* have to implement them ourselves */
176 #if wxUSE_UNICODE_MSLU
177 WXDLLIMPEXP_BASE int wxMSLU__trename(const wxChar *oldname, const wxChar *newname);
178 WXDLLIMPEXP_BASE int wxMSLU__tremove(const wxChar *name);
179
180 #define wxRemove wxMSLU__tremove
181 #define wxRename wxMSLU__trename
182 #else
183 #ifdef __WXWINCE__
184 /* carefully: wxRemove() must return 0 on success while DeleteFile()
185 returns 0 on error, so don't just define one as the other */
186 int wxRemove(const wxChar *path);
187 #else
188 #define wxRemove _tremove
189 #define wxRename _trename
190 #endif
191 #endif
192
193 /* stdlib.h functions */
194 #define wxAtoi _ttoi
195 #define wxAtol _ttol
196 /* #define wxAtof _tttof -- notice that there is no such thing (why?) */
197 /* there are no env vars at all under CE, so no _tgetenv neither */
198 #ifdef __WXWINCE__
199 /* can't define as inline function as this is a C file... */
200 #define wxGetenv(name) ((wxChar *)NULL)
201 #else
202 #define wxGetenv _tgetenv
203 #endif
204 #define wxSystem _tsystem
205
206 /* time.h functions */
207 #define wxAsctime _tasctime
208 #define wxCtime _tctime
209
210 #define wxMbstowcs mbstowcs
211 #define wxWcstombs wcstombs
212 #else /* !TCHAR-aware compilers */
213 /*
214 There are 2 unrelated problems with these functions under Mac:
215 a) Metrowerks MSL CRT implements them strictly in C99 sense and
216 doesn't support (very common) extension of allowing to call
217 mbstowcs(NULL, ...) which makes it pretty useless as you can't
218 know the size of the needed buffer
219 b) OS X <= 10.2 declares and even defined these functions but
220 doesn't really implement them -- they always return an error
221
222 So use our own replacements in both cases.
223 */
224 #if defined(__MWERKS__) && defined(__MSL__)
225 #define wxNEED_WX_MBSTOWCS
226 #endif
227
228 #ifdef __DARWIN__
229 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
230 #define wxNEED_WX_MBSTOWCS
231 #endif
232 #endif
233
234 #ifdef wxNEED_WX_MBSTOWCS
235 /* even though they are defined and "implemented", they are bad and just
236 stubs so we need our own - we need these even in ANSI builds!! */
237 WXDLLIMPEXP_BASE size_t wxMbstowcs (wchar_t *, const char *, size_t);
238 WXDLLIMPEXP_BASE size_t wxWcstombs (char *, const wchar_t *, size_t);
239 #else
240 #define wxMbstowcs mbstowcs
241 #define wxWcstombs wcstombs
242 #endif
243
244 /*
245 The system C library on Mac OS X 10.2 and below does not support
246 unicode: in other words all wide-character functions such as towupper et
247 al. do simply not exist so we need to provide our own in that context,
248 except for the wchar_t definition/typedef itself.
249
250 We need to do this for both project builder and CodeWarrior as
251 the latter uses the system C library in Mach builds for wide character
252 support, which as mentioned does not exist on 10.2 and below.
253 */
254 #if wxUSE_UNICODE && \
255 defined(__DARWIN__) && \
256 ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
257 /* we need everything! */
258 #define wxNEED_WX_STRING_H
259 #define wxNEED_WX_CTYPE_H
260
261 #define wxFgetchar(c) wxFgetc(c, stdin)
262 #define wxFputc wxPutc
263 #define wxFputchar(c) wxPutc(c, stdout)
264 #define wxGetc wxFgetc
265 #define wxGetchar(c) wxFgetc(c, stdin)
266
267 #include <stdio.h>
268
269 #define wxNEED_FGETC
270 #define wxNEED_FGETS
271 #define wxNEED_GETS
272 #define wxNEED_UNGETC
273
274 #define wxNEED_FPUTS
275 #define wxNEED_PUTS
276 #define wxNEED_PUTC
277
278 int wxFputs(const wxChar *ch, FILE *stream);
279 int wxPuts(const wxChar *ws);
280 int wxPutc(wxChar ch, FILE *stream);
281
282 #ifdef __cplusplus
283 extern "C" {
284 #endif
285 WXDLLIMPEXP_BASE size_t wxStrlen_(const wxChar *s);
286 #ifdef __cplusplus
287 }
288 #endif
289
290 #define wxPutchar(wch) wxPutc(wch, stdout)
291
292 #define wxNEED_PRINTF_CONVERSION
293 #define wxNEED_WX_STDIO_H
294 #define wxNEED_WX_STDLIB_H
295 #define wxNEED_WX_TIME_H
296
297 #elif wxUSE_UNICODE
298 #include <wctype.h>
299
300 /* this is probably glibc-specific */
301 #if defined(__WCHAR_TYPE__) && !defined(__MWERKS__)
302 /* ctype.h functions (wctype.h) */
303 #define wxIsalnum iswalnum
304 #define wxIsalpha iswalpha
305 #define wxIscntrl iswcntrl
306 #define wxIsdigit iswdigit
307 #define wxIsgraph iswgraph
308 #define wxIslower iswlower
309 #define wxIsprint iswprint
310 #define wxIspunct iswpunct
311 #define wxIsspace iswspace
312 #define wxIsupper iswupper
313 #define wxIsxdigit iswxdigit
314
315 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
316 /* /usr/include/wctype.h incorrectly declares translations */
317 /* tables which provokes tons of compile-time warnings -- try */
318 /* to correct this */
319 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
320 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
321 #else /* !glibc 2.0 */
322 #define wxTolower towlower
323 #define wxToupper towupper
324 #endif /* gcc/!gcc */
325
326 /* string.h functions (wchar.h) */
327 #define wxStrcat wcscat
328 #define wxStrchr wcschr
329 #define wxStrcmp wcscmp
330 #define wxStrcoll wcscoll
331 #define wxStrcpy wcscpy
332 #define wxStrcspn wcscspn
333 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
334 #define wxStrncat wcsncat
335 #define wxStrncmp wcsncmp
336 #define wxStrncpy wcsncpy
337 #define wxStrpbrk wcspbrk
338 #define wxStrrchr wcsrchr
339 #define wxStrspn wcsspn
340 #define wxStrstr wcsstr
341 #define wxStrtod wcstod
342 #define wxStrtol wcstol
343 #define wxStrtoul wcstoul
344 #ifdef HAVE_WCSTOULL
345 /* assume that we have wcstoull(), which is also C99, too */
346 #define wxStrtoll wcstoll
347 #define wxStrtoull wcstoull
348 #endif /* HAVE_WCSTOULL */
349 #define wxStrxfrm wcsxfrm
350
351 #define wxFgetc fgetwc
352 #define wxFgetchar fgetwchar
353 #define wxFgets fgetws
354 #define wxFputc fputwc
355 #define wxFputchar fputwchar
356 #define wxGetc getwc
357 #define wxGetchar getwchar
358 #define wxGets getws
359 #define wxUngetc ungetwc
360
361 #ifdef HAVE_FPUTWS
362 #define wxFputs fputws
363 #else
364 #define wxNEED_FPUTS
365 #include <stdio.h>
366 int wxFputs(const wxChar *ch, FILE *stream);
367 #endif
368
369 #ifdef HAVE_WPUTC
370 #define wxPutc wputc
371 #else
372 #define wxNEED_PUTC
373 #include <stdio.h>
374 int wxPutc(wxChar ch, FILE *stream);
375 #endif
376
377 #ifdef HAVE_WPUTCHAR
378 #define wxPutchar wputchar
379 #else
380 #define wxPutchar(wch) wxPutc(wch, stdout)
381 #endif
382
383 #ifdef HAVE_PUTWS
384 #define wxPuts putws
385 #else
386 #define wxNEED_PUTS
387 int wxPuts(const wxChar *ws);
388 #endif
389
390 /* we need %s to %ls conversion for printf and scanf etc */
391 #define wxNEED_PRINTF_CONVERSION
392
393 /* glibc doesn't have wide char equivalents of the other stuff so */
394 /* use our own versions */
395 #define wxNEED_WX_STDIO_H
396 #define wxNEED_WX_STDLIB_H
397 #define wxNEED_WX_TIME_H
398 #elif defined(__MWERKS__) && ( defined(__MSL__) || defined(__MACH__) )
399 /* ctype.h functions (wctype.h) */
400 #define wxIsalnum iswalnum
401 #define wxIsalpha iswalpha
402 #define wxIscntrl iswcntrl
403 #define wxIsdigit iswdigit
404 #define wxIsgraph iswgraph
405 #define wxIslower iswlower
406 #define wxIsprint iswprint
407 #define wxIspunct iswpunct
408 #define wxIsspace iswspace
409 #define wxIsupper iswupper
410 #define wxIsxdigit iswxdigit
411 #define wxTolower towlower
412 #define wxToupper towupper
413
414 /* string.h functions (wchar.h) */
415 #define wxStrcat wcscat
416 #define wxStrchr wcschr
417 #define wxStrcmp wcscmp
418 #define wxStrcoll wcscoll
419 #define wxStrcpy wcscpy
420 #define wxStrcspn wcscspn
421 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
422 #define wxStrncat wcsncat
423 #define wxStrncmp wcsncmp
424 #define wxStrncpy wcsncpy
425 #define wxStrpbrk wcspbrk
426 #define wxStrrchr wcsrchr
427 #define wxStrspn wcsspn
428 #define wxStrstr wcsstr
429 #define wxStrtod wcstod
430 #define wxStrtol wcstol
431 #define wxStrtoul wcstoul
432 #define wxStrxfrm wcsxfrm
433
434 #define wxFgetc fgetwc
435 #define wxFgetchar fgetwchar
436 #define wxFgets fgetws
437 #define wxFputc fputwc
438 #define wxFputchar fputwchar
439 #define wxGetc getwc
440 #define wxGetchar getwchar
441 #define wxGets getws
442 #define wxUngetc ungetwc
443
444 #define wxNEED_PRINTF_CONVERSION
445
446 #define wxPutc putwc
447 #define wxPutchar putwchar
448 #define wxFputs fputws
449
450 /* stdio.h functions */
451
452 #define wxNEED_WX_STDIO_H
453
454 /* stdlib.h functions */
455 #ifdef __MACH__
456 #define wxNEED_WX_STDLIB_H
457 #else
458 #define wxAtof watof
459 #define wxAtoi watoi
460 #define wxAtol watol
461 #define wxGetenv(a) ((wxChar*)NULL)
462 #define wxSystem(a) ((int)NULL)
463 #endif
464 /* time.h functions */
465 #define wxAsctime wasciitime
466 #define wxCtime wctime
467 /* #define wxStrftime wcsftime */
468
469 #define wxNEED_WX_TIME_H
470 #else /* !metrowerks for apple */
471 #error "Please define wide character functions for your environment"
472 #endif
473 #else /* ASCII */
474 #include <ctype.h>
475 #include <string.h>
476
477 /* ctype.h functions */
478 #define wxIsalnum isalnum
479 #define wxIsalpha isalpha
480 #define wxIscntrl iscntrl
481 #define wxIsdigit isdigit
482 #define wxIsgraph isgraph
483 #define wxIslower islower
484 #define wxIsprint isprint
485 #define wxIspunct ispunct
486 #define wxIsspace isspace
487 #define wxIsupper isupper
488 #define wxIsxdigit isxdigit
489 #define wxTolower tolower
490 #define wxToupper toupper
491
492 /* locale.h functons */
493 #define wxSetlocale_ setlocale
494
495 /* string.h functions */
496 #define wxStrcat strcat
497 #define wxStrchr strchr
498 #define wxStrcmp strcmp
499 #define wxStrcoll strcoll
500 #define wxStrcpy strcpy
501 #define wxStrcspn strcspn
502
503 /* wxStricmp and wxStrnicmp are defined below */
504 #define wxStrlen_ strlen /* used in wxStrlen inline function */
505 #define wxStrncat strncat
506 #define wxStrncmp strncmp
507 #define wxStrncpy strncpy
508 #define wxStrpbrk strpbrk
509 #define wxStrrchr strrchr
510 #define wxStrspn strspn
511 #define wxStrstr strstr
512 #define wxStrtod strtod
513 #ifdef HAVE_STRTOK_R
514 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
515 #endif
516 #define wxStrtol strtol
517 #define wxStrtoul strtoul
518 #ifdef HAVE_STRTOULL
519 /* assume that we have wcstoull(), which is also C99, too */
520 #define wxStrtoll strtoll
521 #define wxStrtoull strtoull
522 #endif /* HAVE_WCSTOULL */
523 #define wxStrxfrm strxfrm
524
525 /* stdio.h functions */
526 #define wxFopen fopen
527 #define wxFreopen freopen
528 #define wxRemove remove
529 #define wxRename rename
530
531 #define wxPerror perror
532 #define wxTmpnam tmpnam
533
534 #define wxFgetc fgetc
535 #define wxFgetchar fgetchar
536 #define wxFgets fgets
537 #define wxFputc fputc
538 #define wxFputs fputs
539 #define wxFputchar fputchar
540 #define wxGetc getc
541 #define wxGetchar getchar
542 #define wxGets gets
543 #define wxPutc putc
544 #define wxPutchar putchar
545 #define wxPuts puts
546 #define wxUngetc ungetc
547
548 /* stdlib.h functions */
549 #define wxAtof atof
550 #define wxAtoi atoi
551 #define wxAtol atol
552 #define wxGetenv getenv
553 #define wxSystem system
554
555 /* time.h functions */
556 #define wxAsctime asctime
557 #define wxCtime ctime
558 #define wxStrftime strftime
559 #endif /* Unicode/ASCII */
560 #endif /* TCHAR-aware compilers/the others */
561
562 /*
563 various special cases
564 */
565
566 /* define wxStricmp and wxStrnicmp for various compilers */
567
568 /* note that in Unicode mode we definitely are going to need our own version */
569 #if !defined(wxStricmp) && !wxUSE_UNICODE
570 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
571 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
572 defined(__EMX__) || defined(__DJGPP__)
573 #define wxStricmp stricmp
574 #define wxStrnicmp strnicmp
575 #elif defined(__WXPALMOS__)
576 /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
577 * quick hack should do until one can be written.
578 */
579 #define wxStricmp StrCaselessCompare
580 #define wxStrnicmp strnicmp
581 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
582 (defined(__MWERKS__) && defined(__INTEL__))
583 #define wxStricmp _stricmp
584 #define wxStrnicmp _strnicmp
585 #elif defined(__UNIX__) || defined(__GNUWIN32__)
586 #define wxStricmp strcasecmp
587 #define wxStrnicmp strncasecmp
588 /* #else -- use wxWidgets implementation */
589 #endif
590 #endif /* !defined(wxStricmp) */
591
592 /* define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as */
593 /* it's used in wx/buffer.h -- and also might be used just below by wxStrlen() */
594 /* when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen) */
595 #if wxUSE_WCHAR_T
596 #ifdef HAVE_WCSLEN
597 #define wxWcslen wcslen
598 #else
599 WXDLLIMPEXP_BASE size_t wxWcslen(const wchar_t *s);
600 #endif
601 #endif /* wxUSE_WCHAR_T */
602
603 #ifdef __cplusplus
604 /* checks whether the passed in pointer is NULL and if the string is empty */
605 inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
606
607 /* safe version of strlen() (returns 0 if passed NULL pointer) */
608 inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
609 #endif
610
611 /*
612 each of strdup() and wcsdup() may or may not be available but we need both
613 of them anyhow for wx/buffer.h so we define the missing one(s) in
614 wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
615 defined -- if this is somehow not the case in some situations, please
616 correct that and not the lines here
617 */
618 #if wxUSE_UNICODE
619 #define wxStrdup wxStrdupW
620 #else
621 #define wxStrdup wxStrdupA
622 #endif
623
624 #ifdef __cplusplus
625 WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
626 #endif
627
628 #ifndef wxStrtoll
629 /* supply strtoll and strtoull, if needed */
630 WXDLLIMPEXP_BASE wxLongLong_t wxStrtoll(const wxChar* nptr, wxChar** endptr, int base);
631 WXDLLIMPEXP_BASE wxULongLong_t wxStrtoull(const wxChar* nptr, wxChar** endptr, int base);
632 #endif
633
634 #define wxHAS_STRTOLL
635
636 /*
637 In Unicode mode we need to have all standard functions such as wprintf() and
638 so on but not all systems have them so use our own implementations in this
639 case.
640 */
641 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
642 #define wxNEED_WPRINTF
643 #endif
644
645 /*
646 various functions which might not be available in libc and for which we
647 provide our own replacements in wxchar.cpp
648 */
649
650 /* ctype.h functions */
651
652 /* RN: Used only under OSX <= 10.2 currently */
653 #ifdef wxNEED_WX_CTYPE_H
654 WXDLLIMPEXP_BASE int wxIsalnum(wxChar ch);
655 WXDLLIMPEXP_BASE int wxIsalpha(wxChar ch);
656 WXDLLIMPEXP_BASE int wxIscntrl(wxChar ch);
657 WXDLLIMPEXP_BASE int wxIsdigit(wxChar ch);
658 WXDLLIMPEXP_BASE int wxIsgraph(wxChar ch);
659 WXDLLIMPEXP_BASE int wxIslower(wxChar ch);
660 WXDLLIMPEXP_BASE int wxIsprint(wxChar ch);
661 WXDLLIMPEXP_BASE int wxIspunct(wxChar ch);
662 WXDLLIMPEXP_BASE int wxIsspace(wxChar ch);
663 WXDLLIMPEXP_BASE int wxIsupper(wxChar ch);
664 WXDLLIMPEXP_BASE int wxIsxdigit(wxChar ch);
665 WXDLLIMPEXP_BASE int wxTolower(wxChar ch);
666 WXDLLIMPEXP_BASE int wxToupper(wxChar ch);
667 #endif /* wxNEED_WX_CTYPE_H */
668
669 /* under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks */
670 /* the file parsing -- this may be true for 5.0 as well, update #ifdef then */
671 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
672 #undef wxIsspace
673 #define wxIsspace(c) ((((unsigned)(wxChar)c) < 128) && isspace(c))
674 #endif /* VC++ */
675
676 /*
677 a few compilers don't have the (non standard but common) isascii function,
678 define it ourselves for them
679 */
680 #ifndef isascii
681 #if defined(__MWERKS__)
682 #define wxNEED_ISASCII
683 #elif defined(_WIN32_WCE)
684 #if _WIN32_WCE <= 211
685 #define wxNEED_ISASCII
686 #endif
687 #endif
688 #endif /* isascii */
689
690 #ifdef wxNEED_ISASCII
691 inline int isascii(int c) { return (unsigned)c < 0x80; }
692 #endif
693
694 #ifdef _WIN32_WCE
695 #if _WIN32_WCE <= 211
696 #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
697 #endif
698 #endif /* _WIN32_WCE */
699
700 /*
701 we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
702 initial versions of this header -- now it is too late to remove it so
703 although we fixed the function/macro name above, still provide the
704 backwards-compatible synonym.
705 */
706 #define wxIsctrl wxIscntrl
707
708 /* string.h functions */
709 #ifndef strdup
710 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
711 #define wxNEED_STRDUP
712 #elif defined(__WXWINCE__)
713 #if _WIN32_WCE <= 211
714 #define wxNEED_STRDUP
715 #endif
716 #endif
717 #endif /* strdup */
718
719 #ifdef wxNEED_STRDUP
720 WXDLLIMPEXP_BASE char *strdup(const char* s);
721 #endif
722
723 /* RN: Used only under OSX <= 10.2 currently
724 The __cplusplus ifdefs are messy, but they are required to build
725 the regex library, since c does not support function overloading
726 */
727 #ifdef wxNEED_WX_STRING_H
728 # ifdef __cplusplus
729 extern "C" {
730 # endif
731 WXDLLIMPEXP_BASE wxChar * wxStrcat(wxChar *dest, const wxChar *src);
732 WXDLLIMPEXP_BASE const wxChar * wxStrchr(const wxChar *s, wxChar c);
733 WXDLLIMPEXP_BASE int wxStrcmp(const wxChar *s1, const wxChar *s2);
734 WXDLLIMPEXP_BASE int wxStrcoll(const wxChar *s1, const wxChar *s2);
735 WXDLLIMPEXP_BASE wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
736 WXDLLIMPEXP_BASE size_t wxStrcspn(const wxChar *s, const wxChar *reject);
737 WXDLLIMPEXP_BASE wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
738 WXDLLIMPEXP_BASE int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
739 WXDLLIMPEXP_BASE wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
740 WXDLLIMPEXP_BASE const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
741 WXDLLIMPEXP_BASE const wxChar * wxStrrchr(const wxChar *s, wxChar c);
742 WXDLLIMPEXP_BASE size_t wxStrspn(const wxChar *s, const wxChar *accept);
743 WXDLLIMPEXP_BASE const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
744 # ifdef __cplusplus
745 }
746 # endif
747
748 /* These functions use C++, so we can't c extern them */
749 WXDLLIMPEXP_BASE double wxStrtod(const wxChar *nptr, wxChar **endptr);
750 WXDLLIMPEXP_BASE long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
751 WXDLLIMPEXP_BASE unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
752 WXDLLIMPEXP_BASE size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
753
754 /* inlined versions */
755 #ifdef __cplusplus
756 inline wxChar * wxStrchr(wxChar *s, wxChar c)
757 { return (wxChar *)wxStrchr((const wxChar *)s, c); }
758 inline wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
759 { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
760 inline wxChar * wxStrrchr(wxChar *s, wxChar c)
761 { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
762 inline wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
763 { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
764 #endif
765
766 #endif /* wxNEED_WX_STRING_H */
767
768 #ifndef wxStrdupA
769 WXDLLIMPEXP_BASE char *wxStrdupA(const char *psz);
770 #endif
771
772 #ifndef wxStrdupW
773 WXDLLIMPEXP_BASE wchar_t *wxStrdupW(const wchar_t *pwz);
774 #endif
775
776 #ifndef wxStricmp
777 WXDLLIMPEXP_BASE int wxStricmp(const wxChar *psz1, const wxChar *psz2);
778 #endif
779
780 #ifndef wxStrnicmp
781 WXDLLIMPEXP_BASE int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
782 #endif
783
784 #ifndef wxStrtok
785 WXDLLIMPEXP_BASE wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
786 #endif
787
788 #ifdef __cplusplus
789 #ifndef wxSetlocale_
790 class WXDLLIMPEXP_BASE wxWCharBuffer;
791 WXDLLIMPEXP_BASE wxWCharBuffer wxSetlocale_(int category, const wxChar *locale);
792 WXDLLIMPEXP_BASE wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
793 #else
794 WXDLLIMPEXP_BASE wxChar *wxSetlocale(int category, const wxChar *locale);
795 #endif // defined(wxSetlocale_)
796 #endif // __cplusplus
797
798 /* stdio.h functions */
799 #ifdef wxNEED_WX_STDIO_H
800 #include <stdio.h>
801 WXDLLIMPEXP_BASE FILE * wxFopen(const wxChar *path, const wxChar *mode);
802 WXDLLIMPEXP_BASE FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
803 WXDLLIMPEXP_BASE int wxRemove(const wxChar *path);
804 WXDLLIMPEXP_BASE int wxRename(const wxChar *oldpath, const wxChar *newpath);
805
806 /* *printf() family is handled separately */
807 #endif /* wxNEED_WX_STDIO_H */
808
809
810 /* stdlib.h functions */
811 #ifndef wxAtof
812 WXDLLIMPEXP_BASE double wxAtof(const wxChar *psz);
813 #endif
814
815 #ifdef wxNEED_WX_STDLIB_H
816 WXDLLIMPEXP_BASE int wxAtoi(const wxChar *psz);
817 WXDLLIMPEXP_BASE long wxAtol(const wxChar *psz);
818 WXDLLIMPEXP_BASE wxChar * wxGetenv(const wxChar *name);
819 WXDLLIMPEXP_BASE int wxSystem(const wxChar *psz);
820 #endif
821
822
823 /* time.h functions */
824 #ifdef wxNEED_WX_TIME_H
825 #if defined(__MWERKS__) && defined(macintosh)
826 #include <time.h>
827 #endif
828 /*silent gabby compilers*/
829 struct tm;
830 WXDLLIMPEXP_BASE size_t wxStrftime(wxChar *s, size_t max,
831 const wxChar *fmt,
832 const struct tm *tm);
833 #endif /* wxNEED_WX_TIME_H */
834
835 #ifndef wxCtime
836 #include <time.h>
837 WXDLLIMPEXP_BASE wxChar *wxCtime(const time_t *timep);
838 #endif
839
840
841 /* missing functions in some WinCE versions */
842 #ifdef _WIN32_WCE
843 #if (_WIN32_WCE < 300)
844 WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
845 #endif
846 #endif /* _WIN32_WCE */
847
848 /* multibyte to wide char conversion functions and macros */
849
850 #if wxUSE_WCHAR_T
851 /* multibyte<->widechar conversion */
852 WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
853 WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
854
855 #if wxUSE_UNICODE
856 #define wxMB2WX wxMB2WC
857 #define wxWX2MB wxWC2MB
858 #define wxWC2WX wxStrncpy
859 #define wxWX2WC wxStrncpy
860 #else
861 #define wxMB2WX wxStrncpy
862 #define wxWX2MB wxStrncpy
863 #define wxWC2WX wxWC2MB
864 #define wxWX2WC wxMB2WC
865 #endif
866 #else /* !wxUSE_UNICODE */
867 /* Why is this here?
868 #error ha */
869 /* No wxUSE_WCHAR_T: we have to do something (JACS) */
870 #define wxMB2WC wxStrncpy
871 #define wxWC2MB wxStrncpy
872 #define wxMB2WX wxStrncpy
873 #define wxWX2MB wxStrncpy
874 #define wxWC2WX wxWC2MB
875 #define wxWX2WC wxMB2WC
876 #endif
877
878 /*
879 RN: The following are not normal versions of memcpy et al., rather
880 these are either char or widechar versions depending on
881 if unicode is used or not.
882 */
883
884 #ifdef __cplusplus
885
886 //
887 // RN: We could do the usual tricky compiler detection here,
888 // and use their variant (such as wmemchr, etc.). The problem
889 // is that these functions are quite rare, even though they are
890 // part of the current POSIX standard. In addition, most compilers
891 // (including even MSC) inline them just like we do right in their
892 // headers.
893 //
894 #if wxUSE_UNICODE
895 #include <string.h> //for mem funcs
896
897 //implement our own wmem variants
898 inline wxChar* wxTmemchr(const wxChar* s, wxChar c, size_t l)
899 {
900 for(;l && *s != c;--l, ++s) {}
901
902 if(l)
903 return (wxChar*)s;
904 return NULL;
905 }
906
907 inline int wxTmemcmp(const wxChar* sz1, const wxChar* sz2, size_t len)
908 {
909 for(; *sz1 == *sz2 && len; --len, ++sz1, ++sz2) {}
910
911 if(len)
912 return *sz1 < *sz2 ? -1 : *sz1 > *sz2;
913 else
914 return 0;
915 }
916
917 inline wxChar* wxTmemcpy(wxChar* szOut, const wxChar* szIn, size_t len)
918 {
919 return (wxChar*) memcpy(szOut, szIn, len * sizeof(wxChar));
920 }
921
922 inline wxChar* wxTmemmove(wxChar* szOut, const wxChar* szIn, size_t len)
923 {
924 return (wxChar*) memmove(szOut, szIn, len * sizeof(wxChar));
925 }
926
927 inline wxChar* wxTmemset(wxChar* szOut, const wxChar cIn, size_t len)
928 {
929 wxChar* szRet = szOut;
930
931 while (len--)
932 *szOut++ = cIn;
933
934 return szRet;
935 }
936
937 #else /* !wxUSE_UNICODE */
938 # define wxTmemchr memchr
939 # define wxTmemcmp memcmp
940 # define wxTmemcpy memcpy
941 # define wxTmemmove memmove
942 # define wxTmemset memset
943 #endif /* wxUSE_UNICODE/!wxUSE_UNICODE */
944
945 #endif /*__cplusplus*/
946
947 #endif /* _WX_WXCRT_H_ */