diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/string%2Fwide%2Fwmemcpy.html | |
new repository
Diffstat (limited to 'devdocs/c/string%2Fwide%2Fwmemcpy.html')
| -rw-r--r-- | devdocs/c/string%2Fwide%2Fwmemcpy.html | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/devdocs/c/string%2Fwide%2Fwmemcpy.html b/devdocs/c/string%2Fwide%2Fwmemcpy.html new file mode 100644 index 00000000..6ab00226 --- /dev/null +++ b/devdocs/c/string%2Fwide%2Fwmemcpy.html @@ -0,0 +1,69 @@ + <h1 id="firstHeading" class="firstHeading">wmemcpy, wmemcpy_s</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><wchar.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl-rev-aux"> <td></td> <td rowspan="3">(1)</td> <td></td> </tr> <tr class="t-dcl t-since-c95 t-until-c99"> <td> <pre data-language="c">wchar_t* wmemcpy( wchar_t* dest, const wchar_t* src, size_t count );</pre> +</td> <td> <span class="t-mark-rev t-since-c95">(since C95)</span> <br><span class="t-mark-rev t-until-c99">(until C99)</span> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">wchar_t *wmemcpy(wchar_t *restrict dest, const wchar_t *restrict src, + size_t count );</pre> +</td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl t-since-c11"> <td> <pre data-language="c">errno_t wmemcpy_s( wchar_t *restrict dest, rsize_t destsz, + const wchar_t *restrict src, rsize_t count );</pre> +</td> <td> (2) </td> <td> <span class="t-mark-rev t-since-c11">(since C11)</span> </td> </tr> </table> <div class="t-li1"> +<span class="t-li">1)</span> Copies exactly <code>count</code> successive wide characters from the wide character array pointed to by <code>src</code> to the wide character array pointed to by <code>dest</code>. If the objects overlap, the behavior is undefined. If <code>count</code> is zero, the function does nothing.</div> <div class="t-li1"> +<span class="t-li">2)</span> Same as <span class="t-v">(1)</span>, except that the following errors are detected at runtime and call the currently installed <a href="../../error/set_constraint_handler_s" title="c/error/set constraint handler s">constraint handler</a> function: <dl> +<dd> +<ul> +<li> <code>src</code> or <code>dest</code> is a null pointer </li> +<li> <code>destsz</code> or <code>count</code> is greater than <code>RSIZE_MAX/sizeof(wchar_t)</code> </li> +<li> <code>count</code> is greater than <code>destsz</code> (overflow would occur) </li> +<li> overlap would occur between the source and the destination arrays </li> +</ul> </dd> +<dd>As with all bounds-checked functions, <code>wmemcpy_s</code> only guaranteed to be available if <code>__STDC_LIB_EXT1__</code> is defined by the implementation and if the user defines <code>__STDC_WANT_LIB_EXT1__</code> to the integer constant <code>1</code> before including <a href="../wide" title="c/string/wide"><code><wchar.h></code></a>.</dd> +</dl> +</div> <h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> dest </td> <td> - </td> <td> pointer to the wide character array to copy to </td> +</tr> <tr class="t-par"> <td> src </td> <td> - </td> <td> pointer to the wide character array to copy from </td> +</tr> <tr class="t-par"> <td> count </td> <td> - </td> <td> number of wide characters to copy </td> +</tr> <tr class="t-par"> <td> destsz </td> <td> - </td> <td> max number of wide characters to write (the size of the destination buffer) </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <div class="t-li1"> +<span class="t-li">1)</span> returns a copy of <code>dest</code> +</div> <div class="t-li1"> +<span class="t-li">2)</span> returns zero on success, returns non-zero on error. Also, on error, fills the entire <code>dst</code> up to and not including <code>dst+dstsz</code> with null wide characters, <code>L'\0'</code> (unless <code>dest</code> is null or <code>destsz</code> is greater than <code>RSIZE_MAX/sizeof(wchar_t)</code>)</div> <h3 id="Notes"> Notes</h3> <p>This function's analog for byte strings is <code><a href="../byte/strncpy" title="c/string/byte/strncpy">strncpy</a></code>, not <code><a href="../byte/strcpy" title="c/string/byte/strcpy">strcpy</a></code>.</p> +<p>This function is not locale-sensitive and pays no attention to the values of the <code>wchar_t</code> objects it copies: nulls as well as invalid characters are copied too.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h> +#include <wchar.h> +#include <locale.h> + +int main(void) +{ + wchar_t from1[] = L"नमस्ते"; + size_t sz1 = sizeof from1 / sizeof *from1; + wchar_t from2[] = L"Բարև"; + size_t sz2 = sizeof from2 / sizeof *from2; + wchar_t to[sz1 + sz2]; + wmemcpy(to, from1, sz1); // copy from1, along with its null terminator + wmemcpy(to + sz1, from2, sz2); // append from2, along with its null terminator + + setlocale(LC_ALL, "en_US.utf8"); + printf("Wide array contains: "); + for(size_t n = 0; n < sizeof to / sizeof *to; ++n) + if(to[n]) + printf("%lc", to[n]); + else + printf("\\0"); + printf("\n"); +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">Wide array contains: नमस्ते\0Բարև\0</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul> +<li> 7.29.4.2.3 The wmemcpy function (p: 431) </li> +<li> K.3.9.2.1.3 The wmemcpy_s function (p: 641) </li> +</ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul><li> 7.24.4.2.3 The wmemcpy function (p: 377) </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="wmemmove" title="c/string/wide/wmemmove"> <span class="t-lines"><span>wmemmove</span><span>wmemmove_s</span></span></a></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c95">(C95)</span></span><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> copies a certain amount of wide characters between two, possibly overlapping, arrays <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="../byte/strncpy" title="c/string/byte/strncpy"> <span class="t-lines"><span>strncpy</span><span>strncpy_s</span></span></a></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> copies a certain amount of characters from one string to another <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/string/wide/wmemcpy" title="cpp/string/wide/wmemcpy">C++ documentation</a></span> for <code>wmemcpy</code> </td> +</tr> </table> <div class="_attribution"> + <p class="_attribution-p"> + © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> + <a href="https://en.cppreference.com/w/c/string/wide/wmemcpy" class="_attribution-link">https://en.cppreference.com/w/c/string/wide/wmemcpy</a> + </p> +</div> |
