다음을 통해 공유


_mbsnbcpy_s, _mbsnbcpy_s_l

Copies n bytes of a string to a destination string. These are versions of _mbsnbcpy, _mbsnbcpy_l with security enhancements as described in Security Enhancements in the CRT.

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

Parameters

  • strDest
    Destination for character string to be copied.

  • sizeInBytes
    Destination buffer size.

  • strSource
    Character string to be copied.

  • count
    Number of bytes to be copied.

  • locale
    Locale to use.

Return Value

Zero if successful; EINVAL if a bad parameter was passed in.

Remarks

The _mbsnbcpy_s function copies count bytes from strSource to strDest. If count exceeds the size of strDest, either of the input strings is a null pointer, or sizeInBytes or count is 0, the function invokes the invalid parameter handler as described in Parameter Validation . If execution is allowed to continue, the function returns EINVAL. If the source and destination strings overlap, the behavior of _mbstrncpy is undefined.

The output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale for more information. The versions of these functions without the _l suffix use the current locale for this locale-dependent behavior; the versions with the _l suffix are identical except that they use the locale parameter passed in instead. For more information, see Locale.

참고

Unlike the non-secure version of this function, _mbsnbcpy_s does not do any null padding and always null terminates the string.

In C++, using these functions is simplified by template overloads; the overloads can infer buffer length automatically (eliminating the need to specify a size argument) and they can automatically replace older, non-secure functions with their newer, secure counterparts. For more information, see Secure Template Overloads.

The debug versions of these functions first fill the buffer with 0xFD. To disable this behavior, use _CrtSetDebugFillThreshold.

Generic-Text Routine Mappings

Tchar.h routine

_UNICODE and _MBCS not defined

_MBCS defined

_UNICODE defined

_tcsncpy_s

_strncpy_s

_mbsnbcpy_s

_wcsncpy_s

_tcsncpy_s_l

_strncpy_s_l

_mbsnbcpy_s_l

_wcsncpy_s_l

Requirements

Routine

Required header

_mbsnbcpy_s

<mbstring.h>

_mbsnbcpy_s_l

<mbstring.h>

For more compatibility information, see Compatibility in the Introduction.

.NET Framework Equivalent

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

See Also

Concepts

String Manipulation (CRT)

_mbsnbcat, _mbsnbcat_l

_mbsnbcmp, _mbsnbcmp_l

_mbsnbcnt, _mbsnbcnt_l, _mbsnccnt, _mbsnccnt_l, _strncnt, _wcsncnt

_mbsnbicmp, _mbsnbicmp_l

_mbsnbset, _mbsnbset_l

strncpy, _strncpy_l, wcsncpy, _wcsncpy_l, _mbsncpy, _mbsncpy_l