Previous Table of Contents Next


swprintf, swscanf

int swprintf(wchar_t *buf, size_t bufsize, const wchar_t *fmt, …)
int swscanf(const wchar_t *buf, const wchar_t *fmt, …)

These functions generate or scan formatted strings under control of their fmt arguments, analogously to the sprintf and sscanf functions of section 3.10.1.6, except that both the format strings and the strings read or written are of wide characters. Also, swprintf accepts a bufsize argument that is the size of the array pointed to by buf (in units of wide characters), so it can ensure that the array bounds will not be exceeded. See also section 3.10.17.6.

vwprintf, vfwprintf, vswprintf

int vwprintf(const wchar_t *fmt, va_list argp)
int vfwprintf(FILE *fp, const wchar_t *fmt, va_list argp)
int vswprintf(wchar_t *buf, size_t bufsize,
                        const wchar_t *fmt, va_list argp)

These functions are analogous to those of section 3.10.1.7, except that they work with wide character strings, along the lines of wprintf, fwprintf, and swprintf; see section 3.10.17.6. vswprintf’s bufsize argument is as for swprintf (see section 3.10.17.6).

fwide

int fwide(FILE *fp, int mode)

Each stdio stream has an “orientation” that reflects whether it is being used to read or write normal characters (using the functions of section 3.10.1) or multibyte characters (using the functions of this section). A stream starts out “unoriented” but is switched to either “byte-oriented” or “wide-oriented” upon the first input or output call. fwide attempts to set or reset the orientation of the stream fp to byte-oriented if mode is less than 0 or to wide-oriented if mode is greater than 0. The return value reflects the actual orientation of the stream after the call (where zero indicates unoriented).

3.10.17.7. More Wide String Conversion Functions

The functions here expand on those described in section 3.10.4.7.

btowc, wctob

wint_t btowc(int c)
int wctob(wint_t wc)

These functions convert between normal characters and their wide character equivalents. btowc converts the character c to the corresponding wide character. wctob attempts to convert the wide character wc to a normal character, returning either that character or EOF if the conversion is impossible.

mbrlen

size_t mbrlen(const char *s, size_t n, mbstate_t *state)

mbrlen is similar to mblen (see section 3.10.4.7) except that it can complete the computation of the length of an interrupted multibyte sequence, with the initial part reflected in the state object and the remaining part pointed to by s. The return value is as for mbrtowc.

mbrtowc, wcrtomb

size_t mbrtowc(wchar_t *dest, const char *src, size_t n,
                                        mbstate_t *state)
size_t wcrtomb(char *dest, wchar_t src, mbstate_t *state)

These functions are similar to mbtowc and wctomb (see section 3.10.4.7) except that they can work with multibyte sequences that have been interrupted, as long as the state of the conversion is accurately recorded in the object pointed to by state. mbrtowc converts a multibyte sequence at src to a wide character at dest and returns the number of bytes pointed to by src that form a valid multibyte character, or 0 if src points to a null multibyte character, or -1 if an encoding error is detected, or -2 if bytes have been read from src (and used to update *state) but no complete character has been found. wcrtomb converts the wide character src to a multibyte sequence at dest and returns the number of bytes written to dest, or -1 to indicate an encoding error.

mbsrtowcs, wcsrtombs

size_t mbsrtowcs(wchar_t *dest, const char **srcp, size_t n,
                                       mbstate_t *state)
size_t wcsrtombs(char *dest, const wchar_t **srcp, size_t n,
                                        mbstate_t *state)

These functions are similar to mbstowcs and wcstombs (see section 3.10.4.7) except that they can work with multibyte sequences that have been interrupted. The impending state of the conversion is recorded in the pointed-to object *state. The source string is passed by reference and is updated to point to the remaining unconverted string, if any. That is, if n is insufficient (as a number of wide characters for mbsrtowcs or bytes for wcsrtombs) for the destination buffer to contain the converted result, *srcp is set to point to the unconverted input, and *state is updated to reflect any interrupted conversion state.

mbsinit

int mbsinit(const mbstate_t *p)

mbsinit returns nonzero if the state object pointed to by p is in its initial state, or if p is a null pointer.


Previous Table of Contents Next