errno_t wcsncat_s( wchar_t *restrict dest, rsize_t destsz,
const wchar_t *restrict src, rsize_t count );
1) Appends at most count
wide characters from the wide string pointed to by src
, stopping if the null terminator is copied, to the end of the character string pointed to by dest
. The wide character src[0] replaces the null terminator at the end of dest
. The null terminator is always appended in the end (so the maximum number of wide characters the function may write is count+1).
The behavior is undefined if the destination array is not large enough for the contents of both str
and dest
and the terminating null wide character.
The behavior is undefined if the strings overlap.
2)Same as
(1), except that this function may clobber the remainder of the destination array (from the last wide character written to
destsz
) and that the following errors are detected at runtime and call the currently installed
constraint handlerfunction:
src
or dest
is a null pointerdestsz
or count
is zero or greater than RSIZE_MAX/sizeof(wchar_t)destsz
wide characters of dest
count
or the length of src
, whichever is less, exceeds the space available between the null terminator of dest
and destsz
.wcsncat_s
is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including <wchar.h>.
1) returns a copy of dest
2) returns zero on success, returns non-zero on error. Also, on error, writes L'\0' to dest[0] (unless dest
is a null pointer or destsz
is zero or greater than RSIZE_MAX/sizeof(wchar_t)).
Although truncation to fit the destination buffer is a security risk and therefore a runtime constraints violation for wcsncat_s
, it is possible to get the truncating behavior by specifying count
equal to the size of the destination array minus one: it will copy the first count
wide characters and append the null terminator as always: wcsncat_s(dst, sizeof dst/sizeof *dst, src, (sizeof dst/sizeof *dst)-wcsnlen_s(dst, sizeof dst/sizeof *dst)-1);
#include <wchar.h> #include <stdio.h> #include <locale.h> int main(void) { wchar_t str[50] = L"ÐемлÑ, пÑоÑай."; wcsncat(str, L" ", 1); wcsncat(str, L"РдобÑÑй пÑÑÑ.", 8); // only append the first 8 wide chars setlocale(LC_ALL, "en_US.utf8"); printf("%ls", str); }
Possible output:
ÐемлÑ, пÑоÑай. РдобÑÑй[edit] References
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4