ReactOS 0.4.16-dev-1099-g3bb27eb
mbscpy_s_l.cpp
Go to the documentation of this file.
1/***
2*mbscpy_s_l.c - Copy one string to another (MBCS)
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* Copy one string to another (MBCS)
8*
9*******************************************************************************/
10#ifndef _MBCS
11 #error This file should only be compiled with _MBCS defined
12#endif
13
16
17errno_t __cdecl _mbscpy_s_l(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, _LOCALE_ARG_DECL)
18{
19 unsigned char *p;
20 size_t available;
21 BOOL fIsLeadPrefix;
22
23 /* validation section */
26
29 {
30 return strcpy_s((char *)_Dst, _SizeInBytes, (const char *)_Src);
31 }
32
33 p = _Dst;
35 while ((*p++ = *_Src++) != 0 && --available > 0)
36 {
37 }
38
39 /*
40 * If we ran out of destination bytes then we did so before copying null.
41 * Only exception to that is if last mbc was invalid (leadbyte+null), which
42 * is treated as null. In that case clear the copied lead byte and return ok.
43 */
44
45 if (available == 0)
46 {
47 if (*_Src == 0) {
48 _ISMBBLEADPREFIX(fIsLeadPrefix,_Dst,p-1);
49 if (fIsLeadPrefix)
50 {
51 p[-1] = 0;
53 }
54 }
57 }
58
59 /*
60 * Otherwise we have space left in the dst buffer and stopped copying because
61 * we saw a null in the src. If null is part of invalid MBC (lead byte + null)
62 * then clear the lead byte also.
63 */
64
65 _ISMBBLEADPREFIX(fIsLeadPrefix, _Dst, p-2);
66 if (fIsLeadPrefix && (p - 2) >= _Dst)
67 {
68 p[-2] = 0;
69 available++;
72 }
73
76}
#define __cdecl
Definition: accygwin.h:79
#define _LOCALE_ARG_DECL
#define _FILL_STRING
#define _ISMBBLEADPREFIX(_Result, _StringStart, _BytePtr)
#define _RETURN_BUFFER_TOO_SMALL(_String, _Size)
#define _LOCALE_SHORTCUT_TEST
#define _RESET_STRING(_String, _Size)
#define _RETURN_NO_ERROR
#define _VALIDATE_POINTER_RESET_STRING(_Pointer, _String, _Size)
#define _LOCALE_UPDATE
#define _RETURN_MBCS_ERROR
#define _VALIDATE_STRING(_String, _Size)
static WCHAR available[MAX_STRING_RESOURCE_LEN]
Definition: object.c:2336
unsigned int BOOL
Definition: ntddk_ex.h:94
GLfloat GLfloat p
Definition: glext.h:8902
errno_t __cdecl _mbscpy_s_l(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, _LOCALE_ARG_DECL)
Definition: mbscpy_s_l.cpp:17
#define strcpy_s(d, l, s)
Definition: utility.h:200
_In_ size_t _SizeInBytes
Definition: time.h:146
int errno_t
Definition: corecrt.h:615