]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/mbsnrtowcs.3
4e6dbea3f0b1568970effe4186e3b3080bd18250
[thirdparty/man-pages.git] / man3 / mbsnrtowcs.3
1 .\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2 .\"
3 .\" This is free documentation; you can redistribute it and/or
4 .\" modify it under the terms of the GNU General Public License as
5 .\" published by the Free Software Foundation; either version 2 of
6 .\" the License, or (at your option) any later version.
7 .\"
8 .\" References consulted:
9 .\" GNU glibc-2 source code and manual
10 .\" Dinkumware C library reference http://www.dinkumware.com/
11 .\" OpenGroup's Single Unix specification http://www.UNIX-systems.org/online.html
12 .\"
13 .TH MBSNRTOWCS 3 2007-07-26 "GNU" "Linux Programmer's Manual"
14 .SH NAME
15 mbsnrtowcs \- convert a multibyte string to a wide-character string
16 .SH SYNOPSIS
17 .nf
18 .B #define _GNU_SOURCE
19 .B #include <wchar.h>
20 .sp
21 .BI "size_t mbsnrtowcs(wchar_t *" dest ", const char **" src ,
22 .BI " size_t " nms ", size_t " len ", mbstate_t *" ps );
23 .fi
24 .SH DESCRIPTION
25 The
26 .BR mbsnrtowcs ()
27 function is like the
28 .BR mbsrtowcs (3)
29 function, except that
30 the number of bytes to be converted, starting at \fI*src\fP, is limited to
31 \fInms\fP.
32 .PP
33 If \fIdest\fP is not a NULL pointer, the
34 .BR mbsnrtowcs ()
35 function converts at
36 most \fInms\fP bytes from the
37 multibyte string \fI*src\fP to a wide-character string starting at \fIdest\fP.
38 At most \fIlen\fP wide characters are written to \fIdest\fP.
39 The shift state
40 \fI*ps\fP is updated.
41 The conversion is effectively performed by repeatedly
42 calling
43 .I "mbrtowc(dest, *src, n, ps)"
44 where \fIn\fP is some
45 positive number, as long as this call succeeds, and then incrementing
46 \fIdest\fP by one and \fI*src\fP by the number of bytes consumed.
47 The
48 conversion can stop for three reasons:
49 .PP
50 1. An invalid multibyte sequence has been encountered.
51 In this case \fI*src\fP
52 is left pointing to the invalid multibyte sequence,
53 .I (size_t)(\-1)
54 is returned,
55 and \fIerrno\fP is set to \fBEILSEQ\fP.
56 .PP
57 2. The \fInms\fP limit forces a stop, or \fIlen\fP non-L'\\0' wide characters
58 have been stored at \fIdest\fP.
59 In this case \fI*src\fP is left pointing to the
60 next multibyte sequence to be converted, and the number of wide characters
61 written to \fIdest\fP is returned.
62 .PP
63 3. The multibyte string has been completely converted, including the
64 terminating '\\0' (which has the side effect of bringing back \fI*ps\fP to the
65 initial state).
66 In this case \fI*src\fP is set to NULL, and the number of wide
67 characters written to \fIdest\fP, excluding the terminating L'\\0' character,
68 is returned.
69 .PP
70 If \fIdest\fP is NULL, \fIlen\fP is ignored, and the conversion proceeds as
71 above, except that the converted wide characters
72 are not written out to memory,
73 and that no destination length limit exists.
74 .PP
75 In both of the above cases, if \fIps\fP is a NULL pointer, a static anonymous
76 state only known to the mbsnrtowcs function is used instead.
77 .PP
78 The programmer must ensure that there is room for at least \fIlen\fP wide
79 characters at \fIdest\fP.
80 .SH "RETURN VALUE"
81 The
82 .BR mbsnrtowcs ()
83 function returns the number of wide characters
84 that make up the converted part of the wide-character string,
85 not including the terminating null wide character.
86 If an invalid multibyte sequence was
87 encountered,
88 .I (size_t)(\-1)
89 is returned, and \fIerrno\fP set to \fBEILSEQ\fP.
90 .SH "CONFORMING TO"
91 This function is a GNU extension.
92 .SH NOTES
93 The behavior of
94 .BR mbsnrtowcs ()
95 depends on the
96 .B LC_CTYPE
97 category of the
98 current locale.
99 .PP
100 Passing NULL as \fIps\fP is not multi-thread safe.
101 .SH "SEE ALSO"
102 .BR iconv (3),
103 .BR mbsrtowcs (3)