ReactOS  0.4.15-dev-985-gd905dd5
mbsncat.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS system libraries
4  * FILE: lib/sdk/crt/mbstring/mbsncat.c
5  * PURPOSE: Concatenate two multi byte string to maximum of n characters or bytes
6  * PROGRAMER: Ariadne
7  * UPDATE HISTORY:
8  * 12/04/99: Created
9  */
10 
11 #include <precomp.h>
12 #include <mbstring.h>
13 #include <string.h>
14 
15 size_t _mbclen2(const unsigned int s);
16 unsigned char *_mbset (unsigned char *string, int c);
17 
18 /*
19  * @implemented
20  */
21 unsigned char *_mbsncat (unsigned char *dst, const unsigned char *src, size_t n)
22 {
23  int c;
24  unsigned char *save = dst;
25 
26  while ((c = _mbsnextc (dst)))
27  dst = _mbsinc (dst);
28 
29  while (n-- > 0 && (c = _mbsnextc (src))) {
30 
31  _mbset (dst, c);
32 
33  dst = _mbsinc (dst);
34 
35  src = _mbsinc ((unsigned char *) src);
36 
37  }
38 
39  *dst = '\0';
40 
41  return save;
42 }
43 
44 /*
45  * @implemented
46  */
47 unsigned char * _mbsnbcat(unsigned char *dst, const unsigned char *src, size_t n)
48 {
49  unsigned char *d;
50  const unsigned char *s = src;
51  if (n != 0) {
52  d = dst + _mbslen(dst); // get the end of string
53  d += _mbclen2(*d); // move 1 or 2 up
54 
55  do {
56  if ((*d++ = *s++) == 0)
57  {
58  while (--n != 0)
59  *d++ = 0;
60  break;
61  }
62  if ( !(n==1 && _ismbblead(*s)) )
63  n--;
64  } while (n > 0);
65  }
66  return dst;
67 }
unsigned char * _mbsncat(unsigned char *dst, const unsigned char *src, size_t n)
Definition: mbsncat.c:21
_Check_return_ _CRTIMP size_t __cdecl _mbslen(_In_z_ const unsigned char *_Str)
GLdouble n
Definition: glext.h:7729
#define d
Definition: ke_i.h:81
const GLubyte * c
Definition: glext.h:8905
_Check_return_ _CRTIMP unsigned char *__cdecl _mbsinc(_In_z_ const unsigned char *_Ptr)
_Check_return_ _CRTIMP unsigned int __cdecl _mbsnextc(_In_z_ const unsigned char *_Str)
GLdouble s
Definition: gl.h:2039
GLenum src
Definition: glext.h:6340
unsigned char * _mbsnbcat(unsigned char *dst, const unsigned char *src, size_t n)
Definition: mbsncat.c:47
GLenum GLenum dst
Definition: glext.h:6340
int __cdecl _ismbblead(unsigned int)
Definition: ismblead.c:20
size_t _mbclen2(const unsigned int s)
Definition: mbclen.c:23
#define c
Definition: ke_i.h:80
unsigned char * _mbset(unsigned char *string, int c)
Definition: mbsupr.c:31