]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/mbstowcs.3
7296b87c672f86a669b4d7d797a6506077dfe742
[thirdparty/man-pages.git] / man3 / mbstowcs.3
1 .\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2 .\"
3 .\" %%%LICENSE_START(GPLv2+_ONEPARA_DOC)
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 MBSTOWCS 3 2011-09-28 "GNU" "Linux Programmer's Manual"
17 .SH NAME
18 mbstowcs \- convert a multibyte string to a wide-character string
19 .SH SYNOPSIS
20 .nf
21 .B #include <stdlib.h>
22 .sp
23 .BI "size_t mbstowcs(wchar_t *" dest ", const char *" src ", size_t " n );
24 .fi
25 .SH DESCRIPTION
26 If \fIdest\fP is not a NULL pointer,
27 the
28 .BR mbstowcs ()
29 function converts the
30 multibyte string \fIsrc\fP to a wide-character string starting at \fIdest\fP.
31 At most \fIn\fP wide characters are written to \fIdest\fP.
32 The conversion starts
33 in the initial state.
34 The conversion can stop for three reasons:
35 .IP 1. 3
36 An invalid multibyte sequence has been encountered.
37 In this case
38 .I (size_t)\ \-1
39 is returned.
40 .IP 2.
41 \fIn\fP non-L\(aq\\0\(aq wide characters have been stored at \fIdest\fP.
42 In this
43 case the number of wide characters written to \fIdest\fP is returned, but the
44 shift state at this point is lost.
45 .IP 3.
46 The multibyte string has been completely converted, including the
47 terminating null wide character (\(aq\\0\(aq).
48 In this case the number of wide characters written to
49 \fIdest\fP, excluding the terminating null wide character, is returned.
50 .PP
51 The programmer must ensure that there is room for at least \fIn\fP wide
52 characters at \fIdest\fP.
53 .PP
54 If \fIdest\fP is NULL, \fIn\fP is ignored, and the conversion proceeds as
55 above, except that the converted wide characters are not written out to memory,
56 and that no length limit exists.
57 .PP
58 In order to avoid the case 2 above, the programmer should make sure \fIn\fP is
59 greater or equal to \fImbstowcs(NULL,src,0)+1\fP.
60 .SH RETURN VALUE
61 The
62 .BR mbstowcs ()
63 function returns the number of wide characters that make
64 up the converted part of the wide-character string, not including the
65 terminating null wide character.
66 If an invalid multibyte sequence was
67 encountered,
68 .I (size_t)\ \-1
69 is returned.
70 .SH CONFORMING TO
71 C99.
72 .SH NOTES
73 The behavior of
74 .BR mbstowcs ()
75 depends on the
76 .B LC_CTYPE
77 category of the
78 current locale.
79 .PP
80 The function
81 .BR mbsrtowcs (3)
82 provides a better interface to the same
83 functionality.
84 .SH SEE ALSO
85 .BR mbsrtowcs (3),
86 .BR wcstombs (3)