📄 iconv.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>iconv</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_005_923"> </a>NAME</h4><blockquote>iconv - codeset conversion function</blockquote><h4><a name = "tag_000_005_924"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="iconv.h.html">iconv.h</a>>size_t iconv(iconv_t <i>cd</i>, const char *<i>*inbuf</i>, size_t *<i>inbytesleft</i>, char *<i>*outbuf</i>, size_t *<i>outbytesleft</i>);</code></pre></blockquote><h4><a name = "tag_000_005_925"> </a>DESCRIPTION</h4><blockquote>The<i>iconv()</i>function converts the sequence of characters from one codeset,in the array specified by<i>inbuf</i>,into a sequence of corresponding characters in another codeset,in the array specified by<i>outbuf</i>.The codesets are those specified in the<i><a href="iconv_open.html">iconv_open()</a></i>call that returned the conversion descriptor,<i>cd</i>.The<i>inbuf</i>argument points to a variable thatpoints to the first character in the input buffer and<i>inbytesleft</i>indicates the number of bytes to the end of the buffer to be converted.The<i>outbuf</i>argument points to a variable thatpoints to the first available byte in the output buffer and<i>outbytesleft</i>indicates the number of the available bytes to the end of the buffer.<p>For state-dependent encodings, the conversion descriptor<i>cd</i>is placed into its initial shift stateby a call for which<i>inbuf</i>is a null pointer, or for which<i>inbuf</i>points to a null pointer.When<i>iconv()</i>is called in this way, and if<i>outbuf</i>is not a null pointer or a pointer to a null pointer, and<i>outbytesleft</i>points to a positive value,<i>iconv()</i>will place, into the output buffer,the byte sequence to change the output buffer to its initialshift state. If the output buffer is not large enough to hold the entirereset sequence,<i>iconv()</i>will fail and set<i>errno</i>to [E2BIG].Subsequent calls with<i>inbuf</i>as other than a null pointer or a pointer to a null pointer cause theconversion to take place from the current state of the conversion descriptor.<p>If a sequence of input bytes does not form a valid characterin the specified codeset, conversion stopsafter the previous successfully converted character.If the input buffer ends with an incomplete character or shift sequence,conversion stops after the previous successfully converted bytes.If the output buffer is not large enough to hold the entire convertedinput, conversion stops just prior to the input bytes that would cause theoutput buffer to overflow.The variable pointed to by<i>inbuf</i>is updated to point to the byte following the last byte successfullyused in the conversion. Thevalue pointed to by<i>inbytesleft</i>is decremented to reflect the number of bytes still not converted inthe input buffer.The variable pointed to by<i>outbuf</i>is updated to point to the byte following the last byte of convertedoutput data.The value pointed to by<i>outbytesleft</i>is decremented to reflect the number of bytes still available in theoutput buffer.For state-dependent encodings, the conversion descriptor is updatedto reflect the shift state in effect at the end of the lastsuccessfully converted byte sequence.<p>If<i>iconv()</i>encounters a character in the input buffer that is valid, but for which anidentical character does not exist in the target codeset,<i>iconv()</i>performs an implementation-dependent conversion on this character.</blockquote><h4><a name = "tag_000_005_926"> </a>RETURN VALUE</h4><blockquote>The<i>iconv()</i>function updates the variables pointed to by the arguments to reflect theextent of the conversion and returns the number of non-identical conversionsperformed. If the entire string in the input buffer is converted, the valuepointed to by<i>inbytesleft</i>will be 0. If the input conversion is stopped due to any conditionsmentioned above, the value pointed to by<i>inbytesleft</i>will be non-zero and<i>errno</i>is set to indicate the condition. If an error occurs<i>iconv()</i>returns (<b>size_t</b>)-1 and sets<i>errno</i>to indicate the error.<br></blockquote><h4><a name = "tag_000_005_927"> </a>ERRORS</h4><blockquote>The<i>iconv()</i>function will fail if:<dl compact><dt>[EILSEQ]<dd>Input conversion stopped due to an input byte that does not belong to theinput codeset.<dt>[E2BIG]<dd>Input conversion stopped due to lack of space in the output buffer.<dt>[EINVAL]<dd>Input conversion stopped due to an incompletecharacter or shift sequence at the end of the input buffer.</dl><p>The<i>iconv()</i>function may fail if:<dl compact><dt>[EBADF]<dd>The<i>cd</i>argument is not a valid open conversion descriptor.</dl></blockquote><h4><a name = "tag_000_005_928"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_005_929"> </a>APPLICATION USAGE</h4><blockquote>The<i>inbuf</i>argument indirectly points to the memory area which contains the conversioninput data. The<i>outbuf</i>argument indirectly points to the memory area which is to contain the resultof the conversion. The objects indirectly pointed to by<i>inbuf</i>and<i>outbuf</i>are not restricted to containing data that is directly representable in theISO C language<b>char</b>data type. The type of<i>inbuf</i>and<i>outbuf</i>,<b>char **</b>,does not imply that the objects pointed to are interpreted asnull-terminated C strings or arrays of characters. Any interpretation ofa byte sequencethat represents a character in a given character setencoding scheme is done internally within the codesetconverters. For example, the area pointed to indirectly by<i>inbuf</i>and/or<i>outbuf</i>can contain all zero octets that are not interpreted as string terminators butas coded character data according to the respective codeset encoding scheme.The type of the data (<b> char</b> ,<b>short int</b>,<b>long int</b>,and so on) read or stored in the objects is not specified, but may be inferredfor both the input and output data by the converters determined by the<i>fromcode</i>and<i>tocode</i>arguments of<i><a href="iconv_open.html">iconv_open()</a></i>.<p>Regardless of the data type inferred by the converter, thesize of the remaining space in both input and output objects (the<i>intbytesleft</i>and<i>outbytesleft</i>arguments) is always measured in bytes.<p>For implementations that support the conversion of state-dependent encodings,the conversion descriptor must be able to accurately reflect the shift-statein effect at the end of the last successful conversion. It is not requiredthat the conversion descriptor itself be updated, which would require it to bea pointer type. Thus, implementations are free to implement the descriptor asa handle (other than a pointer type) by which the conversion information canbe accessed and updated.</blockquote><h4><a name = "tag_000_005_930"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_005_931"> </a>SEE ALSO</h4><blockquote><i><a href="iconv_open.html">iconv_open()</a></i>,<i><a href="iconv_close.html">iconv_close()</a></i>,<i><a href="iconv.h.html"><iconv.h></a></i>.</blockquote><h4>DERIVATION</h4><blockquote>Derived from the HP-UX manual.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -