_cwchar.h revision 9720d5f59b9c1f5d1b9ecbc9173dbcb71bd557be
15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
2926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * Copyright (c) 1999
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Boris Fomitchev
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This material is provided "as is", with absolutely no warranty expressed
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * or implied. Any use is at your own risk.
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Permission to use or copy this software for any purpose is hereby granted
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * without fee, provided the above notices are retained on all copies.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Permission to modify the code and to distribute modified code is granted,
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * provided the above notices are retained, and a notice that the code was
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modified is included with the above copyright notice.
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef _STLP_INTERNAL_CWCHAR
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define _STLP_INTERNAL_CWCHAR
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if defined (_STLP_WCE_EVC3)
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#  ifndef _STLP_INTERNAL_MBSTATE_T
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#    include <stl/_mbstate_t.h>
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#  endif
2302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#else
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#  if defined (__GNUC__)
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#    include _STLP_NATIVE_CPP_C_HEADER(cstddef)
2653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#  endif
2753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#  if !defined (_STLP_NO_CWCHAR) && defined (_STLP_USE_NEW_C_HEADERS)
298abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#    include _STLP_NATIVE_CPP_C_HEADER(cwchar)
3053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#    if defined (__OpenBSD__)
3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)typedef _BSD_WINT_T_ wint_t;
3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#    endif /* __OpenBSD__ */
338abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
3453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#  elif defined (_STLP_NO_WCHAR_T) || defined (__MRC__) || (defined (__SC__) && !defined (__DMC__)) || \
3553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)       (defined (__BORLANDC__) && (__BORLANDC__ < 0x580)) || \
365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        defined (__OpenBSD__) || defined (__FreeBSD__) || \
3753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)       (defined (__GNUC__) && (defined (__APPLE__) || defined ( __Lynx__ )))
385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#    include _STLP_NATIVE_C_HEADER(stddef.h)
3953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#    if defined (__Lynx__)
4053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#      ifndef _WINT_T
418abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)typedef long int wint_t;
4253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#        define _WINT_T
4353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#      endif /* _WINT_T */
4453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#    endif
4553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#    if defined(__OpenBSD__)
465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef _BSD_WINT_T_ wint_t;
475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#    endif /* __OpenBSD__ */
4853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#  elif defined (__MWERKS__) && defined (N_PLAT_NLM)
4953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#    include <wchar.h>
5053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#  elif !defined (ANDROID)
5153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// Android doesn't have a working wchar.h
5253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#    include _STLP_NATIVE_C_HEADER(wchar.h)
53926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
54#    if defined (__sun) && (defined (_XOPEN_SOURCE) || (_XOPEN_VERSION - 0 == 4))
55extern wint_t   btowc();
56extern int      fwprintf();
57extern int      fwscanf();
58extern int      fwide();
59extern int      mbsinit();
60extern size_t   mbrlen();
61extern size_t   mbrtowc();
62extern size_t   mbsrtowcs();
63extern int      swprintf();
64extern int      swscanf();
65extern int      vfwprintf();
66extern int      vwprintf();
67extern int      vswprintf();
68extern size_t   wcrtomb();
69extern size_t   wcsrtombs();
70extern wchar_t  *wcsstr();
71extern int      wctob();
72extern wchar_t  *wmemchr();
73extern int      wmemcmp();
74extern wchar_t  *wmemcpy();
75extern wchar_t  *wmemmove();
76extern wchar_t  *wmemset();
77extern int      wprintf();
78extern int      wscanf();
79#    endif
80#  endif
81
82#  if defined (__MSL__) && (__MSL__ <= 0x51FF)  /* dwa 2/28/99 - not yet implemented by MSL  */
83#    define _STLP_WCHAR_MSL_EXCLUDE 1
84namespace std {
85  extern "C" size_t wcsftime(wchar_t * str, size_t max_size, const wchar_t * format_str, const struct tm * timeptr);
86}
87#    define _STLP_NO_MBSTATE_T 1
88#  elif defined (__BORLANDC__)
89#    if !defined (_STLP_USE_NO_IOSTREAMS)
90#      define _STLP_NO_NATIVE_MBSTATE_T
91#    endif
92#    define _STLP_WCHAR_BORLAND_EXCLUDE 1
93#  endif
94
95#  ifndef _STLP_INTERNAL_MBSTATE_T
96#    include <stl/_mbstate_t.h>
97#  endif
98
99#  if !defined (_STLP_NO_WCHAR_T)
100#    ifndef WCHAR_MIN
101#      define WCHAR_MIN 0
102/* SUNpro has some bugs with casts. wchar_t is size of int there anyway. */
103#      if defined (__SUNPRO_CC) || defined (__DJGPP)
104#        define WCHAR_MAX (~0)
105#      else
106#        define WCHAR_MAX ((wchar_t)~0)
107#      endif
108#    endif
109#    if defined (__GNUC__) && defined (__alpha__)
110/* Definition of WCHAR_MIN and MAX are wrong for alpha platform
111 * as gcc consider wchar_t as an unsigned type. Static assertion are
112 * here to check that a future alpha SDK or a future gcc won't change the
113 * situation making this workaround useless.
114 */
115_STLP_STATIC_ASSERT(((wchar_t)-1 > 0) && (WCHAR_MIN < 0))
116#      undef WCHAR_MIN
117#      define WCHAR_MIN 0
118#      undef WCHAR_MAX
119#      define WCHAR_MAX ((wchar_t)~0)
120#    endif
121#    if defined(__HP_aCC) && (__HP_aCC >= 60000)
122/* Starting with B.11.31, HP-UX/ia64 provides C99-compliant definitions
123 * of WCHAR_MIN/MAX macros without having to define
124 * _INCLUDE_STDC__SOURCE_199901 macro (which aCC compiler does not
125 * predefine). Let STLport provide B.11.31 definitions on any version of
126 * HP-UX/ia64.
127 */
128#      undef WCHAR_MIN
129#      define WCHAR_MIN 0
130#      undef WCHAR_MAX
131#      define WCHAR_MAX UINT_MAX
132#    endif
133#  endif
134
135#  if defined (_STLP_IMPORT_VENDOR_CSTD)
136
137#    if defined (__SUNPRO_CC) && !defined (_STLP_HAS_NO_NEW_C_HEADERS)
138using _STLP_VENDOR_CSTD::wint_t;
139#    endif
140
141_STLP_BEGIN_NAMESPACE
142#    if defined (_STLP_NO_WCHAR_T)
143typedef int wint_t;
144#    else
145// gcc 3.0 has a glitch : wint_t only sucked into the global namespace if _GLIBCPP_USE_WCHAR_T is defined
146// __MWERKS__ has definition in wchar_t.h (MSL C++), but ones differ from definition
147// in stdio.h; I prefer settings from last file.
148#      if (defined (__GNUC__) && ! defined (_GLIBCPP_USE_WCHAR_T)) // || (defined(__MWERKS__) && defined(N_PLAT_NLM))
149using ::wint_t;
150#      else
151using _STLP_VENDOR_CSTD::wint_t;
152#      endif
153#    endif
154
155using _STLP_VENDOR_CSTD::size_t;
156
157#    if !defined (_STLP_NO_NATIVE_MBSTATE_T) && !defined (_STLP_USE_OWN_MBSTATE_T)
158using _STLP_VENDOR_MB_NAMESPACE::mbstate_t;
159
160#      if !defined (_STLP_NO_CSTD_FUNCTION_IMPORTS) && !defined(_STLP_WCHAR_BORLAND_EXCLUDE) && \
161         (!defined(__MSL__) || __MSL__ > 0x6001)
162#        if defined (__MINGW32__) && ((__MINGW32_MAJOR_VERSION > 3) || ((__MINGW32_MAJOR_VERSION == 3) && (__MINGW32_MINOR_VERSION >= 8))) || \
163          !(defined (__KCC) || defined (__GNUC__)) && !defined(_STLP_WCE_NET) && !(defined(__MWERKS__) && defined(N_PLAT_NLM))
164using _STLP_VENDOR_MB_NAMESPACE::btowc;
165#          if (!defined(__MSL__) || __MSL__ > 0x7001)
166using _STLP_VENDOR_MB_NAMESPACE::mbsinit;
167#          endif
168#        endif
169#        if defined (__MINGW32__) && ((__MINGW32_MAJOR_VERSION > 3) || ((__MINGW32_MAJOR_VERSION == 3) && (__MINGW32_MINOR_VERSION >= 8))) || \
170           !defined (__GNUC__) && !defined(_STLP_WCE_NET) && !(defined(__MWERKS__) && defined(N_PLAT_NLM))
171using _STLP_VENDOR_MB_NAMESPACE::mbrlen;
172using _STLP_VENDOR_MB_NAMESPACE::mbrtowc;
173using _STLP_VENDOR_MB_NAMESPACE::mbsrtowcs;
174using _STLP_VENDOR_MB_NAMESPACE::wcrtomb;
175using _STLP_VENDOR_MB_NAMESPACE::wcsrtombs;
176#        endif
177#      endif /* BORLAND && !__MSL__ || __MSL__ > 0x6001 */
178
179#    endif /* _STLP_NO_NATIVE_MBSTATE_T */
180
181#    if !defined (_STLP_NO_NATIVE_WIDE_FUNCTIONS) && ! defined (_STLP_NO_CSTD_FUNCTION_IMPORTS)
182
183#      if !defined (_STLP_WCHAR_BORLAND_EXCLUDE) && ! defined (_STLP_NO_CSTD_FUNCTION_IMPORTS) && !(defined(__MWERKS__) && defined(N_PLAT_NLM))
184using _STLP_VENDOR_CSTD::fgetwc;
185using _STLP_VENDOR_CSTD::fgetws;
186using _STLP_VENDOR_CSTD::fputwc;
187using _STLP_VENDOR_CSTD::fputws;
188#      endif
189
190#      if !(defined (_STLP_WCHAR_SUNPRO_EXCLUDE) || defined (_STLP_WCHAR_BORLAND_EXCLUDE) || \
191            defined(_STLP_WCHAR_HPACC_EXCLUDE) || (defined(__MWERKS__) && defined(N_PLAT_NLM)))
192#        if !defined (__DECCXX)
193using _STLP_VENDOR_CSTD::fwide;
194#        endif
195using _STLP_VENDOR_CSTD::fwprintf;
196using _STLP_VENDOR_CSTD::fwscanf;
197using _STLP_VENDOR_CSTD::getwchar;
198#      endif
199
200#      if !defined(_STLP_WCHAR_BORLAND_EXCLUDE) && !(defined(__MWERKS__) && defined(N_PLAT_NLM))
201#        ifndef _STLP_WCE_NET
202using _STLP_VENDOR_CSTD::getwc;
203#        endif
204using _STLP_VENDOR_CSTD::ungetwc;
205#        ifndef _STLP_WCE_NET
206using _STLP_VENDOR_CSTD::putwc;
207#        endif
208using _STLP_VENDOR_CSTD::putwchar;
209#      endif
210
211#      if !(defined (_STLP_WCHAR_SUNPRO_EXCLUDE) || defined (_STLP_WCHAR_BORLAND_EXCLUDE) || \
212            defined (_STLP_WCHAR_HPACC_EXCLUDE) || (defined (__MWERKS__) && defined (N_PLAT_NLM)))
213#        if defined (_STLP_MSVC_LIB) && (_STLP_MSVC_LIB <= 1300) || \
214            defined (__MINGW32__)
215#          undef swprintf
216#          define swprintf _snwprintf
217#          undef vswprintf
218#          define vswprintf _vsnwprintf
219using ::swprintf;
220using ::vswprintf;
221#        else
222using _STLP_VENDOR_CSTD::swprintf;
223using _STLP_VENDOR_CSTD::vswprintf;
224#        endif
225using _STLP_VENDOR_CSTD::swscanf;
226using _STLP_VENDOR_CSTD::vfwprintf;
227using _STLP_VENDOR_CSTD::vwprintf;
228
229#        if (!defined(__MSL__) || __MSL__ > 0x7001 ) && !defined(_STLP_WCE_NET) && \
230             !defined(_STLP_USE_UCLIBC) /* at least in uClibc 0.9.26 */
231
232using _STLP_VENDOR_CSTD::wcsftime;
233#        endif
234using _STLP_VENDOR_CSTD::wcstok;
235
236#      endif
237
238#      if !(defined(__MWERKS__) && defined(N_PLAT_NLM))
239#        if !defined (_STLP_WCE_NET)
240using _STLP_VENDOR_CSTD::wcscoll;
241using _STLP_VENDOR_CSTD::wcsxfrm;
242#        endif
243using _STLP_VENDOR_CSTD::wcscat;
244using _STLP_VENDOR_CSTD::wcsrchr;
245using _STLP_VENDOR_CSTD::wcscmp;
246
247using _STLP_VENDOR_CSTD::wcscpy;
248using _STLP_VENDOR_CSTD::wcscspn;
249
250using _STLP_VENDOR_CSTD::wcslen;
251using _STLP_VENDOR_CSTD::wcsncat;
252using _STLP_VENDOR_CSTD::wcsncmp;
253using _STLP_VENDOR_CSTD::wcsncpy;
254using _STLP_VENDOR_CSTD::wcspbrk;
255using _STLP_VENDOR_CSTD::wcschr;
256
257using _STLP_VENDOR_CSTD::wcsspn;
258#      endif
259
260#      if !defined (_STLP_WCHAR_BORLAND_EXCLUDE) && !(defined(__MWERKS__) && defined(N_PLAT_NLM))
261using _STLP_VENDOR_CSTD::wcstod;
262using _STLP_VENDOR_CSTD::wcstol;
263#      endif
264
265#      if !(defined (_STLP_WCHAR_SUNPRO_EXCLUDE) || defined (_STLP_WCHAR_HPACC_EXCLUDE) || \
266            (defined (__MWERKS__) && defined (N_PLAT_NLM)))
267using _STLP_VENDOR_CSTD::wcsstr;
268using _STLP_VENDOR_CSTD::wmemchr;
269
270#        if !defined (_STLP_WCHAR_BORLAND_EXCLUDE)
271#            if !defined (_STLP_WCE_NET)
272using _STLP_VENDOR_CSTD::wctob;
273#            endif
274#          if !defined (__DMC__)
275using _STLP_VENDOR_CSTD::wmemcmp;
276using _STLP_VENDOR_CSTD::wmemmove;
277#          endif
278using _STLP_VENDOR_CSTD::wprintf;
279using _STLP_VENDOR_CSTD::wscanf;
280#        endif
281
282#        if defined (__BORLANDC__)
283inline wchar_t* _STLP_wmemcpy(wchar_t* __wdst, const wchar_t* __wsrc, size_t __n)
284{ return __STATIC_CAST(wchar_t*, _STLP_VENDOR_CSTD::wmemcpy(__wdst, __wsrc, __n)); }
285inline wchar_t* _STLP_wmemset(wchar_t* __wdst, wchar_t __wc, size_t __n)
286{ return __STATIC_CAST(wchar_t*, _STLP_VENDOR_CSTD::memset(__wdst, __wc, __n)); }
287#          undef wmemcpy
288#          undef wmemset
289inline wchar_t* wmemcpy(wchar_t* __wdst, const wchar_t* __wsrc, size_t __n)
290{ return _STLP_wmemcpy(__wdst, __wsrc, __n); }
291inline wchar_t* wmemset(wchar_t* __wdst, wchar_t __wc, size_t __n)
292{ return _STLP_wmemset(__wdst, __wc, __n); }
293#        elif defined (__DMC__)
294inline wchar_t* wmemcpy(wchar_t* __RESTRICT __wdst, const wchar_t* __RESTRICT __wsrc, size_t __n)
295{ return __STATIC_CAST(wchar_t*, memcpy(__wdst, __wsrc, __n * sizeof(wchar_t))); }
296inline wchar_t* wmemmove(wchar_t* __RESTRICT __wdst, const wchar_t * __RESTRICT __wc, size_t __n)
297{ return __STATIC_CAST(wchar_t*, memmove(__wdst, __wc, __n * sizeof(wchar_t))); }
298inline wchar_t* wmemset(wchar_t* __wdst, wchar_t __wc, size_t __n)
299{ for (size_t i = 0; i < __n; i++) __wdst[i] = __wc; return __wdst; }
300#        else
301using _STLP_VENDOR_CSTD::wmemcpy;
302using _STLP_VENDOR_CSTD::wmemset;
303#        endif
304#      endif
305
306#    elif defined (__MWERKS__) && defined (N_PLAT_NLM) /* _STLP_NO_NATIVE_WIDE_FUNCTIONS */
307using _STLP_VENDOR_CSTD::wcslen;
308using _STLP_VENDOR_CSTD::wcscmp;
309using _STLP_VENDOR_CSTD::wcscpy;
310using _STLP_VENDOR_CSTD::wcsstr;
311using _STLP_VENDOR_CSTD::wcschr;
312using _STLP_VENDOR_CSTD::wcsrchr;
313using _STLP_VENDOR_CSTD::wcspbrk;
314#    endif /* _STLP_NO_NATIVE_WIDE_FUNCTIONS */
315_STLP_END_NAMESPACE
316
317#  endif /* _STLP_IMPORT_VENDOR_CSTD */
318
319#  undef _STLP_WCHAR_SUNPRO_EXCLUDE
320#  undef _STLP_WCHAR_MSL_EXCLUDE
321
322#  endif /* !defined(_STLP_WCE_EVC3) */
323
324#endif /* _STLP_INTERNAL_CWCHAR */
325