1/* Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 4 The GNU C Library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 The GNU C Library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with the GNU C Library; if not, write to the Free 16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 17 02111-1307 USA. */ 18 19/* 20 * ISO C99 Standard: 7.24 21 * Extended multibyte and wide character utilities <wchar.h> 22 */ 23 24#ifndef _WCHAR_H 25 26#ifndef __need_mbstate_t 27# define _WCHAR_H 1 28# include <features.h> 29#endif 30 31#ifdef _WCHAR_H 32/* Get FILE definition. */ 33# define __need___FILE 34# ifdef __USE_UNIX98 35# define __need_FILE 36# endif 37# include <libio/stdio.h> 38/* Get va_list definition. */ 39# define __need___va_list 40# include <stdarg.h> 41 42/* Get size_t, wchar_t, wint_t and NULL from <stddef.h>. */ 43# define __need_size_t 44# define __need_wchar_t 45# define __need_NULL 46#endif 47#define __need_wint_t 48#include <stddef.h> 49 50#include <bits/wchar.h> 51 52/* We try to get wint_t from <stddef.h>, but not all GCC versions define it 53 there. So define it ourselves if it remains undefined. */ 54#ifndef _WINT_T 55/* Integral type unchanged by default argument promotions that can 56 hold any value corresponding to members of the extended character 57 set, as well as at least one value that does not correspond to any 58 member of the extended character set. */ 59# define _WINT_T 60typedef unsigned int wint_t; 61#endif 62 63 64#ifndef __mbstate_t_defined 65# define __mbstate_t_defined 1 66/* Conversion state information - for now a mixture between glibc's idea of 67 mbstate_t and our own. */ 68typedef struct 69{ 70 void* converter; 71 char charset[64]; 72 unsigned int count; 73 char data[1024 + 8]; // 1024 bytes for data, 8 for alignment space 74 int __count; 75 union 76 { 77 wint_t __wch; 78 char __wchb[4]; 79 } __value; /* Value so far. */ 80} __mbstate_t; 81#endif 82#undef __need_mbstate_t 83 84 85/* The rest of the file is only used if used if __need_mbstate_t is not 86 defined. */ 87#ifdef _WCHAR_H 88 89/* Public type. */ 90typedef __mbstate_t mbstate_t; 91 92#ifndef WCHAR_MIN 93/* These constants might also be defined in <inttypes.h>. */ 94# define WCHAR_MIN __WCHAR_MIN 95# define WCHAR_MAX __WCHAR_MAX 96#endif 97 98#ifndef WEOF 99# define WEOF (0xffffffffu) 100#endif 101 102/* For XPG4 compliance we have to define the stuff from <wctype.h> here 103 as well. */ 104#if defined __USE_XOPEN && !defined __USE_UNIX98 105# include <wctype.h> 106#endif 107 108/* This incomplete type is defined in <time.h> but needed here because 109 of `wcsftime'. */ 110struct tm; 111 112 113__BEGIN_DECLS 114 115 116__BEGIN_NAMESPACE_STD 117/* Search N wide characters of S for C. */ 118extern wchar_t *wmemchr (__const wchar_t *__s, wchar_t __c, size_t __n) 119 __THROW; 120 121/* Compare N wide characters of S1 and S2. */ 122extern int wmemcmp (__const wchar_t *__s1, __const wchar_t *__s2, size_t __n) 123 __THROW; 124/* Copy N wide characters of SRC to DEST. */ 125extern wchar_t *wmemcpy (wchar_t *__restrict __s1, 126 __const wchar_t *__restrict __s2, size_t __n) __THROW; 127 128/* Copy N wide characters of SRC to DEST, guaranteeing 129 correct behavior for overlapping strings. */ 130extern wchar_t *wmemmove (wchar_t *__s1, __const wchar_t *__s2, size_t __n) 131 __THROW; 132 133/* Set N wide characters of S to C. */ 134extern wchar_t *wmemset (wchar_t *__s, wchar_t __c, size_t __n) __THROW; 135 136#ifdef __USE_GNU 137/* Copy N wide characters of SRC to DEST and return pointer to following 138 wide character. */ 139extern wchar_t *wmempcpy (wchar_t *__restrict __s1, 140 __const wchar_t *__restrict __s2, size_t __n) 141 __THROW; 142#endif 143 144__BEGIN_NAMESPACE_STD 145/* Determine whether C constitutes a valid (one-byte) multibyte 146 character. */ 147extern wint_t btowc (int __c) __THROW; 148 149/* Determine whether C corresponds to a member of the extended 150 character set whose multibyte representation is a single byte. */ 151extern int wctob (wint_t __c) __THROW; 152 153/* Determine whether PS points to an object representing the initial 154 state. */ 155extern int mbsinit (__const mbstate_t *__ps) __THROW __attribute_pure__; 156 157/* Write wide character representation of multibyte character pointed 158 to by S to PWC. */ 159extern size_t mbrtowc (wchar_t *__restrict __pwc, 160 __const char *__restrict __s, size_t __n, 161 mbstate_t *__restrict __p) __THROW; 162 163/* Write multibyte representation of wide character WC to S. */ 164extern size_t wcrtomb (char *__restrict __s, wchar_t __wc, 165 mbstate_t *__restrict __ps) __THROW; 166 167/* Return number of bytes in multibyte character pointed to by S. */ 168extern size_t __mbrlen (__const char *__restrict __s, size_t __n, 169 mbstate_t *__restrict __ps) __THROW; 170extern size_t mbrlen (__const char *__restrict __s, size_t __n, 171 mbstate_t *__restrict __ps) __THROW; 172__END_NAMESPACE_STD 173 174__BEGIN_NAMESPACE_STD 175/* Write wide character representation of multibyte character string 176 SRC to DST. */ 177extern size_t mbsrtowcs (wchar_t *__restrict __dst, 178 __const char **__restrict __src, size_t __len, 179 mbstate_t *__restrict __ps) __THROW; 180 181/* Write multibyte character representation of wide character string 182 SRC to DST. */ 183extern size_t wcsrtombs (char *__restrict __dst, 184 __const wchar_t **__restrict __src, size_t __len, 185 mbstate_t *__restrict __ps) __THROW; 186__END_NAMESPACE_STD 187 188 189/* Convert initial portion of the wide string NPTR to `double' 190 representation. */ 191extern double wcstod (__const wchar_t *__restrict __nptr, 192 wchar_t **__restrict __endptr) __THROW; 193 194#ifdef __USE_ISOC99 195/* Likewise for `float' and `long double' sizes of floating-point numbers. */ 196extern float wcstof (__const wchar_t *__restrict __nptr, 197 wchar_t **__restrict __endptr) __THROW; 198extern long double wcstold (__const wchar_t *__restrict __nptr, 199 wchar_t **__restrict __endptr) __THROW; 200#endif /* C99 */ 201 202 203/* Convert initial portion of wide string NPTR to `long int' 204 representation. */ 205extern long int wcstol (__const wchar_t *__restrict __nptr, 206 wchar_t **__restrict __endptr, int __base) __THROW; 207 208/* Convert initial portion of wide string NPTR to `unsigned long int' 209 representation. */ 210extern unsigned long int wcstoul (__const wchar_t *__restrict __nptr, 211 wchar_t **__restrict __endptr, int __base) 212 __THROW; 213 214#if defined __GNUC__ && defined __USE_GNU 215/* Convert initial portion of wide string NPTR to `long int' 216 representation. */ 217__extension__ 218extern long long int wcstoq (__const wchar_t *__restrict __nptr, 219 wchar_t **__restrict __endptr, int __base) 220 __THROW; 221 222/* Convert initial portion of wide string NPTR to `unsigned long long int' 223 representation. */ 224__extension__ 225extern unsigned long long int wcstouq (__const wchar_t *__restrict __nptr, 226 wchar_t **__restrict __endptr, 227 int __base) __THROW; 228#endif /* GCC and use GNU. */ 229 230#if defined __USE_ISOC99 || (defined __GNUC__ && defined __USE_GNU) 231/* Convert initial portion of wide string NPTR to `long int' 232 representation. */ 233__extension__ 234extern long long int wcstoll (__const wchar_t *__restrict __nptr, 235 wchar_t **__restrict __endptr, int __base) 236 __THROW; 237 238/* Convert initial portion of wide string NPTR to `unsigned long long int' 239 representation. */ 240__extension__ 241extern unsigned long long int wcstoull (__const wchar_t *__restrict __nptr, 242 wchar_t **__restrict __endptr, 243 int __base) __THROW; 244#endif /* ISO C99 or GCC and GNU. */ 245 246 247/* The internal entry points for `wcstoX' take an extra flag argument 248 saying whether or not to parse locale-dependent number grouping. */ 249extern double __wcstod_internal (__const wchar_t *__restrict __nptr, 250 wchar_t **__restrict __endptr, int __group) 251 __THROW; 252extern float __wcstof_internal (__const wchar_t *__restrict __nptr, 253 wchar_t **__restrict __endptr, int __group) 254 __THROW; 255extern long double __wcstold_internal (__const wchar_t *__restrict __nptr, 256 wchar_t **__restrict __endptr, 257 int __group) __THROW; 258 259#ifndef __wcstol_internal_defined 260extern long int __wcstol_internal (__const wchar_t *__restrict __nptr, 261 wchar_t **__restrict __endptr, 262 int __base, int __group) __THROW; 263# define __wcstol_internal_defined 1 264#endif 265#ifndef __wcstoul_internal_defined 266extern unsigned long int __wcstoul_internal (__const wchar_t *__restrict __npt, 267 wchar_t **__restrict __endptr, 268 int __base, int __group) __THROW; 269# define __wcstoul_internal_defined 1 270#endif 271#ifndef __wcstoll_internal_defined 272__extension__ 273extern long long int __wcstoll_internal (__const wchar_t *__restrict __nptr, 274 wchar_t **__restrict __endptr, 275 int __base, int __group) __THROW; 276# define __wcstoll_internal_defined 1 277#endif 278#ifndef __wcstoull_internal_defined 279__extension__ 280extern unsigned long long int __wcstoull_internal (__const wchar_t * 281 __restrict __nptr, 282 wchar_t ** 283 __restrict __endptr, 284 int __base, 285 int __group) __THROW; 286# define __wcstoull_internal_defined 1 287#endif 288 289 290#if defined __OPTIMIZE__ && __GNUC__ >= 2 291/* Define inline functions which call the internal entry points. */ 292 293__extern_inline double wcstod (__const wchar_t *__restrict __nptr, 294 wchar_t **__restrict __endptr) __THROW 295{ return __wcstod_internal (__nptr, __endptr, 0); } 296__extern_inline long int wcstol (__const wchar_t *__restrict __nptr, 297 wchar_t **__restrict __endptr, 298 int __base) __THROW 299{ return __wcstol_internal (__nptr, __endptr, __base, 0); } 300__extern_inline unsigned long int wcstoul (__const wchar_t *__restrict __nptr, 301 wchar_t **__restrict __endptr, 302 int __base) __THROW 303{ return __wcstoul_internal (__nptr, __endptr, __base, 0); } 304 305# ifdef __USE_GNU 306__extern_inline float wcstof (__const wchar_t *__restrict __nptr, 307 wchar_t **__restrict __endptr) __THROW 308{ return __wcstof_internal (__nptr, __endptr, 0); } 309__extern_inline long double wcstold (__const wchar_t *__restrict __nptr, 310 wchar_t **__restrict __endptr) __THROW 311{ return __wcstold_internal (__nptr, __endptr, 0); } 312 313 314__extension__ 315__extern_inline long long int wcstoq (__const wchar_t *__restrict __nptr, 316 wchar_t **__restrict __endptr, 317 int __base) __THROW 318{ return __wcstoll_internal (__nptr, __endptr, __base, 0); } 319__extension__ 320__extern_inline unsigned long long int wcstouq (__const wchar_t * 321 __restrict __nptr, 322 wchar_t **__restrict __endptr, 323 int __base) __THROW 324{ return __wcstoull_internal (__nptr, __endptr, __base, 0); } 325# endif /* Use GNU. */ 326#endif /* Optimizing GCC >=2. */ 327 328 329/* Wide character I/O functions. */ 330#if defined __USE_ISOC99 || defined __USE_UNIX98 331 332/* Select orientation for stream. */ 333extern int fwide (__FILE *__fp, int __mode) __THROW; 334 335 336/* Write formatted output to STREAM. */ 337extern int fwprintf (__FILE *__restrict __stream, 338 __const wchar_t *__restrict __format, ...) 339 __THROW /* __attribute__ ((__format__ (__wprintf__, 2, 3))) */; 340/* Write formatted output to stdout. */ 341extern int wprintf (__const wchar_t *__restrict __format, ...) 342 __THROW /* __attribute__ ((__format__ (__wprintf__, 1, 2))) */; 343/* Write formatted output of at most N characters to S. */ 344extern int swprintf (wchar_t *__restrict __s, size_t __n, 345 __const wchar_t *__restrict __format, ...) 346 __THROW /* __attribute__ ((__format__ (__wprintf__, 3, 4))) */; 347 348/* Write formatted output to S from argument list ARG. */ 349extern int vfwprintf (__FILE *__restrict __s, 350 __const wchar_t *__restrict __format, 351 __gnuc_va_list __arg) 352 __THROW /* __attribute__ ((__format__ (__wprintf__, 2, 0))) */; 353/* Write formatted output to stdout from argument list ARG. */ 354extern int vwprintf (__const wchar_t *__restrict __format, 355 __gnuc_va_list __arg) 356 __THROW /* __attribute__ ((__format__ (__wprintf__, 1, 0))) */; 357/* Write formatted output of at most N character to S from argument 358 list ARG. */ 359extern int vswprintf (wchar_t *__restrict __s, size_t __n, 360 __const wchar_t *__restrict __format, 361 __gnuc_va_list __arg) 362 __THROW /* __attribute__ ((__format__ (__wprintf__, 3, 0))) */; 363 364 365/* Read formatted input from STREAM. */ 366extern int fwscanf (__FILE *__restrict __stream, 367 __const wchar_t *__restrict __format, ...) 368 __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */; 369/* Read formatted input from stdin. */ 370extern int wscanf (__const wchar_t *__restrict __format, ...) 371 __THROW /* __attribute__ ((__format__ (__wscanf__, 1, 2))) */; 372/* Read formatted input from S. */ 373extern int swscanf (__const wchar_t *__restrict __s, 374 __const wchar_t *__restrict __format, ...) 375 __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */; 376#endif /* Use ISO C99 and Unix98. */ 377 378#ifdef __USE_ISOC99 379/* Read formatted input from S into argument list ARG. */ 380extern int vfwscanf (__FILE *__restrict __s, 381 __const wchar_t *__restrict __format, 382 __gnuc_va_list __arg) 383 __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */; 384/* Read formatted input from stdin into argument list ARG. */ 385extern int vwscanf (__const wchar_t *__restrict __format, 386 __gnuc_va_list __arg) 387 __THROW /* __attribute__ ((__format__ (__wscanf__, 1, 0))) */; 388/* Read formatted input from S into argument list ARG. */ 389extern int vswscanf (__const wchar_t *__restrict __s, 390 __const wchar_t *__restrict __format, 391 __gnuc_va_list __arg) 392 __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */; 393#endif /* Use ISO C99. */ 394 395 396/* Read a character from STREAM. */ 397extern wint_t fgetwc (__FILE *__stream) __THROW; 398extern wint_t getwc (__FILE *__stream) __THROW; 399 400/* Read a character from stdin. */ 401extern wint_t getwchar (void) __THROW; 402 403 404/* Write a character to STREAM. */ 405extern wint_t fputwc (wchar_t __wc, __FILE *__stream) __THROW; 406extern wint_t putwc (wchar_t __wc, __FILE *__stream) __THROW; 407 408/* Write a character to stdout. */ 409extern wint_t putwchar (wchar_t __wc) __THROW; 410 411 412/* Get a newline-terminated wide character string of finite length 413 from STREAM. */ 414extern wchar_t *fgetws (wchar_t *__restrict __ws, int __n, 415 __FILE *__restrict __stream) __THROW; 416 417/* Write a string to STREAM. */ 418extern int fputws (__const wchar_t *__restrict __ws, 419 __FILE *__restrict __stream) __THROW; 420 421 422/* Push a character back onto the input buffer of STREAM. */ 423extern wint_t ungetwc (wint_t __wc, __FILE *__stream) __THROW; 424 425 426#ifdef __USE_GNU 427/* These are defined to be equivalent to the `char' functions defined 428 in POSIX.1:1996. */ 429extern wint_t getwc_unlocked (__FILE *__stream) __THROW; 430extern wint_t getwchar_unlocked (void) __THROW; 431 432/* This is the wide character version of a GNU extension. */ 433extern wint_t fgetwc_unlocked (__FILE *__stream) __THROW; 434 435/* Faster version when locking is not necessary. */ 436extern wint_t fputwc_unlocked (wchar_t __wc, __FILE *__stream) __THROW; 437 438/* These are defined to be equivalent to the `char' functions defined 439 in POSIX.1:1996. */ 440extern wint_t putwc_unlocked (wchar_t __wc, __FILE *__stream) __THROW; 441extern wint_t putwchar_unlocked (wchar_t __wc) __THROW; 442 443 444/* This function does the same as `fgetws' but does not lock the stream. */ 445extern wchar_t *fgetws_unlocked (wchar_t *__restrict __ws, int __n, 446 __FILE *__restrict __stream) __THROW; 447 448/* This function does the same as `fputws' but does not lock the stream. */ 449extern int fputws_unlocked (__const wchar_t *__restrict __ws, 450 __FILE *__restrict __stream) __THROW; 451#endif 452 453 454__END_DECLS 455 456#endif /* _WCHAR_H defined */ 457 458#endif /* wchar.h */ 459