_cwchar.h 12 KB

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