Share via


_mbsnbcpy, _mbsnbcpy_l

Copies n bytes of a string to a destination string. More secure versions of these functions are available—see _mbsnbcpy_s, _mbsnbcpy_s_l.

Important

This API cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported with /ZW.

unsigned char * _mbsnbcpy(
   unsigned char * strDest,
   const unsigned char * strSource,
   size_t count
);
unsigned char * _mbsnbcpy_l(
   unsigned char * strDest,
   const unsigned char * strSource,
   size_t count,
   _locale_t locale
);
template <size_t size>
unsigned char * _mbsnbcpy(
   unsigned char (&strDest)[size],
   const unsigned char * strSource,
   size_t count
); // C++ only
template <size_t size>
unsigned char * _mbsnbcpy_l(
   unsigned char (&strDest)[size],
   const unsigned char * strSource,
   size_t count,
   _locale_t locale
); // C++ only

Parameters

  • strDest
    Destination for the character string to be copied.

  • strSource
    Character string to be copied.

  • count
    Number of bytes to be copied.

  • locale
    Locale to use.

Return Value

_mbsnbcpy returns a pointer to the destination character string. No return value is reserved to indicate an error.

Remarks

The _mbsnbcpy function copies count bytes from strSource to strDest. If count exceeds the size of strDest or the source and destination strings overlap, the behavior of _mbsnbcpy is undefined.

If strSource or strDest is a null pointer, this function invokes the invalid parameter handler as described in Parameter Validation. If execution is allowed to continue, the function returns NULL and sets errno to EINVAL.

The output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale, _wsetlocale for more information. The versions of these functions are identical, except that those that don't have the _l suffix use the current locale and the versions that do have the _l suffix instead use the locale parameter that's passed in. For more information, see Locale.

Security noteSecurity Note

These functions might be vulnerable to buffer overrun threats. Buffer overruns can be used to execute arbitrary attacker code, which can cause an unwarranted elevation of privilege and compromise the system. For more information, see Avoiding Buffer Overruns.

In C++, these functions have template overloads that invoke the newer, more secure counterparts of these functions. For more information, see Secure Template Overloads.

Generic-Text Routine Mappings

Tchar.h routine

_UNICODE and _MBCS not defined

_MBCS defined

_UNICODE defined

_tcsncpy

strncpy

_mbsnbcpy

wcsncpy

_tcsncpy_l

_strncpy_l

_mbsnbcp_l

_wcsncpy_l

Requirements

Routine

Required header

_mbsnbcpy

<mbstring.h>

_mbsnbcpy_l

<mbstring.h>

For more compatibility information, see Compatibility.

.NET Framework Equivalent

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

See Also

Reference

String Manipulation (CRT)

_mbsnbcat, _mbsnbcat_l

_mbsnbcmp, _mbsnbcmp_l

_strncnt, _wcsncnt, _mbsnbcnt, _mbsnbcnt_l, _mbsnccnt, _mbsnccnt_l

_mbsnbset, _mbsnbset_l

strncpy, _strncpy_l, wcsncpy, _wcsncpy_l, _mbsncpy, _mbsncpy_l