Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222/* * PROJECT: ReactOS CRT library * LICENSE: LGPL - See COPYING in the top level directory * FILE: lib/sdk/crt/string/wcs.c * PURPOSE: wcs* CRT functions * PROGRAMMERS: Wine team * Ported to ReactOS by Aleksey Bragin (aleksey@reactos.org) */
/* * msvcrt.dll wide-char functions * * Copyright 1999 Alexandre Julliard * Copyright 2000 Jon Griffiths * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */#include <precomp.h>#include <assert.h>#include "wine/unicode.h"
/********************************************************************* * _wcsnset (MSVCRT.@) */wchar_t* CDECL _wcsnset( wchar_t* str, wchar_t c, size_t n ){ wchar_t* ret = str; while ((n-- > 0) && *str) *str++ = c; return ret;}
/********************************************************************* * _wcsrev (MSVCRT.@) */wchar_t* CDECL _wcsrev( wchar_t* str ){ wchar_t* ret = str; wchar_t* end = str + strlenW(str) - 1; while (end > str) { wchar_t t = *end; *end-- = *str; *str++ = t; } return ret;}
/********************************************************************* * wcscoll (MSVCRT.@) */int CDECL wcscoll( const wchar_t* str1, const wchar_t* str2 ){ /* FIXME: handle collates */ return strcmpW( str1, str2 );}
/********************************************************************* * wcspbrk (MSVCRT.@) */wchar_t* CDECL wcspbrk( const wchar_t* str, const wchar_t* accept ){ const wchar_t* p; while (*str) { for (p = accept; *p; p++) if (*p == *str) return (wchar_t*)str; str++; } return NULL;}
/********************************************************************* * wcscpy_s (MSVCRT.@) */INT CDECL wcscpy_s( wchar_t* wcDest, size_t numElement, const wchar_t *wcSrc){ size_t size = 0;
if(!wcDest || !numElement) return EINVAL;
wcDest[0] = 0;
if(!wcSrc) { return EINVAL; }
size = strlenW(wcSrc) + 1;
if(size > numElement) { return ERANGE; }
memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
return 0;}
/****************************************************************** * wcsncpy_s (MSVCRT.@) */INT CDECL wcsncpy_s( wchar_t* wcDest, size_t numElement, const wchar_t *wcSrc, size_t count ){ size_t size = 0;
if (!wcDest || !numElement) return EINVAL;
wcDest[0] = 0;
if (!wcSrc) { return EINVAL; }
size = min(strlenW(wcSrc), count);
if (size >= numElement) { return ERANGE; }
memcpy( wcDest, wcSrc, size*sizeof(WCHAR) ); wcDest[size] = '\0';
return 0;}
/****************************************************************** * wcscat_s (MSVCRT.@) * */INT CDECL wcscat_s(wchar_t* dst, size_t elem, const wchar_t* src){ wchar_t* ptr = dst;
if (!dst || elem == 0) return EINVAL; if (!src) { dst[0] = '\0'; return EINVAL; }
/* seek to end of dst string (or elem if no end of string is found */ while (ptr < dst + elem && *ptr != '\0') ptr++; while (ptr < dst + elem) { if ((*ptr++ = *src++) == '\0') return 0; } /* not enough space */ dst[0] = '\0'; return ERANGE;}
/********************************************************************* * wcsncat_s (MSVCRT.@) * */INT CDECL wcsncat_s(wchar_t *dst, size_t elem, const wchar_t *src, size_t count){ size_t srclen; wchar_t dststart; INT ret = 0;
if (!MSVCRT_CHECK_PMT(dst != NULL) || !MSVCRT_CHECK_PMT(elem > 0)) { return EINVAL; } if (!MSVCRT_CHECK_PMT(src != NULL || count == 0)) return EINVAL; if (count == 0) return 0;
for (dststart = 0; dststart < elem; dststart++) { if (dst[dststart] == '\0') break; } if (dststart == elem) { MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", EINVAL); return EINVAL; }
if (count == _TRUNCATE) { srclen = strlenW(src); if (srclen >= (elem - dststart)) { srclen = elem - dststart - 1; ret = STRUNCATE; } } else srclen = min(strlenW(src), count); if (srclen < (elem - dststart)) { memcpy(&dst[dststart], src, srclen*sizeof(wchar_t)); dst[dststart+srclen] = '\0'; return ret; } MSVCRT_INVALID_PMT("dst[elem] is too small", ERANGE); dst[0] = '\0'; return ERANGE;}