ReactOS 0.4.16-dev-927-g467dec4
mbsnbcat.cpp File Reference
#include <corecrt_internal.h>
#include <corecrt_internal_mbstring.h>
#include <locale.h>
#include <string.h>
Include dependency graph for mbsnbcat.cpp:

Go to the source code of this file.

Functions

unsigned char *__cdecl _mbsnbcat_l (unsigned char *dst, const unsigned char *src, size_t cnt, _locale_t plocinfo)
 
unsigned char *__cdecl _mbsnbcat (unsigned char *dst, const unsigned char *src, size_t cnt)
 

Function Documentation

◆ _mbsnbcat()

unsigned char *__cdecl _mbsnbcat ( unsigned char dst,
const unsigned char src,
size_t  cnt 
)

Definition at line 107 of file mbsnbcat.cpp.

112{
114 return _mbsnbcat_l(dst, src, cnt, nullptr);
116}
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
#define _BEGIN_SECURE_CRT_DEPRECATION_DISABLE
#define _END_SECURE_CRT_DEPRECATION_DISABLE
unsigned char *__cdecl _mbsnbcat_l(unsigned char *dst, const unsigned char *src, size_t cnt, _locale_t plocinfo)
Definition: mbsnbcat.cpp:40
_In_ size_t cnt
Definition: wcstombs.cpp:43

◆ _mbsnbcat_l()

unsigned char *__cdecl _mbsnbcat_l ( unsigned char dst,
const unsigned char src,
size_t  cnt,
_locale_t  plocinfo 
)

Definition at line 40 of file mbsnbcat.cpp.

46{
47 unsigned char *start;
48
49 if (!cnt)
50 return(dst);
51
52 /* validation section */
53 _VALIDATE_RETURN(dst != nullptr, EINVAL, nullptr);
54 _VALIDATE_RETURN(src != nullptr, EINVAL, nullptr);
55
56 _LocaleUpdate _loc_update(plocinfo);
57
59 if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0)
60 return (unsigned char *)strncat((char *)dst, (const char *)src, cnt);
62
63 start = dst;
64 while (*dst++)
65 ;
66 --dst; // dst now points to end of dst string
67
68 /* if last char in string is a lead byte, back up pointer */
69 if ( dst!=start && _mbsbtype_l(start, (int) ((dst - start) - 1), _loc_update.GetLocaleT()) == _MBC_LEAD )
70 {
71 --dst;
72 }
73
74 /* copy over the characters */
75
76 while (cnt--) {
77
78 if ( _ismbblead_l(*src, _loc_update.GetLocaleT()) ) {
79 *dst++ = *src++;
80 if (cnt == 0) { /* write null if cnt exhausted */
81 dst[-1] = '\0';
82 break;
83 }
84 cnt--;
85 if ((*dst++ = *src++)=='\0') { /* or if no trail byte */
86 dst[-2] = '\0';
87 break;
88 }
89 }
90 else if ((*dst++ = *src++) == '\0')
91 break;
92
93 }
94
95 if ( dst!=start && _mbsbtype_l(start, (int) ((dst - start) - 1), _loc_update.GetLocaleT()) == _MBC_LEAD )
96 {
97 dst[-1] = '\0';
98 }
99 else
100 {
101 *dst = '\0';
102 }
103
104 return(start);
105}
#define EINVAL
Definition: acclib.h:90
#define _ismbblead_l(_c, p)
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
GLuint start
Definition: gl.h:1545
_CRTIMP int __cdecl _mbsbtype_l(_In_reads_bytes_(_Pos) _Pre_z_ const unsigned char *_Str, _In_ size_t _Pos, _In_opt_ _locale_t _Locale)
_locale_t plocinfo
Definition: ismbbyte.cpp:75
#define _MBC_LEAD
Definition: msvcrt.h:824
_In_opt_ _Locale strncat
Definition: string.h:263

Referenced by _mbsnbcat().