]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
added test for snprintf() which may not be present in system headers, treat it simila...
[wxWidgets.git] / include / wx / wxchar.h
1 /*
2 * Name: wx/wxchar.h
3 * Purpose: Declarations common to wx char/wchar_t usage (wide chars)
4 * Author: Joel Farley, Ove Kåven
5 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
6 * Created: 1998/06/12
7 * RCS-ID: $Id$
8 * Copyright: (c) 1998-2002 Joel Farley, Ove Kåven, Robert Roebling, Ron Lee
9 * Licence: wxWindows licence
10 */
11
12 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
13
14 #ifndef _WX_WXCHAR_H_
15 #define _WX_WXCHAR_H_
16
17 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
18 #pragma interface "wxchar.h"
19 #endif
20
21 #include "wx/defs.h" /* for wxUSE_UNICODE */
22
23 #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
24 char *strtok_r(char *, const char *, char **);
25 #endif
26
27 /* check whether we have wchar_t and which size it is if we do */
28 #if !defined(wxUSE_WCHAR_T)
29 #if defined(__UNIX__)
30 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
31 #define wxUSE_WCHAR_T 1
32 #else
33 #define wxUSE_WCHAR_T 0
34 #endif
35 #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
36 #define wxUSE_WCHAR_T 0
37 #elif defined(__WATCOMC__)
38 #define wxUSE_WCHAR_T 0
39 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
40 #define wxUSE_WCHAR_T 0
41 #else
42 /* add additional compiler checks if this fails */
43 #define wxUSE_WCHAR_T 1
44 #endif
45 #endif /* !defined(wxUSE_WCHAR_T) */
46
47 /* Unicode support requires wchar_t */
48 #if wxUSE_UNICODE && !wxUSE_WCHAR_T
49 #error "wchar_t must be available in Unicode build"
50 #endif /* Unicode */
51
52 /*
53 Standard headers we need here.
54
55 NB: don't include any wxWidgets headers here because almost of them include
56 this one!
57 */
58
59 /* Required for wxPrintf() etc */
60 #include <stdarg.h>
61
62 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac */
63 /* and VC++ for Windows CE don't provide it */
64 #if !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
65 /* use #define, not inline wrapper, as it is tested with #ifndef below */
66 #define wxStrdupA strdup
67 #endif
68
69 /*
70 non Unix compilers which do have wchar.h (but not tchar.h which is included
71 below and which includes wchar.h anyhow).
72
73 Actually MinGW has tchar.h, but it does not include wchar.h
74 */
75 #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
76 #ifndef HAVE_WCHAR_H
77 #define HAVE_WCHAR_H
78 #endif
79 #endif
80 #if defined(__MWERKS__) && !defined(__MACH__)
81 #ifndef HAVE_WCSLEN
82 #define HAVE_WCSLEN
83 #endif
84 #endif
85
86 #if wxUSE_WCHAR_T
87 #ifdef HAVE_WCHAR_H
88 /* the current (as of Nov 2002) version of cygwin has a bug in its */
89 /* wchar.h -- there is no extern "C" around the declarations in it and */
90 /* this results in linking errors later; also, at least on some */
91 /* Cygwin versions, wchar.h requires sys/types.h */
92 #ifdef __CYGWIN__
93 #include <sys/types.h>
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97 #endif /* Cygwin */
98
99 #include <wchar.h>
100
101 #if defined(__CYGWIN__) && defined(__cplusplus)
102 }
103 #endif /* Cygwin and C++ */
104
105 #elif defined(HAVE_WCSTR_H)
106 /* old compilers have relevant declarations here */
107 #include <wcstr.h>
108 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
109 /* include stdlib.h for wchar_t */
110 #include <stdlib.h>
111 #endif /* HAVE_WCHAR_H */
112 #endif /* wxUSE_WCHAR_T */
113
114 /* ---------------------------------------------------------------------------- */
115 /* define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type */
116 /* mapped to either char or wchar_t depending on the ASCII/Unicode mode and have */
117 /* the function mapping _tfoo() -> foo() or wfoo() */
118 /* ---------------------------------------------------------------------------- */
119
120 /* VC++ and BC++ starting with 5.2 have TCHAR support */
121 #ifdef __VISUALC__
122 #define wxHAVE_TCHAR_SUPPORT
123 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
124 #define wxHAVE_TCHAR_SUPPORT
125 #include <ctype.h>
126 #elif defined(__WATCOMC__)
127 #define wxHAVE_TCHAR_SUPPORT
128 #elif defined(__DMC__)
129 #define wxHAVE_TCHAR_SUPPORT
130 #elif defined(__WXPALMOS__)
131 #include <stddef.h>
132 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
133 #define wxHAVE_TCHAR_SUPPORT
134 #include <stddef.h>
135 #include <string.h>
136 #include <ctype.h>
137 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
138 /* VZ: the old VisualAge definitions were completely wrong and had no */
139 /* chance at all to work in Unicode build anyhow so let's pretend that */
140 /* VisualAge does _not_ support TCHAR for the moment (as indicated by */
141 /* "0 &&" above) until someone really has time to delve into Unicode */
142 /* issues under OS/2 */
143
144 /* VisualAge 4.0+ supports TCHAR */
145 #define wxHAVE_TCHAR_SUPPORT
146 #endif /* compilers with (good) TCHAR support */
147
148 #ifdef __MWERKS__
149 #define HAVE_WPRINTF
150 #endif
151
152 #ifdef wxHAVE_TCHAR_SUPPORT
153 /* get TCHAR definition if we've got it */
154 #include <tchar.h>
155
156 /* we surely do have wchar_t if we have TCHAR */
157 #ifndef wxUSE_WCHAR_T
158 #define wxUSE_WCHAR_T 1
159 #endif /* !defined(wxUSE_WCHAR_T) */
160
161 /* and we also do have wcslen() */
162 #ifndef HAVE_WCSLEN
163 #define HAVE_WCSLEN
164 #endif
165 #endif /* wxHAVE_TCHAR_SUPPORT */
166
167 /* ---------------------------------------------------------------------------- */
168 /* define wxChar type */
169 /* ---------------------------------------------------------------------------- */
170
171 /* TODO: define wxCharInt to be equal to either int or wint_t? */
172
173 #if !wxUSE_UNICODE
174 typedef char wxChar;
175 typedef signed char wxSChar;
176 typedef unsigned char wxUChar;
177 #else /* Unicode */
178 /* VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as */
179 /* signed/unsigned version of it which (a) makes sense to me (unlike */
180 /* char wchar_t is always unsigned) and (b) was how the previous */
181 /* definitions worked so keep it like this */
182
183 /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */
184 /* comment below */
185 #if !defined(__WCHAR_TYPE__) || \
186 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
187 /* standard case */
188 typedef wchar_t wxChar;
189 typedef wchar_t wxSChar;
190 typedef wchar_t wxUChar;
191 #else /* __WCHAR_TYPE__ and gcc < 2.96 */
192 /* VS: wxWidgets used to define wxChar as __WCHAR_TYPE__ here. However, */
193 /* this doesn't work with new GCC 3.x compilers because wchar_t is */
194 /* C++'s builtin type in the new standard. OTOH, old compilers (GCC */
195 /* 2.x) won't accept new definition of wx{S,U}Char, therefore we */
196 /* have to define wxChar conditionally depending on detected */
197 /* compiler & compiler version. */
198 /* with old definition of wxChar. */
199 typedef __WCHAR_TYPE__ wxChar;
200 typedef __WCHAR_TYPE__ wxSChar;
201 typedef __WCHAR_TYPE__ wxUChar;
202 #endif /* __WCHAR_TYPE__ */
203 #endif /* ASCII/Unicode */
204
205 /* ---------------------------------------------------------------------------- */
206 /* define _T() and related macros */
207 /* ---------------------------------------------------------------------------- */
208
209 /* BSD systems define _T() to be something different in ctype.h, override it */
210 #if defined(__FreeBSD__) || defined(__DARWIN__)
211 #include <ctype.h>
212 #undef _T
213 #endif
214
215 /* could already be defined by tchar.h (it's quasi standard) */
216 #ifndef _T
217 #if !wxUSE_UNICODE
218 #define _T(x) x
219 #else /* Unicode */
220 #define _T(x) L ## x
221 #endif /* ASCII/Unicode */
222 #endif /* !defined(_T) */
223
224 /* although global macros with such names are normally bad, we want to have */
225 /* another name for _T() which should be used to avoid confusion between _T() */
226 /* and _() in wxWidgets sources */
227 #define wxT(x) _T(x)
228
229 /* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */
230 #ifndef __TFILE__
231 #define __XFILE__(x) wxT(x)
232 #define __TFILE__ __XFILE__(__FILE__)
233 #endif
234
235 #ifndef __TDATE__
236 #define __XDATE__(x) wxT(x)
237 #define __TDATE__ __XDATE__(__DATE__)
238 #endif
239
240 #ifndef __TTIME__
241 #define __XTIME__(x) wxT(x)
242 #define __TTIME__ __XTIME__(__TIME__)
243 #endif
244
245 /*
246 define wxFoo() function for each standard foo() function whose signature
247 (exceptionally including the return type) includes any mention of char:
248 wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
249 the same signature but with char replaced by wxChar which allows us to use
250 it in Unicode build as well
251 */
252
253 #ifdef wxHAVE_TCHAR_SUPPORT
254 #include <ctype.h>
255
256 #if defined(__WATCOMC__) && defined(UNICODE)
257 #define WXWCHAR_T_CAST(c) (wint_t)(c)
258 #else
259 #define WXWCHAR_T_CAST(c) c
260 #endif
261
262 /* ctype.h functions */
263 #define wxIsalnum(c) _istalnum(WXWCHAR_T_CAST(c))
264 #define wxIsalpha(c) _istalpha(WXWCHAR_T_CAST(c))
265 #define wxIscntrl(c) _istcntrl(WXWCHAR_T_CAST(c))
266 #define wxIsdigit(c) _istdigit(WXWCHAR_T_CAST(c))
267 #define wxIsgraph(c) _istgraph(WXWCHAR_T_CAST(c))
268 #define wxIslower(c) _istlower(WXWCHAR_T_CAST(c))
269 #define wxIsprint(c) _istprint(WXWCHAR_T_CAST(c))
270 #define wxIspunct(c) _istpunct(WXWCHAR_T_CAST(c))
271 #define wxIsspace(c) _istspace(WXWCHAR_T_CAST(c))
272 #define wxIsupper(c) _istupper(WXWCHAR_T_CAST(c))
273 #define wxIsxdigit(c) _istxdigit(WXWCHAR_T_CAST(c))
274
275 /*
276 There is a bug in VC6 C RTL: toxxx() functions dosn't do anything with
277 signed chars < 0, so "fix" it here.
278 */
279 #define wxTolower(c) _totlower((wxUChar)(c))
280 #define wxToupper(c) _totupper((wxUChar)(c))
281
282 /* locale.h functons */
283 #define wxSetlocale _tsetlocale
284
285 /* string.h functions */
286 #define wxStrcat _tcscat
287 #define wxStrchr _tcschr
288 #define wxStrcmp _tcscmp
289 #define wxStrcoll _tcscoll
290 #define wxStrcpy _tcscpy
291 #define wxStrcspn _tcscspn
292 #define wxStrdupW _wcsdup /* notice the 'W'! */
293 #define wxStrftime _tcsftime
294 #define wxStricmp _tcsicmp
295 #define wxStrnicmp _tcsnicmp
296 #define wxStrlen_ _tcslen /* used in wxStrlen inline function */
297 #define wxStrncat _tcsncat
298 #define wxStrncmp _tcsncmp
299 #define wxStrncpy _tcsncpy
300 #define wxStrpbrk _tcspbrk
301 #define wxStrrchr _tcsrchr
302 #define wxStrspn _tcsspn
303 #define wxStrstr _tcsstr
304 #define wxStrtod _tcstod
305 #define wxStrtol _tcstol
306 #define wxStrtoul _tcstoul
307 #define wxStrxfrm _tcsxfrm
308
309 /* stdio.h functions */
310 #define wxFgetc _fgettc
311 #define wxFgetchar _fgettchar
312 #define wxFgets _fgetts
313 #if wxUSE_UNICODE_MSLU
314 #define wxFopen wxMSLU__tfopen
315 #else
316 #define wxFopen _tfopen
317 #endif
318 #define wxFputc _fputtc
319 #define wxFputchar _fputtchar
320 #define wxFprintf _ftprintf
321 #define wxFputs _fputts
322 #define wxFreopen _tfreopen
323 #define wxFscanf _ftscanf
324 #define wxGetc _gettc
325 #define wxGetchar _gettchar
326 #define wxGets _getts
327 #define wxPerror _tperror
328 #define wxPrintf _tprintf
329 #define wxPutc(c,f) _puttc(WXWCHAR_T_CAST(c),f)
330 #define wxPutchar _puttchar
331 #define wxPuts _putts
332 #define wxScanf _tscanf
333 #if defined(__DMC__)
334 #if wxUSE_UNICODE
335 /* Digital Mars adds count to _stprintf (C99) so prototype conversion see wxchar.cpp */
336 int wxSprintf (wchar_t * __RESTRICT s, const wchar_t * __RESTRICT format, ... ) ;
337 #else
338 /* and there is a bug in D Mars tchar.h prior to 8.39.4n, so define as sprintf */
339 #define wxSprintf sprintf
340 #endif
341 #else
342 #define wxSprintf _stprintf
343 #endif
344
345 #define wxSscanf _stscanf
346 #define wxTmpnam _ttmpnam
347 #define wxUngetc _tungetc
348 #define wxVfprintf _vftprintf
349 #define wxVprintf _vtprintf
350 #define wxVsscanf _vstscanf
351 #define wxVsprintf _vstprintf
352
353 /* special case: not all TCHAR-aware compilers have those */
354 #if defined(__VISUALC__) || \
355 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
356 #define wxVsnprintf_ _vsntprintf
357 #define wxSnprintf_ _sntprintf
358 #endif
359
360 /* special case: these functions are missing under Win9x with Unicows so we */
361 /* have to implement them ourselves */
362 #if wxUSE_UNICODE_MSLU
363 #define wxRemove wxMSLU__tremove
364 #define wxRename wxMSLU__trename
365 #else
366 #ifdef __WXWINCE__
367 /* carefully: wxRemove() must return 0 on success while DeleteFile()
368 returns 0 on error, so don't just define one as the other */
369 int wxRemove(const wxChar *path);
370 #else
371 #define wxRemove _tremove
372 #define wxRename _trename
373 #endif
374 #endif
375
376 /* stdlib.h functions */
377 #define wxAtoi _ttoi
378 #define wxAtol _ttol
379 /* #define wxAtof _tttof -- notice that there is no such thing (why?) */
380 /* there are no env vars at all under CE, so no _tgetenv neither */
381 #ifdef __WXWINCE__
382 /* can't define as inline function as this is a C file... */
383 #define wxGetenv(name) ((wxChar *)NULL)
384 #else
385 #define wxGetenv _tgetenv
386 #endif
387 #define wxSystem _tsystem
388
389 /* time.h functions */
390 #define wxAsctime _tasctime
391 #define wxCtime _tctime
392
393 #define wxMbstowcs mbstowcs
394 #define wxWcstombs wcstombs
395 #else /* !TCHAR-aware compilers */
396
397 #if !defined(__MWERKS__) && defined(__DARWIN__) && ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
398 /* even though they are defined and "implemented", they are bad and just
399 stubs so we need our own - we need these even in ANSI builds!! */
400 WXDLLIMPEXP_BASE size_t wxMbstowcs (wchar_t *, const char *, size_t);
401 WXDLLIMPEXP_BASE size_t wxWcstombs (char *, const wchar_t *, size_t);
402 #else
403 #define wxMbstowcs mbstowcs
404 #define wxWcstombs wcstombs
405 #endif
406
407 /* No UNICODE in the c library except wchar_t typedef on mac OSX 10.2 and less - roll our own */
408 #if !defined(__MWERKS__) && wxUSE_UNICODE && defined(__DARWIN__) && ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
409
410 /* we need everything! */
411 #define wxNEED_WX_STRING_H
412 #define wxNEED_WX_CTYPE_H
413
414 #define wxFgetchar(c) wxFgetc(c, stdin)
415 #define wxFputc wxPutc
416 #define wxFputchar(c) wxPutc(c, stdout)
417 #define wxGetc wxFgetc
418 #define wxGetchar(c) wxFgetc(c, stdin)
419
420 #include <stdio.h>
421
422 #define wxNEED_FGETC
423 #define wxNEED_FGETS
424 #define wxNEED_GETS
425 #define wxNEED_UNGETC
426
427 #define wxNEED_FPUTS
428 #define wxNEED_PUTS
429 #define wxNEED_PUTC
430
431 int wxFputs(const wxChar *ch, FILE *stream);
432 int wxPuts(const wxChar *ws);
433 int wxPutc(wxChar ch, FILE *stream);
434
435 #ifdef __cplusplus
436 extern "C" {
437 #endif
438 WXDLLIMPEXP_BASE size_t wxStrlen_(const wxChar *s);
439 #ifdef __cplusplus
440 }
441 #endif
442
443 #define wxPutchar(wch) wxPutc(wch, stdout)
444
445 #define wxNEED_PRINTF_CONVERSION
446 #define wxNEED_WX_STDIO_H
447 #define wxNEED_WX_STDLIB_H
448 #define wxNEED_WX_TIME_H
449
450 #elif wxUSE_UNICODE
451 #include <wctype.h>
452
453 /* this is probably glibc-specific */
454 #if defined(__WCHAR_TYPE__) && !defined(__MWERKS__)
455 /* ctype.h functions (wctype.h) */
456 #define wxIsalnum iswalnum
457 #define wxIsalpha iswalpha
458 #define wxIscntrl iswcntrl
459 #define wxIsdigit iswdigit
460 #define wxIsgraph iswgraph
461 #define wxIslower iswlower
462 #define wxIsprint iswprint
463 #define wxIspunct iswpunct
464 #define wxIsspace iswspace
465 #define wxIsupper iswupper
466 #define wxIsxdigit iswxdigit
467
468 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
469 /* /usr/include/wctype.h incorrectly declares translations */
470 /* tables which provokes tons of compile-time warnings -- try */
471 /* to correct this */
472 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
473 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
474 #else /* !glibc 2.0 */
475 #define wxTolower towlower
476 #define wxToupper towupper
477 #endif /* gcc/!gcc */
478
479 /* string.h functions (wchar.h) */
480 #define wxStrcat wcscat
481 #define wxStrchr wcschr
482 #define wxStrcmp wcscmp
483 #define wxStrcoll wcscoll
484 #define wxStrcpy wcscpy
485 #define wxStrcspn wcscspn
486 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
487 #define wxStrncat wcsncat
488 #define wxStrncmp wcsncmp
489 #define wxStrncpy wcsncpy
490 #define wxStrpbrk wcspbrk
491 #define wxStrrchr wcsrchr
492 #define wxStrspn wcsspn
493 #define wxStrstr wcsstr
494 #define wxStrtod wcstod
495 #define wxStrtol wcstol
496 #define wxStrtoul wcstoul
497 #define wxStrxfrm wcsxfrm
498
499 #define wxFgetc fgetwc
500 #define wxFgetchar fgetwchar
501 #define wxFgets fgetws
502 #define wxFputc fputwc
503 #define wxFputchar fputwchar
504 #define wxGetc getwc
505 #define wxGetchar getwchar
506 #define wxGets getws
507 #define wxUngetc ungetwc
508
509 #ifdef HAVE_FPUTWS
510 #define wxFputs fputws
511 #else
512 #define wxNEED_FPUTS
513 #include <stdio.h>
514 int wxFputs(const wxChar *ch, FILE *stream);
515 #endif
516
517 #ifdef HAVE_WPUTC
518 #define wxPutc wputc
519 #else
520 #define wxNEED_PUTC
521 #include <stdio.h>
522 int wxPutc(wxChar ch, FILE *stream);
523 #endif
524
525 #ifdef HAVE_WPUTCHAR
526 #define wxPutchar wputchar
527 #else
528 #define wxPutchar(wch) wxPutc(wch, stdout)
529 #endif
530
531 #ifdef HAVE_PUTWS
532 #define wxPuts putws
533 #else
534 #define wxNEED_PUTS
535 int wxPuts(const wxChar *ws);
536 #endif
537
538 /* we need %s to %ls conversion for printf and scanf etc */
539 #define wxNEED_PRINTF_CONVERSION
540
541 /* glibc doesn't have wide char equivalents of the other stuff so */
542 /* use our own versions */
543 #define wxNEED_WX_STDIO_H
544 #define wxNEED_WX_STDLIB_H
545 #define wxNEED_WX_TIME_H
546 #elif defined(__MWERKS__) && ( defined(__MSL__) || defined(__MACH__) )
547 /* ctype.h functions (wctype.h) */
548 #define wxIsalnum iswalnum
549 #define wxIsalpha iswalpha
550 #define wxIscntrl iswcntrl
551 #define wxIsdigit iswdigit
552 #define wxIsgraph iswgraph
553 #define wxIslower iswlower
554 #define wxIsprint iswprint
555 #define wxIspunct iswpunct
556 #define wxIsspace iswspace
557 #define wxIsupper iswupper
558 #define wxIsxdigit iswxdigit
559 #define wxTolower towlower
560 #define wxToupper towupper
561
562 /* string.h functions (wchar.h) */
563 #define wxStrcat wcscat
564 #define wxStrchr wcschr
565 #define wxStrcmp wcscmp
566 #define wxStrcoll wcscoll
567 #define wxStrcpy wcscpy
568 #define wxStrcspn wcscspn
569 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
570 #define wxStrncat wcsncat
571 #define wxStrncmp wcsncmp
572 #define wxStrncpy wcsncpy
573 #define wxStrpbrk wcspbrk
574 #define wxStrrchr wcsrchr
575 #define wxStrspn wcsspn
576 #define wxStrstr wcsstr
577 #define wxStrtod wcstod
578 #define wxStrtol wcstol
579 #define wxStrtoul wcstoul
580 #define wxStrxfrm wcsxfrm
581
582 #define wxFgetc fgetwc
583 #define wxFgetchar fgetwchar
584 #define wxFgets fgetws
585 #define wxFputc fputwc
586 #define wxFputchar fputwchar
587 #define wxGetc getwc
588 #define wxGetchar getwchar
589 #define wxGets getws
590 #define wxUngetc ungetwc
591
592 #define wxNEED_PRINTF_CONVERSION
593
594 #define wxPutc putwc
595 #define wxPutchar putwchar
596 #define wxFputs fputws
597
598 /* stdio.h functions */
599
600 #define wxNEED_WX_STDIO_H
601
602 /* stdlib.h functions */
603 #ifdef __MACH__
604 #define wxNEED_WX_STDLIB_H
605 #else
606 #define wxAtof watof
607 #define wxAtoi watoi
608 #define wxAtol watol
609 #define wxGetenv(a) ((wxChar*)NULL)
610 #define wxSystem(a) ((int)NULL)
611 #endif
612 /* time.h functions */
613 #define wxAsctime wasciitime
614 #define wxCtime wctime
615 /* #define wxStrftime wcsftime */
616
617 #define wxNEED_WX_TIME_H
618 #else /* !metrowerks for apple */
619 #error "Please define wide character functions for your environment"
620 #endif
621 #else /* ASCII */
622 #include <ctype.h>
623 #include <string.h>
624
625 /* ctype.h functions */
626 #define wxIsalnum isalnum
627 #define wxIsalpha isalpha
628 #define wxIscntrl iscntrl
629 #define wxIsdigit isdigit
630 #define wxIsgraph isgraph
631 #define wxIslower islower
632 #define wxIsprint isprint
633 #define wxIspunct ispunct
634 #define wxIsspace isspace
635 #define wxIsupper isupper
636 #define wxIsxdigit isxdigit
637 #define wxTolower tolower
638 #define wxToupper toupper
639
640 /* locale.h functons */
641 #define wxSetlocale setlocale
642
643 /* string.h functions */
644 #define wxStrcat strcat
645 #define wxStrchr strchr
646 #define wxStrcmp strcmp
647 #define wxStrcoll strcoll
648 #define wxStrcpy strcpy
649 #define wxStrcspn strcspn
650
651 /* wxStricmp and wxStrnicmp are defined below */
652 #define wxStrlen_ strlen /* used in wxStrlen inline function */
653 #define wxStrncat strncat
654 #define wxStrncmp strncmp
655 #define wxStrncpy strncpy
656 #define wxStrpbrk strpbrk
657 #define wxStrrchr strrchr
658 #define wxStrspn strspn
659 #define wxStrstr strstr
660 #define wxStrtod strtod
661 #ifdef HAVE_STRTOK_R
662 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
663 #endif
664 #define wxStrtol strtol
665 #define wxStrtoul strtoul
666 #define wxStrxfrm strxfrm
667
668 /* stdio.h functions */
669 #define wxFopen fopen
670 #define wxFreopen freopen
671 #define wxRemove remove
672 #define wxRename rename
673
674 #define wxPerror perror
675 #define wxTmpnam tmpnam
676
677 #define wxFgetc fgetc
678 #define wxFgetchar fgetchar
679 #define wxFgets fgets
680 #define wxFputc fputc
681 #define wxFputs fputs
682 #define wxFputchar fputchar
683 #define wxFprintf fprintf
684 #define wxFscanf fscanf
685 #define wxGetc getc
686 #define wxGetchar getchar
687 #define wxGets gets
688 #define wxPrintf printf
689 #define wxPutc putc
690 #define wxPutchar putchar
691 #define wxPuts puts
692 #define wxScanf scanf
693 #define wxSprintf sprintf
694 #define wxSscanf sscanf
695 #define wxUngetc ungetc
696 #define wxVfprintf vfprintf
697 #define wxVprintf vprintf
698 #define wxVsscanf vsscanf
699 #define wxVsprintf vsprintf
700
701 /* stdlib.h functions */
702 #define wxAtof atof
703 #define wxAtoi atoi
704 #define wxAtol atol
705 #define wxGetenv getenv
706 #define wxSystem system
707
708 /* time.h functions */
709 #define wxAsctime asctime
710 #define wxCtime ctime
711 #define wxStrftime strftime
712 #endif /* Unicode/ASCII */
713 #endif /* TCHAR-aware compilers/the others */
714
715 /*
716 various special cases
717 */
718
719 /* define wxStricmp and wxStrnicmp for various compilers */
720
721 /* note that in Unicode mode we definitely are going to need our own version */
722 #if !defined(wxStricmp) && !wxUSE_UNICODE
723 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
724 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
725 defined(__EMX__) || defined(__DJGPP__)
726 #define wxStricmp stricmp
727 #define wxStrnicmp strnicmp
728 #elif defined(__WXPALMOS__)
729 /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
730 * quick hack should do until one can be written.
731 */
732 #define wxStricmp StrCaselessCompare
733 #define wxStrnicmp strnicmp
734 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
735 (defined(__MWERKS__) && defined(__INTEL__))
736 #define wxStricmp _stricmp
737 #define wxStrnicmp _strnicmp
738 #elif defined(__UNIX__) || defined(__GNUWIN32__)
739 #define wxStricmp strcasecmp
740 #define wxStrnicmp strncasecmp
741 /* #else -- use wxWidgets implementation */
742 #endif
743 #endif /* !defined(wxStricmp) */
744
745 /* define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as */
746 /* it's used in wx/buffer.h -- and also might be used just below by wxStrlen() */
747 /* when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen) */
748 #if wxUSE_WCHAR_T
749 #ifdef HAVE_WCSLEN
750 #define wxWcslen wcslen
751 #else
752 WXDLLIMPEXP_BASE size_t wxWcslen(const wchar_t *s);
753 #endif
754 #endif /* wxUSE_WCHAR_T */
755
756 #ifdef __cplusplus
757 /* checks whether the passed in pointer is NULL and if the string is empty */
758 inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
759
760 /* safe version of strlen() (returns 0 if passed NULL pointer) */
761 inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
762 #endif
763
764 /*
765 each of strdup() and wcsdup() may or may not be available but we need both
766 of them anyhow for wx/buffer.h so we define the missing one(s) in
767 wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
768 defined -- if this is somehow not the case in some situations, please
769 correct that and not the lines here
770 */
771 #if wxUSE_UNICODE
772 #define wxStrdup wxStrdupW
773 #else
774 #define wxStrdup wxStrdupA
775 #endif
776
777 #ifdef __cplusplus
778 WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
779 #endif
780
781 /* printf() family saga */
782
783 /*
784 For some systems [v]snprintf() exists in the system libraries but not in the
785 headers, so we need to declare it ourselves to be able to use it.
786 */
787 #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
788 #ifdef __cplusplus
789 extern "C"
790 #else
791 extern
792 #endif
793 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
794 #endif /* !HAVE_VSNPRINTF_DECL */
795
796 #if defined(HAVE_SNPRINTF) && !defined(HAVE_SNPRINTF_DECL)
797 #ifdef __cplusplus
798 extern "C"
799 #else
800 extern
801 #endif
802 int snprintf(char *str, size_t size, const char *format, ...);
803 #endif /* !HAVE_SNPRINTF_DECL */
804
805 /*
806 First of all, we always want to define safe snprintf() function to be used
807 instead of sprintf(). Some compilers already have it (or rather vsnprintf()
808 which we really need...), otherwise we implement it using our own printf()
809 code.
810
811 We define function with a trailing underscore here because the real one is a
812 wrapper around it as explained below
813 */
814 #ifndef wxVsnprintf_
815 #if wxUSE_UNICODE
816 #if defined(__MWERKS__)
817 #define HAVE_WCSRTOMBS 1
818 #define HAVE_VSWPRINTF 1
819 #endif
820 #if defined(__WATCOMC__)
821 #define wxVsnprintf_ _vsnwprintf
822 #define wxSnprintf_ _snwprintf
823 #endif
824 #if defined(HAVE__VSNWPRINTF)
825 #define wxVsnprintf_ _vsnwprintf
826 /* MinGW?MSVCRT has the wrong vswprintf */
827 #elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__)
828 #define wxVsnprintf_ vswprintf
829 #endif
830 #else /* ASCII */
831 /* all versions of CodeWarrior supported by wxWidgets apparently have */
832 /* both snprintf() and vsnprintf() */
833 #ifdef HAVE_SNPRINTF || defined(__MWERKS__) || defined(__WATCOMC__)
834 #define wxSnprintf_ snprintf
835 #endif
836 #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__) || defined(__WATCOMC__)
837 #define wxVsnprintf_ vsnprintf
838 #endif
839 #endif
840 #endif /* wxVsnprintf_ not defined yet */
841
842 #ifndef wxSnprintf_
843 /* no [v]snprintf(), cook our own */
844 WXDLLIMPEXP_BASE int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
845 ...) ATTRIBUTE_PRINTF_3;
846 #endif
847 #ifndef wxVsnprintf_
848 WXDLLIMPEXP_BASE int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
849 va_list argptr);
850 #endif
851
852 /*
853 In Unicode mode we need to have all standard functions such as wprintf() and
854 so on but not all systems have them so use our own implementations in this
855 case.
856 */
857 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
858 #define wxNEED_WPRINTF
859 #endif
860
861 /*
862 More Unicode complications: although both ANSI C and C++ define a number of
863 wide character functions such as wprintf(), not all environments have them.
864 Worse, those which do have different behaviours: under Windows, %s format
865 specifier changes its meaning in Unicode build and expects a Unicode string
866 while under Unix/POSIX it still means an ASCII string even for wprintf() and
867 %ls has to be used for wide strings.
868
869 We choose to always emulate Windows behaviour as more useful for us so even
870 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
871
872 */
873
874 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
875 /*
876 we need to implement all wide character printf and scanf functions
877 either because we don't have them at all or because they don't have the
878 semantics we need
879 */
880
881 #include <stdio.h> /* for FILE */
882
883 int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
884 int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
885 int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
886 int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap );
887 int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
888 int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
889 int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
890 int wxVfprintf( FILE *stream, const wxChar *format, va_list ap );
891 int wxVprintf( const wxChar *format, va_list ap );
892 int wxVsprintf( wxChar *str, const wxChar *format, va_list ap );
893 #endif /* wxNEED_PRINTF_CONVERSION */
894
895 /* these 2 can be simply mapped to the versions with underscore at the end */
896 /* if we don't have to do the conversion */
897 /*
898 However, if we don't have any vswprintf() at all we don't need to redefine
899 anything as our own wxVsnprintf_() already behaves as needed.
900 */
901 #if defined(wxNEED_PRINTF_CONVERSION) && defined(wxVsnprintf_)
902 int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
903 int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
904 #else
905 #define wxSnprintf wxSnprintf_
906 #define wxVsnprintf wxVsnprintf_
907 #endif
908
909 /*
910 various functions which might not be available in libc and for which we
911 provide our own replacements in wxchar.cpp
912 */
913
914 /* ctype.h functions */
915
916 /* RN: Used only under OSX <= 10.2 currently */
917 #ifdef wxNEED_WX_CTYPE_H
918 WXDLLIMPEXP_BASE int wxIsalnum(wxChar ch);
919 WXDLLIMPEXP_BASE int wxIsalpha(wxChar ch);
920 WXDLLIMPEXP_BASE int wxIscntrl(wxChar ch);
921 WXDLLIMPEXP_BASE int wxIsdigit(wxChar ch);
922 WXDLLIMPEXP_BASE int wxIsgraph(wxChar ch);
923 WXDLLIMPEXP_BASE int wxIslower(wxChar ch);
924 WXDLLIMPEXP_BASE int wxIsprint(wxChar ch);
925 WXDLLIMPEXP_BASE int wxIspunct(wxChar ch);
926 WXDLLIMPEXP_BASE int wxIsspace(wxChar ch);
927 WXDLLIMPEXP_BASE int wxIsupper(wxChar ch);
928 WXDLLIMPEXP_BASE int wxIsxdigit(wxChar ch);
929 WXDLLIMPEXP_BASE int wxTolower(wxChar ch);
930 WXDLLIMPEXP_BASE int wxToupper(wxChar ch);
931 #endif /* wxNEED_WX_CTYPE_H */
932
933 /* under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks */
934 /* the file parsing -- this may be true for 5.0 as well, update #ifdef then */
935 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
936 #undef wxIsspace
937 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
938 #endif /* VC++ */
939
940 /*
941 a few compilers don't have the (non standard but common) isascii function,
942 define it ourselves for them
943 */
944 #ifndef isascii
945 #if defined(__MWERKS__)
946 #define wxNEED_ISASCII
947 #elif defined(_WIN32_WCE)
948 #if _WIN32_WCE <= 211
949 #define wxNEED_ISASCII
950 #endif
951 #endif
952 #endif /* isascii */
953
954 #ifdef wxNEED_ISASCII
955 inline int isascii(int c) { return (unsigned)c < 0x80; }
956 #endif
957
958 #ifdef _WIN32_WCE
959 #if _WIN32_WCE <= 211
960 #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
961 #endif
962 #endif /* _WIN32_WCE */
963
964 /*
965 we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
966 initial versions of this header -- now it is too late to remove it so
967 although we fixed the function/macro name above, still provide the
968 backwards-compatible synonym.
969 */
970 #define wxIsctrl wxIscntrl
971
972 /* string.h functions */
973 #ifndef strdup
974 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
975 #define wxNEED_STRDUP
976 #elif defined(__WXWINCE__)
977 #if _WIN32_WCE <= 211
978 #define wxNEED_STRDUP
979 #endif
980 #endif
981 #endif /* strdup */
982
983 #ifdef wxNEED_STRDUP
984 WXDLLIMPEXP_BASE char *strdup(const char* s);
985 #endif
986
987 /* RN: Used only under OSX <= 10.2 currently
988 The __cplusplus ifdefs are messy, but they are required to build
989 the regex library, since c does not support function overloading
990 */
991 #ifdef wxNEED_WX_STRING_H
992 # ifdef __cplusplus
993 extern "C" {
994 # endif
995 WXDLLIMPEXP_BASE wxChar * wxStrcat(wxChar *dest, const wxChar *src);
996 WXDLLIMPEXP_BASE const wxChar * wxStrchr(const wxChar *s, wxChar c);
997 WXDLLIMPEXP_BASE int wxStrcmp(const wxChar *s1, const wxChar *s2);
998 WXDLLIMPEXP_BASE int wxStrcoll(const wxChar *s1, const wxChar *s2);
999 WXDLLIMPEXP_BASE wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
1000 WXDLLIMPEXP_BASE size_t wxStrcspn(const wxChar *s, const wxChar *reject);
1001 WXDLLIMPEXP_BASE wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
1002 WXDLLIMPEXP_BASE int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
1003 WXDLLIMPEXP_BASE wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
1004 WXDLLIMPEXP_BASE const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
1005 WXDLLIMPEXP_BASE const wxChar * wxStrrchr(const wxChar *s, wxChar c);
1006 WXDLLIMPEXP_BASE size_t wxStrspn(const wxChar *s, const wxChar *accept);
1007 WXDLLIMPEXP_BASE const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
1008 # ifdef __cplusplus
1009 }
1010 # endif
1011
1012 /* These functions use C++, so we can't c extern them */
1013 WXDLLIMPEXP_BASE double wxStrtod(const wxChar *nptr, wxChar **endptr);
1014 WXDLLIMPEXP_BASE long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
1015 WXDLLIMPEXP_BASE unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
1016 WXDLLIMPEXP_BASE size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
1017
1018 /* inlined versions */
1019 #ifdef __cplusplus
1020 inline wxChar * wxStrchr(wxChar *s, wxChar c)
1021 { return (wxChar *)wxStrchr((const wxChar *)s, c); }
1022 inline wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
1023 { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
1024 inline wxChar * wxStrrchr(wxChar *s, wxChar c)
1025 { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
1026 inline wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
1027 { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
1028 #endif
1029
1030 #endif /* wxNEED_WX_STRING_H */
1031
1032 #ifndef wxStrdupA
1033 WXDLLIMPEXP_BASE char *wxStrdupA(const char *psz);
1034 #endif
1035
1036 #ifndef wxStrdupW
1037 WXDLLIMPEXP_BASE wchar_t *wxStrdupW(const wchar_t *pwz);
1038 #endif
1039
1040 #ifndef wxStricmp
1041 WXDLLIMPEXP_BASE int wxStricmp(const wxChar *psz1, const wxChar *psz2);
1042 #endif
1043
1044 #ifndef wxStrnicmp
1045 WXDLLIMPEXP_BASE int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
1046 #endif
1047
1048 #ifndef wxStrtok
1049 WXDLLIMPEXP_BASE wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
1050 #endif
1051
1052 #ifdef __cplusplus
1053 #ifndef wxSetlocale
1054 class WXDLLIMPEXP_BASE wxWCharBuffer;
1055 WXDLLIMPEXP_BASE wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
1056 #endif
1057 #endif
1058
1059 /* stdio.h functions */
1060 #ifdef wxNEED_WX_STDIO_H
1061 #include <stdio.h>
1062 WXDLLIMPEXP_BASE FILE * wxFopen(const wxChar *path, const wxChar *mode);
1063 WXDLLIMPEXP_BASE FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
1064 WXDLLIMPEXP_BASE int wxRemove(const wxChar *path);
1065 WXDLLIMPEXP_BASE int wxRename(const wxChar *oldpath, const wxChar *newpath);
1066
1067 /* *printf() family is handled separately */
1068 #endif /* wxNEED_WX_STDIO_H */
1069
1070
1071 /* stdlib.h functions */
1072 #ifndef wxAtof
1073 WXDLLIMPEXP_BASE double wxAtof(const wxChar *psz);
1074 #endif
1075
1076 #ifdef wxNEED_WX_STDLIB_H
1077 WXDLLIMPEXP_BASE int wxAtoi(const wxChar *psz);
1078 WXDLLIMPEXP_BASE long wxAtol(const wxChar *psz);
1079 WXDLLIMPEXP_BASE wxChar * wxGetenv(const wxChar *name);
1080 WXDLLIMPEXP_BASE int wxSystem(const wxChar *psz);
1081 #endif
1082
1083
1084 /* time.h functions */
1085 #ifdef wxNEED_WX_TIME_H
1086 #if defined(__MWERKS__) && defined(macintosh)
1087 #include <time.h>
1088 #endif
1089 /*silent gabby compilers*/
1090 struct tm;
1091 WXDLLIMPEXP_BASE size_t wxStrftime(wxChar *s, size_t max,
1092 const wxChar *fmt, const struct tm *tm);
1093 #endif /* wxNEED_WX_TIME_H */
1094
1095 #ifndef wxCtime
1096 #include <time.h>
1097 WXDLLIMPEXP_BASE wxChar *wxCtime(const time_t *timep);
1098 #endif
1099
1100
1101 /* missing functions in some WinCE versions */
1102 #ifdef _WIN32_WCE
1103 #if (_WIN32_WCE < 300)
1104 WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
1105 #endif
1106 #endif /* _WIN32_WCE */
1107
1108 /* multibyte to wide char conversion functions and macros */
1109
1110 #if wxUSE_WCHAR_T
1111 /* multibyte<->widechar conversion */
1112 WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
1113 WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
1114
1115 #if wxUSE_UNICODE
1116 #define wxMB2WX wxMB2WC
1117 #define wxWX2MB wxWC2MB
1118 #define wxWC2WX wxStrncpy
1119 #define wxWX2WC wxStrncpy
1120 #else
1121 #define wxMB2WX wxStrncpy
1122 #define wxWX2MB wxStrncpy
1123 #define wxWC2WX wxWC2MB
1124 #define wxWX2WC wxMB2WC
1125 #endif
1126 #else /* !wxUSE_UNICODE */
1127 /* Why is this here?
1128 #error ha */
1129 /* No wxUSE_WCHAR_T: we have to do something (JACS) */
1130 #define wxMB2WC wxStrncpy
1131 #define wxWC2MB wxStrncpy
1132 #define wxMB2WX wxStrncpy
1133 #define wxWX2MB wxStrncpy
1134 #define wxWC2WX wxWC2MB
1135 #define wxWX2WC wxMB2WC
1136 #endif
1137
1138 /*
1139 RN: The following are not normal versions of memcpy et al., rather
1140 these are either char or widechar versions depending on
1141 if unicode is used or not.
1142 */
1143
1144 #ifdef __cplusplus
1145
1146 //
1147 // RN: We could do the usual tricky compiler detection here,
1148 // and use their variant (such as wmemchr, etc.). The problem
1149 // is that these functions are quite rare, even though they are
1150 // part of the current POSIX standard. In addition, most compilers
1151 // (including even MSC) inline them just like we do right in their
1152 // headers.
1153 //
1154 #if wxUSE_UNICODE
1155 #include <string.h> //for mem funcs
1156
1157 //implement our own wmem variants
1158 inline wxChar* wxTmemchr(const wxChar* s, wxChar c, size_t l)
1159 {
1160 for(;l && *s != c;--l, ++s) {}
1161
1162 if(l)
1163 return (wxChar*)s;
1164 return NULL;
1165 }
1166
1167 inline int wxTmemcmp(const wxChar* sz1, const wxChar* sz2, size_t len)
1168 {
1169 for(; *sz1 == *sz2 && len; --len, ++sz1, ++sz2) {}
1170
1171 if(len)
1172 return *sz1 < *sz2 ? -1 : *sz1 > *sz2;
1173 else
1174 return 0;
1175 }
1176
1177 inline wxChar* wxTmemcpy(wxChar* szOut, const wxChar* szIn, size_t len)
1178 {
1179 return (wxChar*) memcpy(szOut, szIn, len * sizeof(wxChar));
1180 }
1181
1182 inline wxChar* wxTmemmove(wxChar* szOut, const wxChar* szIn, size_t len)
1183 {
1184 return (wxChar*) memmove(szOut, szIn, len * sizeof(wxChar));
1185 }
1186
1187 inline wxChar* wxTmemset(wxChar* szOut, const wxChar cIn, size_t len)
1188 {
1189 wxChar* szRet = szOut;
1190
1191 while (len--)
1192 *szOut++ = cIn;
1193
1194 return szRet;
1195 }
1196
1197 #else //!wxUSE_UNICODE
1198 # define wxTmemchr memchr
1199 # define wxTmemcmp memcmp
1200 # define wxTmemcpy memcpy
1201 # define wxTmemmove memmove
1202 # define wxTmemset memset
1203 #endif
1204
1205 #endif /*__cplusplus*/
1206
1207
1208 #endif /* _WX_WXCHAR_H_ */
1209