]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/mbtowc.3
mbtowc.3: ffix
[thirdparty/man-pages.git] / man3 / mbtowc.3
1 .\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2 .\"
3 .\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
8 .\" %%%LICENSE_END
9 .\"
10 .\" References consulted:
11 .\" GNU glibc-2 source code and manual
12 .\" Dinkumware C library reference http://www.dinkumware.com/
13 .\" OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html
14 .\" ISO/IEC 9899:1999
15 .\"
16 .TH MBTOWC 3 2011-09-28 "GNU" "Linux Programmer's Manual"
17 .SH NAME
18 mbtowc \- convert a multibyte sequence to a wide character
19 .SH SYNOPSIS
20 .nf
21 .B #include <stdlib.h>
22 .sp
23 .BI "int mbtowc(wchar_t *" pwc ", const char *" s ", size_t " n );
24 .fi
25 .SH DESCRIPTION
26 The main case for this function is when \fIs\fP is not NULL and \fIpwc\fP is
27 not NULL.
28 In this case, the
29 .BR mbtowc ()
30 function inspects at most \fIn\fP
31 bytes of the multibyte string starting at \fIs\fP,
32 extracts the next complete
33 multibyte character, converts it to a wide character and stores it at
34 \fI*pwc\fP.
35 It updates an internal shift state only known to the
36 .BR mbtowc ()
37 function.
38 If \fIs\fP does not point to a null byte (\(aq\\0\(aq), it returns the number
39 of bytes that were consumed from \fIs\fP, otherwise it returns 0.
40 .PP
41 If the \fIn\fP bytes starting at \fIs\fP do not contain a complete multibyte
42 character, or if they contain an invalid multibyte sequence,
43 .BR mbtowc ()
44 returns \-1.
45 This can happen even if \fIn\fP >= \fIMB_CUR_MAX\fP,
46 if the multibyte string contains redundant shift sequences.
47 .PP
48 A different case is when \fIs\fP is not NULL but \fIpwc\fP is NULL.
49 In this
50 case the
51 .BR mbtowc ()
52 function behaves as above, except that it does not
53 store the converted wide character in memory.
54 .PP
55 A third case is when \fIs\fP is NULL.
56 In this case, \fIpwc\fP and \fIn\fP are
57 ignored.
58 The
59 .BR mbtowc ()
60 function
61 .\" The Dinkumware doc and the Single UNIX specification say this, but
62 .\" glibc doesn't implement this.
63 resets the shift state, only known to this function,
64 to the initial state, and
65 returns nonzero if the encoding has nontrivial shift state, or zero if the
66 encoding is stateless.
67 .SH RETURN VALUE
68 If \fIs\fP is not NULL, the
69 .BR mbtowc ()
70 function returns the number of
71 consumed bytes starting at \fIs\fP, or 0 if \fIs\fP points to a null byte,
72 or \-1 upon failure.
73 .PP
74 If \fIs\fP is NULL, the
75 .BR mbtowc ()
76 function
77 returns nonzero if the encoding
78 has nontrivial shift state, or zero if the encoding is stateless.
79 .SH CONFORMING TO
80 C99.
81 .SH NOTES
82 The behavior of
83 .BR mbtowc ()
84 depends on the
85 .B LC_CTYPE
86 category of the
87 current locale.
88 .PP
89 This function is not multithread safe.
90 The function
91 .BR mbrtowc (3)
92 provides
93 a better interface to the same functionality.
94 .SH SEE ALSO
95 .BR MB_CUR_MAX (3),
96 .BR mbrtowc (3),
97 .BR mbstowcs (3)