wchar.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. /* Copyright (C) 1995-2017 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. /*
  15. * ISO C99 Standard: 7.24
  16. * Extended multibyte and wide character utilities <wchar.h>
  17. */
  18. #ifndef _WCHAR_H
  19. #if !defined __need_mbstate_t && !defined __need_wint_t
  20. # define _WCHAR_H 1
  21. # define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
  22. # include <bits/libc-header-start.h>
  23. #endif
  24. #ifdef _WCHAR_H
  25. /* Get FILE definition. */
  26. # define __need___FILE
  27. # if defined __USE_UNIX98 || defined __USE_XOPEN2K
  28. # define __need_FILE
  29. # endif
  30. # include <stdio.h>
  31. /* Get va_list definition. */
  32. # define __need___va_list
  33. # include <stdarg.h>
  34. # include <bits/wchar.h>
  35. /* Get size_t, wchar_t, wint_t and NULL from <stddef.h>. */
  36. # define __need_size_t
  37. # define __need_wchar_t
  38. # define __need_NULL
  39. #endif
  40. #if defined _WCHAR_H || defined __need_wint_t || !defined __WINT_TYPE__
  41. # undef __need_wint_t
  42. # define __need_wint_t
  43. # include <stddef.h>
  44. /* We try to get wint_t from <stddef.h>, but not all GCC versions define it
  45. there. So define it ourselves if it remains undefined. */
  46. # ifndef _WINT_T
  47. /* Integral type unchanged by default argument promotions that can
  48. hold any value corresponding to members of the extended character
  49. set, as well as at least one value that does not correspond to any
  50. member of the extended character set. */
  51. # define _WINT_T
  52. typedef unsigned int wint_t;
  53. # else
  54. /* Work around problems with the <stddef.h> file which doesn't put
  55. wint_t in the std namespace. */
  56. # if defined __cplusplus && defined _GLIBCPP_USE_NAMESPACES \
  57. && defined __WINT_TYPE__
  58. __BEGIN_NAMESPACE_STD
  59. typedef __WINT_TYPE__ wint_t;
  60. __END_NAMESPACE_STD
  61. # endif
  62. # endif
  63. /* Tell the caller that we provide correct C++ prototypes. */
  64. # if defined __cplusplus && __GNUC_PREREQ (4, 4)
  65. # define __CORRECT_ISO_CPP_WCHAR_H_PROTO
  66. # endif
  67. #endif
  68. #if (defined _WCHAR_H || defined __need_mbstate_t) && !defined ____mbstate_t_defined
  69. # define ____mbstate_t_defined 1
  70. /* Conversion state information. */
  71. typedef struct
  72. {
  73. int __count;
  74. union
  75. {
  76. # ifdef __WINT_TYPE__
  77. __WINT_TYPE__ __wch;
  78. # else
  79. wint_t __wch;
  80. # endif
  81. char __wchb[4];
  82. } __value; /* Value so far. */
  83. } __mbstate_t;
  84. #endif
  85. #undef __need_mbstate_t
  86. /* The rest of the file is only used if used if __need_mbstate_t is not
  87. defined. */
  88. #ifdef _WCHAR_H
  89. # ifndef __mbstate_t_defined
  90. __BEGIN_NAMESPACE_C99
  91. /* Public type. */
  92. typedef __mbstate_t mbstate_t;
  93. __END_NAMESPACE_C99
  94. # define __mbstate_t_defined 1
  95. # endif
  96. #ifdef __USE_GNU
  97. __USING_NAMESPACE_C99(mbstate_t)
  98. #endif
  99. #ifndef WCHAR_MIN
  100. /* These constants might also be defined in <inttypes.h>. */
  101. # define WCHAR_MIN __WCHAR_MIN
  102. # define WCHAR_MAX __WCHAR_MAX
  103. #endif
  104. #ifndef WEOF
  105. # define WEOF (0xffffffffu)
  106. #endif
  107. /* For XPG4 compliance we have to define the stuff from <wctype.h> here
  108. as well. */
  109. #if defined __USE_XOPEN && !defined __USE_UNIX98
  110. # include <wctype.h>
  111. #endif
  112. __BEGIN_DECLS
  113. __BEGIN_NAMESPACE_STD
  114. /* This incomplete type is defined in <time.h> but needed here because
  115. of `wcsftime'. */
  116. struct tm;
  117. __END_NAMESPACE_STD
  118. /* XXX We have to clean this up at some point. Since tm is in the std
  119. namespace but wcsftime is in __c99 the type wouldn't be found
  120. without inserting it in the global namespace. */
  121. __USING_NAMESPACE_STD(tm)
  122. __BEGIN_NAMESPACE_STD
  123. /* Copy SRC to DEST. */
  124. extern wchar_t *wcscpy (wchar_t *__restrict __dest,
  125. const wchar_t *__restrict __src)
  126. __THROW __nonnull ((1, 2));
  127. /* Copy no more than N wide-characters of SRC to DEST. */
  128. extern wchar_t *wcsncpy (wchar_t *__restrict __dest,
  129. const wchar_t *__restrict __src, size_t __n)
  130. __THROW __nonnull ((1, 2));
  131. /* Append SRC onto DEST. */
  132. extern wchar_t *wcscat (wchar_t *__restrict __dest,
  133. const wchar_t *__restrict __src)
  134. __THROW __nonnull ((1, 2));
  135. /* Append no more than N wide-characters of SRC onto DEST. */
  136. extern wchar_t *wcsncat (wchar_t *__restrict __dest,
  137. const wchar_t *__restrict __src, size_t __n)
  138. __THROW __nonnull ((1, 2));
  139. /* Compare S1 and S2. */
  140. extern int wcscmp (const wchar_t *__s1, const wchar_t *__s2)
  141. __THROW __attribute_pure__ __nonnull ((1, 2));
  142. /* Compare N wide-characters of S1 and S2. */
  143. extern int wcsncmp (const wchar_t *__s1, const wchar_t *__s2, size_t __n)
  144. __THROW __attribute_pure__ __nonnull ((1, 2));
  145. __END_NAMESPACE_STD
  146. #ifdef __USE_XOPEN2K8
  147. /* Compare S1 and S2, ignoring case. */
  148. extern int wcscasecmp (const wchar_t *__s1, const wchar_t *__s2) __THROW;
  149. /* Compare no more than N chars of S1 and S2, ignoring case. */
  150. extern int wcsncasecmp (const wchar_t *__s1, const wchar_t *__s2,
  151. size_t __n) __THROW;
  152. /* Similar to the two functions above but take the information from
  153. the provided locale and not the global locale. */
  154. # include <xlocale.h>
  155. extern int wcscasecmp_l (const wchar_t *__s1, const wchar_t *__s2,
  156. __locale_t __loc) __THROW;
  157. extern int wcsncasecmp_l (const wchar_t *__s1, const wchar_t *__s2,
  158. size_t __n, __locale_t __loc) __THROW;
  159. #endif
  160. __BEGIN_NAMESPACE_STD
  161. /* Compare S1 and S2, both interpreted as appropriate to the
  162. LC_COLLATE category of the current locale. */
  163. extern int wcscoll (const wchar_t *__s1, const wchar_t *__s2) __THROW;
  164. /* Transform S2 into array pointed to by S1 such that if wcscmp is
  165. applied to two transformed strings the result is the as applying
  166. `wcscoll' to the original strings. */
  167. extern size_t wcsxfrm (wchar_t *__restrict __s1,
  168. const wchar_t *__restrict __s2, size_t __n) __THROW;
  169. __END_NAMESPACE_STD
  170. #ifdef __USE_XOPEN2K8
  171. /* Similar to the two functions above but take the information from
  172. the provided locale and not the global locale. */
  173. /* Compare S1 and S2, both interpreted as appropriate to the
  174. LC_COLLATE category of the given locale. */
  175. extern int wcscoll_l (const wchar_t *__s1, const wchar_t *__s2,
  176. __locale_t __loc) __THROW;
  177. /* Transform S2 into array pointed to by S1 such that if wcscmp is
  178. applied to two transformed strings the result is the as applying
  179. `wcscoll' to the original strings. */
  180. extern size_t wcsxfrm_l (wchar_t *__s1, const wchar_t *__s2,
  181. size_t __n, __locale_t __loc) __THROW;
  182. /* Duplicate S, returning an identical malloc'd string. */
  183. extern wchar_t *wcsdup (const wchar_t *__s) __THROW __attribute_malloc__;
  184. #endif
  185. __BEGIN_NAMESPACE_STD
  186. /* Find the first occurrence of WC in WCS. */
  187. #ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO
  188. extern "C++" wchar_t *wcschr (wchar_t *__wcs, wchar_t __wc)
  189. __THROW __asm ("wcschr") __attribute_pure__;
  190. extern "C++" const wchar_t *wcschr (const wchar_t *__wcs, wchar_t __wc)
  191. __THROW __asm ("wcschr") __attribute_pure__;
  192. #else
  193. extern wchar_t *wcschr (const wchar_t *__wcs, wchar_t __wc)
  194. __THROW __attribute_pure__;
  195. #endif
  196. /* Find the last occurrence of WC in WCS. */
  197. #ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO
  198. extern "C++" wchar_t *wcsrchr (wchar_t *__wcs, wchar_t __wc)
  199. __THROW __asm ("wcsrchr") __attribute_pure__;
  200. extern "C++" const wchar_t *wcsrchr (const wchar_t *__wcs, wchar_t __wc)
  201. __THROW __asm ("wcsrchr") __attribute_pure__;
  202. #else
  203. extern wchar_t *wcsrchr (const wchar_t *__wcs, wchar_t __wc)
  204. __THROW __attribute_pure__;
  205. #endif
  206. __END_NAMESPACE_STD
  207. #ifdef __USE_GNU
  208. /* This function is similar to `wcschr'. But it returns a pointer to
  209. the closing NUL wide character in case C is not found in S. */
  210. extern wchar_t *wcschrnul (const wchar_t *__s, wchar_t __wc)
  211. __THROW __attribute_pure__;
  212. #endif
  213. __BEGIN_NAMESPACE_STD
  214. /* Return the length of the initial segmet of WCS which
  215. consists entirely of wide characters not in REJECT. */
  216. extern size_t wcscspn (const wchar_t *__wcs, const wchar_t *__reject)
  217. __THROW __attribute_pure__;
  218. /* Return the length of the initial segmet of WCS which
  219. consists entirely of wide characters in ACCEPT. */
  220. extern size_t wcsspn (const wchar_t *__wcs, const wchar_t *__accept)
  221. __THROW __attribute_pure__;
  222. /* Find the first occurrence in WCS of any character in ACCEPT. */
  223. #ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO
  224. extern "C++" wchar_t *wcspbrk (wchar_t *__wcs, const wchar_t *__accept)
  225. __THROW __asm ("wcspbrk") __attribute_pure__;
  226. extern "C++" const wchar_t *wcspbrk (const wchar_t *__wcs,
  227. const wchar_t *__accept)
  228. __THROW __asm ("wcspbrk") __attribute_pure__;
  229. #else
  230. extern wchar_t *wcspbrk (const wchar_t *__wcs, const wchar_t *__accept)
  231. __THROW __attribute_pure__;
  232. #endif
  233. /* Find the first occurrence of NEEDLE in HAYSTACK. */
  234. #ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO
  235. extern "C++" wchar_t *wcsstr (wchar_t *__haystack, const wchar_t *__needle)
  236. __THROW __asm ("wcsstr") __attribute_pure__;
  237. extern "C++" const wchar_t *wcsstr (const wchar_t *__haystack,
  238. const wchar_t *__needle)
  239. __THROW __asm ("wcsstr") __attribute_pure__;
  240. #else
  241. extern wchar_t *wcsstr (const wchar_t *__haystack, const wchar_t *__needle)
  242. __THROW __attribute_pure__;
  243. #endif
  244. /* Divide WCS into tokens separated by characters in DELIM. */
  245. extern wchar_t *wcstok (wchar_t *__restrict __s,
  246. const wchar_t *__restrict __delim,
  247. wchar_t **__restrict __ptr) __THROW;
  248. /* Return the number of wide characters in S. */
  249. extern size_t wcslen (const wchar_t *__s) __THROW __attribute_pure__;
  250. __END_NAMESPACE_STD
  251. #ifdef __USE_XOPEN
  252. /* Another name for `wcsstr' from XPG4. */
  253. # ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO
  254. extern "C++" wchar_t *wcswcs (wchar_t *__haystack, const wchar_t *__needle)
  255. __THROW __asm ("wcswcs") __attribute_pure__;
  256. extern "C++" const wchar_t *wcswcs (const wchar_t *__haystack,
  257. const wchar_t *__needle)
  258. __THROW __asm ("wcswcs") __attribute_pure__;
  259. # else
  260. extern wchar_t *wcswcs (const wchar_t *__haystack, const wchar_t *__needle)
  261. __THROW __attribute_pure__;
  262. # endif
  263. #endif
  264. #ifdef __USE_XOPEN2K8
  265. /* Return the number of wide characters in S, but at most MAXLEN. */
  266. extern size_t wcsnlen (const wchar_t *__s, size_t __maxlen)
  267. __THROW __attribute_pure__;
  268. #endif
  269. __BEGIN_NAMESPACE_STD
  270. /* Search N wide characters of S for C. */
  271. #ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO
  272. extern "C++" wchar_t *wmemchr (wchar_t *__s, wchar_t __c, size_t __n)
  273. __THROW __asm ("wmemchr") __attribute_pure__;
  274. extern "C++" const wchar_t *wmemchr (const wchar_t *__s, wchar_t __c,
  275. size_t __n)
  276. __THROW __asm ("wmemchr") __attribute_pure__;
  277. #else
  278. extern wchar_t *wmemchr (const wchar_t *__s, wchar_t __c, size_t __n)
  279. __THROW __attribute_pure__;
  280. #endif
  281. /* Compare N wide characters of S1 and S2. */
  282. extern int wmemcmp (const wchar_t *__s1, const wchar_t *__s2, size_t __n)
  283. __THROW __attribute_pure__;
  284. /* Copy N wide characters of SRC to DEST. */
  285. extern wchar_t *wmemcpy (wchar_t *__restrict __s1,
  286. const wchar_t *__restrict __s2, size_t __n) __THROW;
  287. /* Copy N wide characters of SRC to DEST, guaranteeing
  288. correct behavior for overlapping strings. */
  289. extern wchar_t *wmemmove (wchar_t *__s1, const wchar_t *__s2, size_t __n)
  290. __THROW;
  291. /* Set N wide characters of S to C. */
  292. extern wchar_t *wmemset (wchar_t *__s, wchar_t __c, size_t __n) __THROW;
  293. __END_NAMESPACE_STD
  294. #ifdef __USE_GNU
  295. /* Copy N wide characters of SRC to DEST and return pointer to following
  296. wide character. */
  297. extern wchar_t *wmempcpy (wchar_t *__restrict __s1,
  298. const wchar_t *__restrict __s2, size_t __n)
  299. __THROW;
  300. #endif
  301. __BEGIN_NAMESPACE_STD
  302. /* Determine whether C constitutes a valid (one-byte) multibyte
  303. character. */
  304. extern wint_t btowc (int __c) __THROW;
  305. /* Determine whether C corresponds to a member of the extended
  306. character set whose multibyte representation is a single byte. */
  307. extern int wctob (wint_t __c) __THROW;
  308. /* Determine whether PS points to an object representing the initial
  309. state. */
  310. extern int mbsinit (const mbstate_t *__ps) __THROW __attribute_pure__;
  311. /* Write wide character representation of multibyte character pointed
  312. to by S to PWC. */
  313. extern size_t mbrtowc (wchar_t *__restrict __pwc,
  314. const char *__restrict __s, size_t __n,
  315. mbstate_t *__restrict __p) __THROW;
  316. /* Write multibyte representation of wide character WC to S. */
  317. extern size_t wcrtomb (char *__restrict __s, wchar_t __wc,
  318. mbstate_t *__restrict __ps) __THROW;
  319. /* Return number of bytes in multibyte character pointed to by S. */
  320. extern size_t __mbrlen (const char *__restrict __s, size_t __n,
  321. mbstate_t *__restrict __ps) __THROW;
  322. extern size_t mbrlen (const char *__restrict __s, size_t __n,
  323. mbstate_t *__restrict __ps) __THROW;
  324. __END_NAMESPACE_STD
  325. #ifdef __USE_EXTERN_INLINES
  326. /* Define inline function as optimization. */
  327. /* We can use the BTOWC and WCTOB optimizations since we know that all
  328. locales must use ASCII encoding for the values in the ASCII range
  329. and because the wchar_t encoding is always ISO 10646. */
  330. extern wint_t __btowc_alias (int __c) __asm ("btowc");
  331. __extern_inline wint_t
  332. __NTH (btowc (int __c))
  333. { return (__builtin_constant_p (__c) && __c >= '\0' && __c <= '\x7f'
  334. ? (wint_t) __c : __btowc_alias (__c)); }
  335. extern int __wctob_alias (wint_t __c) __asm ("wctob");
  336. __extern_inline int
  337. __NTH (wctob (wint_t __wc))
  338. { return (__builtin_constant_p (__wc) && __wc >= L'\0' && __wc <= L'\x7f'
  339. ? (int) __wc : __wctob_alias (__wc)); }
  340. __extern_inline size_t
  341. __NTH (mbrlen (const char *__restrict __s, size_t __n,
  342. mbstate_t *__restrict __ps))
  343. { return (__ps != NULL
  344. ? mbrtowc (NULL, __s, __n, __ps) : __mbrlen (__s, __n, NULL)); }
  345. #endif
  346. __BEGIN_NAMESPACE_STD
  347. /* Write wide character representation of multibyte character string
  348. SRC to DST. */
  349. extern size_t mbsrtowcs (wchar_t *__restrict __dst,
  350. const char **__restrict __src, size_t __len,
  351. mbstate_t *__restrict __ps) __THROW;
  352. /* Write multibyte character representation of wide character string
  353. SRC to DST. */
  354. extern size_t wcsrtombs (char *__restrict __dst,
  355. const wchar_t **__restrict __src, size_t __len,
  356. mbstate_t *__restrict __ps) __THROW;
  357. __END_NAMESPACE_STD
  358. #ifdef __USE_XOPEN2K8
  359. /* Write wide character representation of at most NMC bytes of the
  360. multibyte character string SRC to DST. */
  361. extern size_t mbsnrtowcs (wchar_t *__restrict __dst,
  362. const char **__restrict __src, size_t __nmc,
  363. size_t __len, mbstate_t *__restrict __ps) __THROW;
  364. /* Write multibyte character representation of at most NWC characters
  365. from the wide character string SRC to DST. */
  366. extern size_t wcsnrtombs (char *__restrict __dst,
  367. const wchar_t **__restrict __src,
  368. size_t __nwc, size_t __len,
  369. mbstate_t *__restrict __ps) __THROW;
  370. #endif /* use POSIX 2008 */
  371. /* The following functions are extensions found in X/Open CAE. */
  372. #ifdef __USE_XOPEN
  373. /* Determine number of column positions required for C. */
  374. extern int wcwidth (wchar_t __c) __THROW;
  375. /* Determine number of column positions required for first N wide
  376. characters (or fewer if S ends before this) in S. */
  377. extern int wcswidth (const wchar_t *__s, size_t __n) __THROW;
  378. #endif /* Use X/Open. */
  379. __BEGIN_NAMESPACE_STD
  380. /* Convert initial portion of the wide string NPTR to `double'
  381. representation. */
  382. extern double wcstod (const wchar_t *__restrict __nptr,
  383. wchar_t **__restrict __endptr) __THROW;
  384. __END_NAMESPACE_STD
  385. #ifdef __USE_ISOC99
  386. __BEGIN_NAMESPACE_C99
  387. /* Likewise for `float' and `long double' sizes of floating-point numbers. */
  388. extern float wcstof (const wchar_t *__restrict __nptr,
  389. wchar_t **__restrict __endptr) __THROW;
  390. extern long double wcstold (const wchar_t *__restrict __nptr,
  391. wchar_t **__restrict __endptr) __THROW;
  392. __END_NAMESPACE_C99
  393. #endif /* C99 */
  394. __BEGIN_NAMESPACE_STD
  395. /* Convert initial portion of wide string NPTR to `long int'
  396. representation. */
  397. extern long int wcstol (const wchar_t *__restrict __nptr,
  398. wchar_t **__restrict __endptr, int __base) __THROW;
  399. /* Convert initial portion of wide string NPTR to `unsigned long int'
  400. representation. */
  401. extern unsigned long int wcstoul (const wchar_t *__restrict __nptr,
  402. wchar_t **__restrict __endptr, int __base)
  403. __THROW;
  404. __END_NAMESPACE_STD
  405. #ifdef __USE_ISOC99
  406. __BEGIN_NAMESPACE_C99
  407. /* Convert initial portion of wide string NPTR to `long long int'
  408. representation. */
  409. __extension__
  410. extern long long int wcstoll (const wchar_t *__restrict __nptr,
  411. wchar_t **__restrict __endptr, int __base)
  412. __THROW;
  413. /* Convert initial portion of wide string NPTR to `unsigned long long int'
  414. representation. */
  415. __extension__
  416. extern unsigned long long int wcstoull (const wchar_t *__restrict __nptr,
  417. wchar_t **__restrict __endptr,
  418. int __base) __THROW;
  419. __END_NAMESPACE_C99
  420. #endif /* ISO C99. */
  421. #ifdef __USE_GNU
  422. /* Convert initial portion of wide string NPTR to `long long int'
  423. representation. */
  424. __extension__
  425. extern long long int wcstoq (const wchar_t *__restrict __nptr,
  426. wchar_t **__restrict __endptr, int __base)
  427. __THROW;
  428. /* Convert initial portion of wide string NPTR to `unsigned long long int'
  429. representation. */
  430. __extension__
  431. extern unsigned long long int wcstouq (const wchar_t *__restrict __nptr,
  432. wchar_t **__restrict __endptr,
  433. int __base) __THROW;
  434. #endif /* Use GNU. */
  435. #ifdef __USE_GNU
  436. /* The concept of one static locale per category is not very well
  437. thought out. Many applications will need to process its data using
  438. information from several different locales. Another application is
  439. the implementation of the internationalization handling in the
  440. upcoming ISO C++ standard library. To support this another set of
  441. the functions using locale data exist which have an additional
  442. argument.
  443. Attention: all these functions are *not* standardized in any form.
  444. This is a proof-of-concept implementation. */
  445. /* Structure for reentrant locale using functions. This is an
  446. (almost) opaque type for the user level programs. */
  447. # include <xlocale.h>
  448. /* Special versions of the functions above which take the locale to
  449. use as an additional parameter. */
  450. extern long int wcstol_l (const wchar_t *__restrict __nptr,
  451. wchar_t **__restrict __endptr, int __base,
  452. __locale_t __loc) __THROW;
  453. extern unsigned long int wcstoul_l (const wchar_t *__restrict __nptr,
  454. wchar_t **__restrict __endptr,
  455. int __base, __locale_t __loc) __THROW;
  456. __extension__
  457. extern long long int wcstoll_l (const wchar_t *__restrict __nptr,
  458. wchar_t **__restrict __endptr,
  459. int __base, __locale_t __loc) __THROW;
  460. __extension__
  461. extern unsigned long long int wcstoull_l (const wchar_t *__restrict __nptr,
  462. wchar_t **__restrict __endptr,
  463. int __base, __locale_t __loc)
  464. __THROW;
  465. extern double wcstod_l (const wchar_t *__restrict __nptr,
  466. wchar_t **__restrict __endptr, __locale_t __loc)
  467. __THROW;
  468. extern float wcstof_l (const wchar_t *__restrict __nptr,
  469. wchar_t **__restrict __endptr, __locale_t __loc)
  470. __THROW;
  471. extern long double wcstold_l (const wchar_t *__restrict __nptr,
  472. wchar_t **__restrict __endptr,
  473. __locale_t __loc) __THROW;
  474. #endif /* use GNU */
  475. #ifdef __USE_XOPEN2K8
  476. /* Copy SRC to DEST, returning the address of the terminating L'\0' in
  477. DEST. */
  478. extern wchar_t *wcpcpy (wchar_t *__restrict __dest,
  479. const wchar_t *__restrict __src) __THROW;
  480. /* Copy no more than N characters of SRC to DEST, returning the address of
  481. the last character written into DEST. */
  482. extern wchar_t *wcpncpy (wchar_t *__restrict __dest,
  483. const wchar_t *__restrict __src, size_t __n)
  484. __THROW;
  485. #endif
  486. /* Wide character I/O functions. */
  487. #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
  488. /* Like OPEN_MEMSTREAM, but the stream is wide oriented and produces
  489. a wide character string. */
  490. extern __FILE *open_wmemstream (wchar_t **__bufloc, size_t *__sizeloc) __THROW;
  491. #endif
  492. #if defined __USE_ISOC95 || defined __USE_UNIX98
  493. __BEGIN_NAMESPACE_STD
  494. /* Select orientation for stream. */
  495. extern int fwide (__FILE *__fp, int __mode) __THROW;
  496. /* Write formatted output to STREAM.
  497. This function is a possible cancellation point and therefore not
  498. marked with __THROW. */
  499. extern int fwprintf (__FILE *__restrict __stream,
  500. const wchar_t *__restrict __format, ...)
  501. /* __attribute__ ((__format__ (__wprintf__, 2, 3))) */;
  502. /* Write formatted output to stdout.
  503. This function is a possible cancellation point and therefore not
  504. marked with __THROW. */
  505. extern int wprintf (const wchar_t *__restrict __format, ...)
  506. /* __attribute__ ((__format__ (__wprintf__, 1, 2))) */;
  507. /* Write formatted output of at most N characters to S. */
  508. extern int swprintf (wchar_t *__restrict __s, size_t __n,
  509. const wchar_t *__restrict __format, ...)
  510. __THROW /* __attribute__ ((__format__ (__wprintf__, 3, 4))) */;
  511. /* Write formatted output to S from argument list ARG.
  512. This function is a possible cancellation point and therefore not
  513. marked with __THROW. */
  514. extern int vfwprintf (__FILE *__restrict __s,
  515. const wchar_t *__restrict __format,
  516. __gnuc_va_list __arg)
  517. /* __attribute__ ((__format__ (__wprintf__, 2, 0))) */;
  518. /* Write formatted output to stdout from argument list ARG.
  519. This function is a possible cancellation point and therefore not
  520. marked with __THROW. */
  521. extern int vwprintf (const wchar_t *__restrict __format,
  522. __gnuc_va_list __arg)
  523. /* __attribute__ ((__format__ (__wprintf__, 1, 0))) */;
  524. /* Write formatted output of at most N character to S from argument
  525. list ARG. */
  526. extern int vswprintf (wchar_t *__restrict __s, size_t __n,
  527. const wchar_t *__restrict __format,
  528. __gnuc_va_list __arg)
  529. __THROW /* __attribute__ ((__format__ (__wprintf__, 3, 0))) */;
  530. /* Read formatted input from STREAM.
  531. This function is a possible cancellation point and therefore not
  532. marked with __THROW. */
  533. extern int fwscanf (__FILE *__restrict __stream,
  534. const wchar_t *__restrict __format, ...)
  535. /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
  536. /* Read formatted input from stdin.
  537. This function is a possible cancellation point and therefore not
  538. marked with __THROW. */
  539. extern int wscanf (const wchar_t *__restrict __format, ...)
  540. /* __attribute__ ((__format__ (__wscanf__, 1, 2))) */;
  541. /* Read formatted input from S. */
  542. extern int swscanf (const wchar_t *__restrict __s,
  543. const wchar_t *__restrict __format, ...)
  544. __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
  545. # if defined __USE_ISOC99 && !defined __USE_GNU \
  546. && (!defined __LDBL_COMPAT || !defined __REDIRECT) \
  547. && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K)
  548. # ifdef __REDIRECT
  549. /* For strict ISO C99 or POSIX compliance disallow %as, %aS and %a[
  550. GNU extension which conflicts with valid %a followed by letter
  551. s, S or [. */
  552. extern int __REDIRECT (fwscanf, (__FILE *__restrict __stream,
  553. const wchar_t *__restrict __format, ...),
  554. __isoc99_fwscanf)
  555. /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
  556. extern int __REDIRECT (wscanf, (const wchar_t *__restrict __format, ...),
  557. __isoc99_wscanf)
  558. /* __attribute__ ((__format__ (__wscanf__, 1, 2))) */;
  559. extern int __REDIRECT_NTH (swscanf, (const wchar_t *__restrict __s,
  560. const wchar_t *__restrict __format,
  561. ...), __isoc99_swscanf)
  562. /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
  563. # else
  564. extern int __isoc99_fwscanf (__FILE *__restrict __stream,
  565. const wchar_t *__restrict __format, ...);
  566. extern int __isoc99_wscanf (const wchar_t *__restrict __format, ...);
  567. extern int __isoc99_swscanf (const wchar_t *__restrict __s,
  568. const wchar_t *__restrict __format, ...)
  569. __THROW;
  570. # define fwscanf __isoc99_fwscanf
  571. # define wscanf __isoc99_wscanf
  572. # define swscanf __isoc99_swscanf
  573. # endif
  574. # endif
  575. __END_NAMESPACE_STD
  576. #endif /* Use ISO C95, C99 and Unix98. */
  577. #ifdef __USE_ISOC99
  578. __BEGIN_NAMESPACE_C99
  579. /* Read formatted input from S into argument list ARG.
  580. This function is a possible cancellation point and therefore not
  581. marked with __THROW. */
  582. extern int vfwscanf (__FILE *__restrict __s,
  583. const wchar_t *__restrict __format,
  584. __gnuc_va_list __arg)
  585. /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
  586. /* Read formatted input from stdin into argument list ARG.
  587. This function is a possible cancellation point and therefore not
  588. marked with __THROW. */
  589. extern int vwscanf (const wchar_t *__restrict __format,
  590. __gnuc_va_list __arg)
  591. /* __attribute__ ((__format__ (__wscanf__, 1, 0))) */;
  592. /* Read formatted input from S into argument list ARG. */
  593. extern int vswscanf (const wchar_t *__restrict __s,
  594. const wchar_t *__restrict __format,
  595. __gnuc_va_list __arg)
  596. __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
  597. # if !defined __USE_GNU \
  598. && (!defined __LDBL_COMPAT || !defined __REDIRECT) \
  599. && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K)
  600. # ifdef __REDIRECT
  601. extern int __REDIRECT (vfwscanf, (__FILE *__restrict __s,
  602. const wchar_t *__restrict __format,
  603. __gnuc_va_list __arg), __isoc99_vfwscanf)
  604. /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
  605. extern int __REDIRECT (vwscanf, (const wchar_t *__restrict __format,
  606. __gnuc_va_list __arg), __isoc99_vwscanf)
  607. /* __attribute__ ((__format__ (__wscanf__, 1, 0))) */;
  608. extern int __REDIRECT_NTH (vswscanf, (const wchar_t *__restrict __s,
  609. const wchar_t *__restrict __format,
  610. __gnuc_va_list __arg), __isoc99_vswscanf)
  611. /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
  612. # else
  613. extern int __isoc99_vfwscanf (__FILE *__restrict __s,
  614. const wchar_t *__restrict __format,
  615. __gnuc_va_list __arg);
  616. extern int __isoc99_vwscanf (const wchar_t *__restrict __format,
  617. __gnuc_va_list __arg);
  618. extern int __isoc99_vswscanf (const wchar_t *__restrict __s,
  619. const wchar_t *__restrict __format,
  620. __gnuc_va_list __arg) __THROW;
  621. # define vfwscanf __isoc99_vfwscanf
  622. # define vwscanf __isoc99_vwscanf
  623. # define vswscanf __isoc99_vswscanf
  624. # endif
  625. # endif
  626. __END_NAMESPACE_C99
  627. #endif /* Use ISO C99. */
  628. __BEGIN_NAMESPACE_STD
  629. /* Read a character from STREAM.
  630. These functions are possible cancellation points and therefore not
  631. marked with __THROW. */
  632. extern wint_t fgetwc (__FILE *__stream);
  633. extern wint_t getwc (__FILE *__stream);
  634. /* Read a character from stdin.
  635. This function is a possible cancellation point and therefore not
  636. marked with __THROW. */
  637. extern wint_t getwchar (void);
  638. /* Write a character to STREAM.
  639. These functions are possible cancellation points and therefore not
  640. marked with __THROW. */
  641. extern wint_t fputwc (wchar_t __wc, __FILE *__stream);
  642. extern wint_t putwc (wchar_t __wc, __FILE *__stream);
  643. /* Write a character to stdout.
  644. This function is a possible cancellation point and therefore not
  645. marked with __THROW. */
  646. extern wint_t putwchar (wchar_t __wc);
  647. /* Get a newline-terminated wide character string of finite length
  648. from STREAM.
  649. This function is a possible cancellation point and therefore not
  650. marked with __THROW. */
  651. extern wchar_t *fgetws (wchar_t *__restrict __ws, int __n,
  652. __FILE *__restrict __stream);
  653. /* Write a string to STREAM.
  654. This function is a possible cancellation point and therefore not
  655. marked with __THROW. */
  656. extern int fputws (const wchar_t *__restrict __ws,
  657. __FILE *__restrict __stream);
  658. /* Push a character back onto the input buffer of STREAM.
  659. This function is a possible cancellation point and therefore not
  660. marked with __THROW. */
  661. extern wint_t ungetwc (wint_t __wc, __FILE *__stream);
  662. __END_NAMESPACE_STD
  663. #ifdef __USE_GNU
  664. /* These are defined to be equivalent to the `char' functions defined
  665. in POSIX.1:1996.
  666. These functions are not part of POSIX and therefore no official
  667. cancellation point. But due to similarity with an POSIX interface
  668. or due to the implementation they are cancellation points and
  669. therefore not marked with __THROW. */
  670. extern wint_t getwc_unlocked (__FILE *__stream);
  671. extern wint_t getwchar_unlocked (void);
  672. /* This is the wide character version of a GNU extension.
  673. This function is not part of POSIX and therefore no official
  674. cancellation point. But due to similarity with an POSIX interface
  675. or due to the implementation it is a cancellation point and
  676. therefore not marked with __THROW. */
  677. extern wint_t fgetwc_unlocked (__FILE *__stream);
  678. /* Faster version when locking is not necessary.
  679. This function is not part of POSIX and therefore no official
  680. cancellation point. But due to similarity with an POSIX interface
  681. or due to the implementation it is a cancellation point and
  682. therefore not marked with __THROW. */
  683. extern wint_t fputwc_unlocked (wchar_t __wc, __FILE *__stream);
  684. /* These are defined to be equivalent to the `char' functions defined
  685. in POSIX.1:1996.
  686. These functions are not part of POSIX and therefore no official
  687. cancellation point. But due to similarity with an POSIX interface
  688. or due to the implementation they are cancellation points and
  689. therefore not marked with __THROW. */
  690. extern wint_t putwc_unlocked (wchar_t __wc, __FILE *__stream);
  691. extern wint_t putwchar_unlocked (wchar_t __wc);
  692. /* This function does the same as `fgetws' but does not lock the stream.
  693. This function is not part of POSIX and therefore no official
  694. cancellation point. But due to similarity with an POSIX interface
  695. or due to the implementation it is a cancellation point and
  696. therefore not marked with __THROW. */
  697. extern wchar_t *fgetws_unlocked (wchar_t *__restrict __ws, int __n,
  698. __FILE *__restrict __stream);
  699. /* This function does the same as `fputws' but does not lock the stream.
  700. This function is not part of POSIX and therefore no official
  701. cancellation point. But due to similarity with an POSIX interface
  702. or due to the implementation it is a cancellation point and
  703. therefore not marked with __THROW. */
  704. extern int fputws_unlocked (const wchar_t *__restrict __ws,
  705. __FILE *__restrict __stream);
  706. #endif
  707. __BEGIN_NAMESPACE_C99
  708. /* Format TP into S according to FORMAT.
  709. Write no more than MAXSIZE wide characters and return the number
  710. of wide characters written, or 0 if it would exceed MAXSIZE. */
  711. extern size_t wcsftime (wchar_t *__restrict __s, size_t __maxsize,
  712. const wchar_t *__restrict __format,
  713. const struct tm *__restrict __tp) __THROW;
  714. __END_NAMESPACE_C99
  715. # ifdef __USE_GNU
  716. # include <xlocale.h>
  717. /* Similar to `wcsftime' but takes the information from
  718. the provided locale and not the global locale. */
  719. extern size_t wcsftime_l (wchar_t *__restrict __s, size_t __maxsize,
  720. const wchar_t *__restrict __format,
  721. const struct tm *__restrict __tp,
  722. __locale_t __loc) __THROW;
  723. # endif
  724. /* The X/Open standard demands that most of the functions defined in
  725. the <wctype.h> header must also appear here. This is probably
  726. because some X/Open members wrote their implementation before the
  727. ISO C standard was published and introduced the better solution.
  728. We have to provide these definitions for compliance reasons but we
  729. do this nonsense only if really necessary. */
  730. #if defined __USE_UNIX98 && !defined __USE_GNU
  731. # define __need_iswxxx
  732. # include <wctype.h>
  733. #endif
  734. /* Define some macros helping to catch buffer overflows. */
  735. #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
  736. # include <bits/wchar2.h>
  737. #endif
  738. #ifdef __LDBL_COMPAT
  739. # include <bits/wchar-ldbl.h>
  740. #endif
  741. __END_DECLS
  742. #endif /* _WCHAR_H defined */
  743. #endif /* wchar.h */
  744. /* Undefine all __need_* constants in case we are included to get those
  745. constants but the whole file was already read. */
  746. #undef __need_mbstate_t
  747. #undef __need_wint_t