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