blob: bf919cdbc428b6af58ec046591e0b7de31d6d852 [file]
<html lang="en">
<head>
<title>mbtowc - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Stdlib.html#Stdlib" title="Stdlib">
<link rel="prev" href="mblen.html#mblen" title="mblen">
<link rel="next" href="on_005fexit.html#on_005fexit" title="on_exit">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="mbtowc"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="on_005fexit.html#on_005fexit">on_exit</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="mblen.html#mblen">mblen</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Stdlib.html#Stdlib">Stdlib</a>
<hr>
</div>
<h3 class="section">2.29 <code>mbtowc</code>&mdash;minimal multibyte to wide char converter</h3>
<p><a name="index-mbtowc-63"></a><strong>Synopsis</strong>
<pre class="example"> #include &lt;stdlib.h&gt;
int mbtowc(wchar_t *<var>pwc</var>, const char *<var>s</var>, size_t <var>n</var>);
</pre>
<p><strong>Description</strong><br>
When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming
implementation of <code>mbtowc</code>. In this case,
only &ldquo;multi-byte character sequences&rdquo; recognized are single bytes,
and they are &ldquo;converted&rdquo; to themselves.
Each call to <code>mbtowc</code> copies one character from <code>*</code><var>s</var> to
<code>*</code><var>pwc</var>, unless <var>s</var> is a null pointer. The argument n
is ignored.
<p>When _MB_CAPABLE is defined, this routine calls <code>_mbtowc_r</code> to perform
the conversion, passing a state variable to allow state dependent
decoding. The result is based on the locale setting which may
be restricted to a defined set of locales.
<p><br>
<strong>Returns</strong><br>
This implementation of <code>mbtowc</code> returns <code>0</code> if
<var>s</var> is <code>NULL</code> or is the empty string;
it returns <code>1</code> if not _MB_CAPABLE or
the character is a single-byte character; it returns <code>-1</code>
if n is <code>0</code> or the multi-byte character is invalid;
otherwise it returns the number of bytes in the multibyte character.
If the return value is -1, no changes are made to the <code>pwc</code>
output string. If the input is the empty string, a wchar_t nul
is placed in the output string and 0 is returned. If the input
has a length of 0, no changes are made to the <code>pwc</code> output string.
<p><br>
<strong>Portability</strong><br>
<code>mbtowc</code> is required in the ANSI C standard. However, the precise
effects vary with the locale.
<p><code>mbtowc</code> requires no supporting OS subroutines.
<p><br>
</body></html>