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