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 } 68