]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (c) Bruno Haible <haible@clisp.cons.org> |
2 | .\" | |
89e3ffe9 | 3 | .\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA) |
fea681da MK |
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. | |
fe382ebf | 8 | .\" %%%LICENSE_END |
fea681da MK |
9 | .\" |
10 | .\" References consulted: | |
11 | .\" GNU glibc-2 source code and manual | |
12 | .\" Dinkumware C library reference http://www.dinkumware.com/ | |
008f1ecc | 13 | .\" OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html |
fea681da | 14 | .\" |
3c81e148 | 15 | .TH WCSNRTOMBS 3 2011-10-16 "GNU" "Linux Programmer's Manual" |
fea681da | 16 | .SH NAME |
d0f17b57 | 17 | wcsnrtombs \- convert a wide-character string to a multibyte string |
fea681da MK |
18 | .SH SYNOPSIS |
19 | .nf | |
20 | .B #include <wchar.h> | |
21 | .sp | |
22 | .BI "size_t wcsnrtombs(char *" dest ", const wchar_t **" src ", size_t " nwc , | |
b9f02710 | 23 | .BI " size_t " len ", mbstate_t *" ps ); |
fea681da | 24 | .fi |
7dbff9b4 MK |
25 | .sp |
26 | .in -4n | |
27 | Feature Test Macro Requirements for glibc (see | |
28 | .BR feature_test_macros (7)): | |
29 | .in | |
30 | .sp | |
31 | .BR wcsnrtombs (): | |
ea91c3fd MK |
32 | .PD 0 |
33 | .ad l | |
34 | .RS 4 | |
35 | .TP 4 | |
36 | Since glibc 2.10: | |
37 | _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L | |
38 | .TP | |
7dbff9b4 MK |
39 | Before glibc 2.10: |
40 | _GNU_SOURCE | |
ea91c3fd MK |
41 | .RE |
42 | .ad | |
43 | .PD | |
fea681da | 44 | .SH DESCRIPTION |
60a90ecd MK |
45 | The |
46 | .BR wcsnrtombs () | |
47 | function is like the | |
9daa4fb9 | 48 | .BR wcsrtombs (3) |
60a90ecd | 49 | function, |
c13182ef | 50 | except that the number of wide characters to be converted, |
35478399 | 51 | starting at \fI*src\fP, is limited to \fInwc\fP. |
fea681da | 52 | .PP |
c13182ef | 53 | If \fIdest\fP is not a NULL pointer, |
60a90ecd MK |
54 | the |
55 | .BR wcsnrtombs () | |
56 | function converts | |
fea681da MK |
57 | at most \fInwc\fP wide characters from |
58 | the wide-character string \fI*src\fP to a multibyte string starting at | |
c13182ef MK |
59 | \fIdest\fP. |
60 | At most \fIlen\fP bytes are written to \fIdest\fP. | |
61 | The shift state | |
62 | \fI*ps\fP is updated. | |
63 | The conversion is effectively performed by repeatedly | |
657e762d | 64 | calling |
930d718c | 65 | .IR "wcrtomb(dest, *src, ps)" , |
c13182ef MK |
66 | as long as this call succeeds, |
67 | and then incrementing \fIdest\fP by the | |
68 | number of bytes written and \fI*src\fP | |
69 | by one. | |
70 | The conversion can stop for three reasons: | |
fea681da MK |
71 | .PP |
72 | 1. A wide character has been encountered that can not be represented as a | |
c13182ef MK |
73 | multibyte sequence (according to the current locale). |
74 | In this case \fI*src\fP | |
7d2cb9d5 | 75 | is left pointing to the invalid wide character, |
009df872 | 76 | .I (size_t)\ \-1 |
7d2cb9d5 | 77 | is returned, |
dcec8eb5 | 78 | and \fIerrno\fP is set to \fBEILSEQ\fP. |
fea681da | 79 | .PP |
c13182ef | 80 | 2. \fInwc\fP wide characters have been |
e9c23bc6 | 81 | converted without encountering a null wide character (L\(aq\\0\(aq), |
c13182ef MK |
82 | or the length limit forces a stop. |
83 | In this case \fI*src\fP is left pointing | |
fea681da MK |
84 | to the next wide character to be converted, and the number of bytes written |
85 | to \fIdest\fP is returned. | |
86 | .PP | |
87 | 3. The wide-character string has been completely converted, including the | |
e9c23bc6 | 88 | terminating null wide character (which has the side effect of bringing back \fI*ps\fP |
c13182ef MK |
89 | to the initial state). |
90 | In this case \fI*src\fP is set to NULL, and the number | |
3c81e148 MK |
91 | of bytes written to \fIdest\fP, |
92 | excluding the terminating null byte (\(aq\\0\(aq), is | |
fea681da MK |
93 | returned. |
94 | .PP | |
c13182ef MK |
95 | If \fIdest\fP is NULL, \fIlen\fP is ignored, |
96 | and the conversion proceeds as above, | |
97 | except that the converted bytes are not written out to memory, and that | |
fea681da MK |
98 | no destination length limit exists. |
99 | .PP | |
c13182ef MK |
100 | In both of the above cases, |
101 | if \fIps\fP is a NULL pointer, a static anonymous | |
fea681da MK |
102 | state only known to the wcsnrtombs function is used instead. |
103 | .PP | |
104 | The programmer must ensure that there is room for at least \fIlen\fP bytes | |
105 | at \fIdest\fP. | |
47297adb | 106 | .SH RETURN VALUE |
60a90ecd MK |
107 | The |
108 | .BR wcsnrtombs () | |
109 | function returns | |
c13182ef MK |
110 | the number of bytes that make up the |
111 | converted part of multibyte sequence, | |
3c81e148 | 112 | not including the terminating null byte. |
c13182ef | 113 | If a wide character was encountered which |
7d2cb9d5 | 114 | could not be converted, |
009df872 | 115 | .I (size_t)\ \-1 |
dcec8eb5 | 116 | is returned, and \fIerrno\fP set to \fBEILSEQ\fP. |
47297adb | 117 | .SH CONFORMING TO |
d9a8bda4 | 118 | POSIX.1-2008. |
fea681da | 119 | .SH NOTES |
d9bfdb9c | 120 | The behavior of |
60a90ecd | 121 | .BR wcsnrtombs () |
1274071a MK |
122 | depends on the |
123 | .B LC_CTYPE | |
124 | category of the | |
fea681da MK |
125 | current locale. |
126 | .PP | |
71fea607 | 127 | Passing NULL as \fIps\fP is not multithread safe. |
47297adb | 128 | .SH SEE ALSO |
e37e3282 MK |
129 | .BR iconv (3), |
130 | .BR wcsrtombs (3) |