branch update for HEAD-2003021201
[reactos.git] / lib / crtdll / mbstring / mbsncat.c
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS system libraries
4  * FILE:        lib/crtdll/mbstring/mbsset.c 
5  * PURPOSE:     Concatenate two multi byte string to maximum of n characters or bytes
6  * PROGRAMER:   Boudewijn Dekker
7  * UPDATE HISTORY:
8  *              12/04/99: Created
9  */
10
11 #include <msvcrt/mbstring.h>
12 #include <msvcrt/string.h>
13
14 size_t _mbclen2(const unsigned int s);
15
16 unsigned char * _mbsncat(unsigned char *dst, const unsigned char *src, size_t n)
17 {
18         char *d = (char *)dst;
19         char *s = (char *)src;
20         if (n != 0) {
21                 d = dst + strlen(dst); // get the end of string 
22                 d += _mbclen2(*d); // move 1 or 2 up
23
24                 do {
25                         if ((*d++ = *s++) == 0)
26                         {
27                                 while (--n != 0)
28                                         *d++ = 0;
29                                 break;
30                         }
31                         if (!_ismbblead(*s) )
32                                 n--;
33                 } while (n > 0);
34         }
35         return dst;
36 }
37
38 unsigned char * _mbsnbcat(unsigned char *dst, const unsigned char *src, size_t n)
39 {
40         char *d; 
41         char *s = (char *)src;
42         if (n != 0) {
43                 d = dst + strlen(dst); // get the end of string 
44                 d += _mbclen2(*d); // move 1 or 2 up
45
46                 do {
47                         if ((*d++ = *s++) == 0)
48                         {
49                                 while (--n != 0)
50                                         *d++ = 0;
51                                 break;
52                         }
53                         if ( !(n==1 && _ismbblead(*s)) )
54                                 n--;
55                 } while (n > 0);
56         }
57         return dst;
58 }