2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll wide-char functions
|
|
|
|
*
|
|
|
|
* Copyright 1999 Alexandre Julliard
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2010-04-26 12:33:38 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2001-01-22 03:21:54 +01:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
2004-04-08 21:48:19 +02:00
|
|
|
#include <math.h>
|
2005-02-14 21:53:42 +01:00
|
|
|
#include <assert.h>
|
2001-01-11 00:59:25 +01:00
|
|
|
#include "msvcrt.h"
|
|
|
|
#include "winnls.h"
|
2011-04-20 14:42:16 +02:00
|
|
|
#include "wtypes.h"
|
2001-01-11 00:59:25 +01:00
|
|
|
#include "wine/unicode.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2011-04-27 20:09:00 +02:00
|
|
|
static BOOL n_format_enabled = TRUE;
|
|
|
|
|
2011-04-20 14:42:16 +02:00
|
|
|
#include "printf.h"
|
|
|
|
#define PRINTF_WIDE
|
|
|
|
#include "printf.h"
|
|
|
|
#undef PRINTF_WIDE
|
2001-01-22 03:21:54 +01:00
|
|
|
|
2011-04-27 20:09:00 +02:00
|
|
|
/* _get_printf_count_output - not exported in native msvcrt */
|
2011-06-03 15:28:32 +02:00
|
|
|
int CDECL MSVCRT__get_printf_count_output( void )
|
2011-04-27 20:09:00 +02:00
|
|
|
{
|
|
|
|
return n_format_enabled ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _set_printf_count_output - not exported in native msvcrt */
|
2011-06-03 15:28:32 +02:00
|
|
|
int CDECL MSVCRT__set_printf_count_output( int enable )
|
2011-04-27 20:09:00 +02:00
|
|
|
{
|
|
|
|
BOOL old = n_format_enabled;
|
2012-08-08 21:25:57 +02:00
|
|
|
n_format_enabled = enable != 0;
|
2011-04-27 20:09:00 +02:00
|
|
|
return old ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _wcsdup (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
MSVCRT_wchar_t* CDECL MSVCRT__wcsdup( const MSVCRT_wchar_t* str )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t* ret = NULL;
|
2001-01-11 00:59:25 +01:00
|
|
|
if (str)
|
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
int size = (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t);
|
2001-01-11 00:59:25 +01:00
|
|
|
ret = MSVCRT_malloc( size );
|
|
|
|
if (ret) memcpy( ret, str, size );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-25 16:14:23 +02:00
|
|
|
INT CDECL MSVCRT__wcsicmp_l(const MSVCRT_wchar_t *str1, const MSVCRT_wchar_t *str2, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
if(!MSVCRT_CHECK_PMT(str1 != NULL) || !MSVCRT_CHECK_PMT(str2 != NULL))
|
|
|
|
return MSVCRT__NLSCMPERROR;
|
|
|
|
|
|
|
|
return strcmpiW(str1, str2);
|
|
|
|
}
|
|
|
|
|
2013-03-27 16:11:06 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcsicmp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
INT CDECL MSVCRT__wcsicmp( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
|
|
|
|
{
|
|
|
|
return strcmpiW( str1, str2 );
|
|
|
|
}
|
|
|
|
|
2013-09-12 12:50:19 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcsnicmp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
INT CDECL MSVCRT__wcsnicmp(const MSVCRT_wchar_t *str1, const MSVCRT_wchar_t *str2, INT n)
|
|
|
|
{
|
|
|
|
return strncmpiW(str1, str2, n);
|
|
|
|
}
|
|
|
|
|
2013-03-30 15:59:02 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcsicoll_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__wcsicoll_l(const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
|
|
|
|
|
|
|
return CompareStringW(locinfo->lc_handle[MSVCRT_LC_COLLATE], NORM_IGNORECASE,
|
|
|
|
str1, -1, str2, -1)-CSTR_EQUAL;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _wcsicoll (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
INT CDECL MSVCRT__wcsicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2013-03-30 15:59:02 +01:00
|
|
|
return MSVCRT__wcsicoll_l(str1, str2, NULL);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2013-03-30 17:00:30 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcsnicoll_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__wcsnicoll_l(const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2,
|
|
|
|
MSVCRT_size_t count, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
|
|
|
|
|
|
|
return CompareStringW(locinfo->lc_handle[MSVCRT_LC_COLLATE], NORM_IGNORECASE,
|
|
|
|
str1, count, str2, count)-CSTR_EQUAL;
|
|
|
|
}
|
|
|
|
|
2010-12-03 18:12:23 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcsnicoll (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
INT CDECL MSVCRT__wcsnicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2, MSVCRT_size_t count )
|
2010-12-03 18:12:23 +01:00
|
|
|
{
|
2013-03-30 17:00:30 +01:00
|
|
|
return MSVCRT__wcsnicoll_l(str1, str2, count, NULL);
|
2010-12-03 18:12:23 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _wcsnset (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2010-03-29 00:00:26 +02:00
|
|
|
MSVCRT_wchar_t* CDECL MSVCRT__wcsnset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c, MSVCRT_size_t n )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t* ret = str;
|
2001-01-11 00:59:25 +01:00
|
|
|
while ((n-- > 0) && *str) *str++ = c;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _wcsrev (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
MSVCRT_wchar_t* CDECL MSVCRT__wcsrev( MSVCRT_wchar_t* str )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t* ret = str;
|
|
|
|
MSVCRT_wchar_t* end = str + strlenW(str) - 1;
|
2001-01-11 00:59:25 +01:00
|
|
|
while (end > str)
|
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t t = *end;
|
2001-01-11 00:59:25 +01:00
|
|
|
*end-- = *str;
|
|
|
|
*str++ = t;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _wcsset (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
MSVCRT_wchar_t* CDECL MSVCRT__wcsset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t* ret = str;
|
2001-01-11 00:59:25 +01:00
|
|
|
while (*str) *str++ = c;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-11-16 02:09:17 +01:00
|
|
|
/******************************************************************
|
2011-03-05 00:28:28 +01:00
|
|
|
* _wcsupr_s_l (MSVCRT.@)
|
2009-11-16 02:09:17 +01:00
|
|
|
*/
|
2011-03-05 00:28:28 +01:00
|
|
|
int CDECL MSVCRT__wcsupr_s_l( MSVCRT_wchar_t* str, MSVCRT_size_t n,
|
|
|
|
MSVCRT__locale_t locale )
|
2009-11-16 02:09:17 +01:00
|
|
|
{
|
|
|
|
MSVCRT_wchar_t* ptr = str;
|
|
|
|
|
|
|
|
if (!str || !n)
|
|
|
|
{
|
|
|
|
if (str) *str = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (n--)
|
|
|
|
{
|
|
|
|
if (!*ptr) return 0;
|
2011-03-05 00:28:28 +01:00
|
|
|
/* FIXME: add locale support */
|
2009-11-16 02:09:17 +01:00
|
|
|
*ptr = toupperW(*ptr);
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MSDN claims that the function should return and set errno to
|
|
|
|
* ERANGE, which doesn't seem to be true based on the tests. */
|
|
|
|
*str = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-03-05 00:28:28 +01:00
|
|
|
/******************************************************************
|
|
|
|
* _wcsupr_s (MSVCRT.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
INT CDECL MSVCRT__wcsupr_s( MSVCRT_wchar_t* str, MSVCRT_size_t n )
|
|
|
|
{
|
|
|
|
return MSVCRT__wcsupr_s_l( str, n, NULL );
|
|
|
|
}
|
|
|
|
|
2011-03-04 23:59:08 +01:00
|
|
|
/******************************************************************
|
|
|
|
* _wcslwr_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__wcslwr_s( MSVCRT_wchar_t* str, MSVCRT_size_t n )
|
|
|
|
{
|
|
|
|
MSVCRT_wchar_t* ptr = str;
|
|
|
|
|
|
|
|
if (!str || !n)
|
|
|
|
{
|
|
|
|
if (str) *str = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (n--)
|
|
|
|
{
|
|
|
|
if (!*ptr) return 0;
|
|
|
|
*ptr = tolowerW(*ptr);
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MSDN claims that the function should return and set errno to
|
|
|
|
* ERANGE, which doesn't seem to be true based on the tests. */
|
|
|
|
*str = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-03-29 10:12:53 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcsncoll_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__wcsncoll_l(const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2,
|
|
|
|
MSVCRT_size_t count, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
|
|
|
|
|
|
|
return CompareStringW(locinfo->lc_handle[MSVCRT_LC_COLLATE], 0, str1, count, str2, count)-CSTR_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wcsncoll (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__wcsncoll(const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2, MSVCRT_size_t count)
|
|
|
|
{
|
|
|
|
return MSVCRT__wcsncoll_l(str1, str2, count, NULL);
|
|
|
|
}
|
|
|
|
|
2010-04-26 12:33:38 +02:00
|
|
|
/*********************************************************************
|
2013-03-28 12:56:38 +01:00
|
|
|
* _wcstod_l (MSVCRT.@)
|
2010-04-26 12:33:38 +02:00
|
|
|
*/
|
|
|
|
double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end,
|
|
|
|
MSVCRT__locale_t locale)
|
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
2010-04-26 12:33:38 +02:00
|
|
|
unsigned __int64 d=0, hlp;
|
2010-05-09 15:07:33 +02:00
|
|
|
unsigned fpcontrol;
|
2010-04-26 12:33:38 +02:00
|
|
|
int exp=0, sign=1;
|
|
|
|
const MSVCRT_wchar_t *p;
|
|
|
|
double ret;
|
2012-11-06 10:33:40 +01:00
|
|
|
long double lret=1, expcnt = 10;
|
|
|
|
BOOL found_digit = FALSE, negexp;
|
2010-04-26 12:33:38 +02:00
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) return 0;
|
2010-04-26 12:33:38 +02:00
|
|
|
|
|
|
|
if(!locale)
|
2011-05-24 17:22:32 +02:00
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
2010-04-26 12:33:38 +02:00
|
|
|
|
|
|
|
p = str;
|
|
|
|
while(isspaceW(*p))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
if(*p == '-') {
|
|
|
|
sign = -1;
|
|
|
|
p++;
|
|
|
|
} else if(*p == '+')
|
|
|
|
p++;
|
|
|
|
|
|
|
|
while(isdigitW(*p)) {
|
2010-07-22 12:35:08 +02:00
|
|
|
found_digit = TRUE;
|
2010-04-26 12:33:38 +02:00
|
|
|
hlp = d*10+*(p++)-'0';
|
|
|
|
if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
|
|
|
|
exp++;
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
d = hlp;
|
|
|
|
}
|
|
|
|
while(isdigitW(*p)) {
|
|
|
|
exp++;
|
|
|
|
p++;
|
|
|
|
}
|
2011-05-24 17:22:32 +02:00
|
|
|
if(*p == *locinfo->lconv->decimal_point)
|
2010-04-26 12:33:38 +02:00
|
|
|
p++;
|
|
|
|
|
|
|
|
while(isdigitW(*p)) {
|
2010-07-22 12:35:08 +02:00
|
|
|
found_digit = TRUE;
|
2010-04-26 12:33:38 +02:00
|
|
|
hlp = d*10+*(p++)-'0';
|
|
|
|
if(d>MSVCRT_UI64_MAX/10 || hlp<d)
|
|
|
|
break;
|
|
|
|
|
|
|
|
d = hlp;
|
|
|
|
exp--;
|
|
|
|
}
|
|
|
|
while(isdigitW(*p))
|
|
|
|
p++;
|
|
|
|
|
2010-07-22 12:35:08 +02:00
|
|
|
if(!found_digit) {
|
2010-04-26 12:33:38 +02:00
|
|
|
if(end)
|
|
|
|
*end = (MSVCRT_wchar_t*)str;
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*p=='e' || *p=='E' || *p=='d' || *p=='D') {
|
|
|
|
int e=0, s=1;
|
|
|
|
|
|
|
|
p++;
|
|
|
|
if(*p == '-') {
|
|
|
|
s = -1;
|
|
|
|
p++;
|
|
|
|
} else if(*p == '+')
|
|
|
|
p++;
|
|
|
|
|
|
|
|
if(isdigitW(*p)) {
|
|
|
|
while(isdigitW(*p)) {
|
|
|
|
if(e>INT_MAX/10 || (e=e*10+*p-'0')<0)
|
|
|
|
e = INT_MAX;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
e *= s;
|
|
|
|
|
|
|
|
if(exp<0 && e<0 && exp+e>=0) exp = INT_MIN;
|
|
|
|
else if(exp>0 && e>0 && exp+e<0) exp = INT_MAX;
|
|
|
|
else exp += e;
|
|
|
|
} else {
|
|
|
|
if(*p=='-' || *p=='+')
|
|
|
|
p--;
|
|
|
|
p--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-09 15:07:33 +02:00
|
|
|
fpcontrol = _control87(0, 0);
|
|
|
|
_control87(MSVCRT__EM_DENORMAL|MSVCRT__EM_INVALID|MSVCRT__EM_ZERODIVIDE
|
|
|
|
|MSVCRT__EM_OVERFLOW|MSVCRT__EM_UNDERFLOW|MSVCRT__EM_INEXACT, 0xffffffff);
|
|
|
|
|
2012-11-06 10:33:40 +01:00
|
|
|
negexp = (exp < 0);
|
|
|
|
if(negexp)
|
|
|
|
exp = -exp;
|
|
|
|
while(exp) {
|
|
|
|
if(exp & 1)
|
|
|
|
lret *= expcnt;
|
|
|
|
exp /= 2;
|
|
|
|
expcnt = expcnt*expcnt;
|
|
|
|
}
|
|
|
|
ret = (long double)sign * (negexp ? d/lret : d*lret);
|
2010-04-26 12:33:38 +02:00
|
|
|
|
2010-05-09 15:07:33 +02:00
|
|
|
_control87(fpcontrol, 0xffffffff);
|
|
|
|
|
2010-04-26 12:33:38 +02:00
|
|
|
if((d && ret==0.0) || isinf(ret))
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
|
|
|
|
if(end)
|
|
|
|
*end = (MSVCRT_wchar_t*)p;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:42:46 +02:00
|
|
|
/*********************************************************************
|
2011-04-27 20:08:41 +02:00
|
|
|
* wcsrtombs_l (INTERNAL)
|
2010-04-27 08:42:46 +02:00
|
|
|
*/
|
2011-04-27 20:08:41 +02:00
|
|
|
static MSVCRT_size_t CDECL MSVCRT_wcsrtombs_l(char *mbstr, const MSVCRT_wchar_t **wcstr,
|
2010-04-27 08:42:46 +02:00
|
|
|
MSVCRT_size_t count, MSVCRT__locale_t locale)
|
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
2010-05-24 10:03:55 +02:00
|
|
|
MSVCRT_size_t tmp = 0;
|
2010-05-06 14:27:57 +02:00
|
|
|
BOOL used_default;
|
2010-04-27 08:42:46 +02:00
|
|
|
|
|
|
|
if(!locale)
|
2011-05-24 17:22:32 +02:00
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
2010-04-27 08:42:46 +02:00
|
|
|
|
2011-07-28 12:28:38 +02:00
|
|
|
if(!mbstr) {
|
|
|
|
tmp = WideCharToMultiByte(locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS,
|
|
|
|
*wcstr, -1, NULL, 0, NULL, &used_default)-1;
|
|
|
|
if(used_default)
|
|
|
|
return -1;
|
|
|
|
return tmp;
|
|
|
|
}
|
2010-04-27 08:42:46 +02:00
|
|
|
|
2011-04-27 20:08:41 +02:00
|
|
|
while(**wcstr) {
|
2010-05-24 10:03:55 +02:00
|
|
|
char buf[3];
|
|
|
|
MSVCRT_size_t i, size;
|
2010-04-27 08:42:46 +02:00
|
|
|
|
2011-05-24 17:22:32 +02:00
|
|
|
size = WideCharToMultiByte(locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS,
|
2011-07-28 12:28:38 +02:00
|
|
|
*wcstr, 1, buf, 3, NULL, &used_default);
|
2010-05-24 10:03:55 +02:00
|
|
|
if(used_default)
|
|
|
|
return -1;
|
|
|
|
if(tmp+size > count)
|
|
|
|
return tmp;
|
2010-04-27 08:42:46 +02:00
|
|
|
|
2010-05-24 10:03:55 +02:00
|
|
|
for(i=0; i<size; i++)
|
|
|
|
mbstr[tmp++] = buf[i];
|
2011-04-27 20:08:41 +02:00
|
|
|
(*wcstr)++;
|
2010-05-24 10:03:55 +02:00
|
|
|
}
|
2010-05-06 14:27:57 +02:00
|
|
|
|
2011-04-27 20:08:41 +02:00
|
|
|
if(tmp < count) {
|
2010-05-24 10:03:55 +02:00
|
|
|
mbstr[tmp] = '\0';
|
2011-04-27 20:08:41 +02:00
|
|
|
*wcstr = NULL;
|
|
|
|
}
|
2010-05-06 14:27:57 +02:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2011-04-27 20:08:41 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcstombs_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT__wcstombs_l(char *mbstr, const MSVCRT_wchar_t *wcstr,
|
|
|
|
MSVCRT_size_t count, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return MSVCRT_wcsrtombs_l(mbstr, &wcstr, count, locale);
|
|
|
|
}
|
|
|
|
|
2010-05-06 14:27:57 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* wcstombs (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT_wcstombs(char *mbstr, const MSVCRT_wchar_t *wcstr,
|
|
|
|
MSVCRT_size_t count)
|
|
|
|
{
|
2011-04-27 20:08:41 +02:00
|
|
|
return MSVCRT_wcsrtombs_l(mbstr, &wcstr, count, NULL);
|
2010-05-06 14:27:57 +02:00
|
|
|
}
|
2010-04-27 08:42:46 +02:00
|
|
|
|
2010-05-06 14:27:57 +02:00
|
|
|
/*********************************************************************
|
2011-04-27 20:08:41 +02:00
|
|
|
* wcsrtombs (MSVCRT.@)
|
2010-05-06 14:27:57 +02:00
|
|
|
*/
|
2011-04-27 20:08:41 +02:00
|
|
|
MSVCRT_size_t CDECL MSVCRT_wcsrtombs(char *mbstr, const MSVCRT_wchar_t **wcstr,
|
|
|
|
MSVCRT_size_t count, MSVCRT_mbstate_t *mbstate)
|
|
|
|
{
|
|
|
|
if(mbstate)
|
|
|
|
*mbstate = 0;
|
|
|
|
|
|
|
|
return MSVCRT_wcsrtombs_l(mbstr, wcstr, count, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_wcsrtombs_s_l (INTERNAL)
|
|
|
|
*/
|
2011-05-16 16:23:01 +02:00
|
|
|
static int MSVCRT_wcsrtombs_s_l(MSVCRT_size_t *ret, char *mbstr,
|
2011-04-27 20:08:41 +02:00
|
|
|
MSVCRT_size_t size, const MSVCRT_wchar_t **wcstr,
|
2010-05-06 14:27:57 +02:00
|
|
|
MSVCRT_size_t count, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t conv;
|
|
|
|
|
2011-04-27 20:08:41 +02:00
|
|
|
if(!mbstr && !size && wcstr) {
|
|
|
|
conv = MSVCRT_wcsrtombs_l(NULL, wcstr, 0, locale);
|
2010-05-06 14:27:57 +02:00
|
|
|
if(ret)
|
2011-03-30 15:45:04 +02:00
|
|
|
*ret = conv+1;
|
2010-05-06 14:27:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2010-04-27 08:42:46 +02:00
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(mbstr != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (size) mbstr[0] = '\0';
|
|
|
|
if (!MSVCRT_CHECK_PMT(wcstr != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(*wcstr != NULL)) return MSVCRT_EINVAL;
|
2010-04-27 08:42:46 +02:00
|
|
|
|
2010-06-06 17:11:09 +02:00
|
|
|
if(count==MSVCRT__TRUNCATE || size<count)
|
2010-05-06 14:27:57 +02:00
|
|
|
conv = size;
|
|
|
|
else
|
|
|
|
conv = count;
|
|
|
|
|
2011-04-27 20:08:41 +02:00
|
|
|
conv = MSVCRT_wcsrtombs_l(mbstr, wcstr, conv, locale);
|
2010-05-06 14:27:57 +02:00
|
|
|
if(conv<size)
|
|
|
|
mbstr[conv++] = '\0';
|
2010-06-06 17:11:09 +02:00
|
|
|
else if(conv==size && (count==MSVCRT__TRUNCATE || mbstr[conv-1]=='\0'))
|
2010-05-06 14:27:57 +02:00
|
|
|
mbstr[conv-1] = '\0';
|
|
|
|
else {
|
2012-07-26 11:05:32 +02:00
|
|
|
MSVCRT_INVALID_PMT("mbstr[size] is too small", MSVCRT_ERANGE);
|
2010-05-06 14:27:57 +02:00
|
|
|
if(size)
|
|
|
|
mbstr[0] = '\0';
|
2010-04-27 08:42:46 +02:00
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
2010-05-06 14:27:57 +02:00
|
|
|
if(ret)
|
|
|
|
*ret = conv;
|
2010-04-27 08:42:46 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-04-27 20:08:41 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcstombs_s_l (MSVCRT.@)
|
|
|
|
*/
|
2011-05-16 16:23:01 +02:00
|
|
|
int CDECL MSVCRT__wcstombs_s_l(MSVCRT_size_t *ret, char *mbstr,
|
2011-04-27 20:08:41 +02:00
|
|
|
MSVCRT_size_t size, const MSVCRT_wchar_t *wcstr,
|
|
|
|
MSVCRT_size_t count, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return MSVCRT_wcsrtombs_s_l(ret, mbstr, size, &wcstr,count, locale);
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:42:46 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* wcstombs_s (MSVCRT.@)
|
|
|
|
*/
|
2011-05-16 16:23:01 +02:00
|
|
|
int CDECL MSVCRT_wcstombs_s(MSVCRT_size_t *ret, char *mbstr,
|
2010-04-27 08:42:46 +02:00
|
|
|
MSVCRT_size_t size, const MSVCRT_wchar_t *wcstr, MSVCRT_size_t count)
|
|
|
|
{
|
2011-04-27 20:08:41 +02:00
|
|
|
return MSVCRT_wcsrtombs_s_l(ret, mbstr, size, &wcstr, count, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* wcsrtombs_s (MSVCRT.@)
|
|
|
|
*/
|
2011-05-16 16:23:01 +02:00
|
|
|
int CDECL MSVCRT_wcsrtombs_s(MSVCRT_size_t *ret, char *mbstr, MSVCRT_size_t size,
|
2011-04-27 20:08:41 +02:00
|
|
|
const MSVCRT_wchar_t **wcstr, MSVCRT_size_t count, MSVCRT_mbstate_t *mbstate)
|
|
|
|
{
|
|
|
|
if(mbstate)
|
|
|
|
*mbstate = 0;
|
|
|
|
|
|
|
|
return MSVCRT_wcsrtombs_s_l(ret, mbstr, size, wcstr, count, NULL);
|
2010-04-27 08:42:46 +02:00
|
|
|
}
|
|
|
|
|
2003-09-24 00:50:30 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* wcstod (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_wcstod(const MSVCRT_wchar_t* lpszStr, MSVCRT_wchar_t** end)
|
2003-09-24 00:50:30 +02:00
|
|
|
{
|
2010-04-26 12:33:49 +02:00
|
|
|
return MSVCRT__wcstod_l(lpszStr, end, NULL);
|
|
|
|
}
|
2003-09-24 00:50:30 +02:00
|
|
|
|
2010-04-26 12:33:49 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wtof (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCRT__wtof(const MSVCRT_wchar_t *str)
|
|
|
|
{
|
|
|
|
return MSVCRT__wcstod_l(str, NULL, NULL);
|
2003-09-24 00:50:30 +02:00
|
|
|
}
|
|
|
|
|
2010-04-26 12:33:49 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wtof_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCRT__wtof_l(const MSVCRT_wchar_t *str, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return MSVCRT__wcstod_l(str, NULL, locale);
|
|
|
|
}
|
2005-02-14 21:53:42 +01:00
|
|
|
|
2011-04-20 14:42:26 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* arg_clbk_valist (INTERNAL)
|
|
|
|
*/
|
|
|
|
printf_arg arg_clbk_valist(void *ctx, int arg_pos, int type, __ms_va_list *valist)
|
|
|
|
{
|
|
|
|
printf_arg ret;
|
|
|
|
|
|
|
|
if(type == VT_I8)
|
|
|
|
ret.get_longlong = va_arg(*valist, LONGLONG);
|
|
|
|
else if(type == VT_INT)
|
|
|
|
ret.get_int = va_arg(*valist, int);
|
|
|
|
else if(type == VT_R8)
|
|
|
|
ret.get_double = va_arg(*valist, double);
|
|
|
|
else if(type == VT_PTR)
|
|
|
|
ret.get_ptr = va_arg(*valist, void*);
|
|
|
|
else {
|
|
|
|
ERR("Incorrect type\n");
|
|
|
|
ret.get_int = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-27 12:09:01 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* arg_clbk_positional (INTERNAL)
|
|
|
|
*/
|
2011-05-03 00:35:12 +02:00
|
|
|
static printf_arg arg_clbk_positional(void *ctx, int pos, int type, __ms_va_list *valist)
|
2011-04-27 12:09:01 +02:00
|
|
|
{
|
|
|
|
printf_arg *args = ctx;
|
|
|
|
return args[pos];
|
|
|
|
}
|
|
|
|
|
2010-04-19 10:57:40 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _vsnprintf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vsnprintf( char *str, MSVCRT_size_t len,
|
|
|
|
const char *format, __ms_va_list valist )
|
|
|
|
{
|
2011-04-20 14:42:48 +02:00
|
|
|
static const char nullbyte = '\0';
|
|
|
|
struct _str_ctx_a ctx = {len, str};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pf_printf_a(puts_clbk_str_a, &ctx, format, NULL, FALSE, FALSE,
|
2011-05-11 15:39:07 +02:00
|
|
|
arg_clbk_valist, NULL, &valist);
|
2011-04-20 14:42:48 +02:00
|
|
|
puts_clbk_str_a(&ctx, 1, &nullbyte);
|
|
|
|
return ret;
|
2010-04-19 10:57:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _vsnprintf_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vsnprintf_l( char *str, MSVCRT_size_t len, const char *format,
|
|
|
|
MSVCRT__locale_t locale, __ms_va_list valist )
|
|
|
|
{
|
2011-04-20 14:42:48 +02:00
|
|
|
static const char nullbyte = '\0';
|
|
|
|
struct _str_ctx_a ctx = {len, str};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pf_printf_a(puts_clbk_str_a, &ctx, format, locale, FALSE, FALSE,
|
2011-05-11 15:39:07 +02:00
|
|
|
arg_clbk_valist, NULL, &valist);
|
2011-04-20 14:42:48 +02:00
|
|
|
puts_clbk_str_a(&ctx, 1, &nullbyte);
|
|
|
|
return ret;
|
2010-04-19 10:57:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _vsnprintf_s_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vsnprintf_s_l( char *str, MSVCRT_size_t sizeOfBuffer,
|
|
|
|
MSVCRT_size_t count, const char *format,
|
|
|
|
MSVCRT__locale_t locale, __ms_va_list valist )
|
|
|
|
{
|
2011-04-20 14:42:48 +02:00
|
|
|
static const char nullbyte = '\0';
|
|
|
|
struct _str_ctx_a ctx;
|
2010-04-19 10:57:40 +02:00
|
|
|
int len, ret;
|
|
|
|
|
|
|
|
if(sizeOfBuffer<count+1 || count==-1)
|
|
|
|
len = sizeOfBuffer;
|
|
|
|
else
|
|
|
|
len = count+1;
|
|
|
|
|
2011-04-20 14:42:48 +02:00
|
|
|
ctx.len = len;
|
|
|
|
ctx.buf = str;
|
|
|
|
ret = pf_printf_a(puts_clbk_str_a, &ctx, format, locale, FALSE, TRUE,
|
2011-05-11 15:39:07 +02:00
|
|
|
arg_clbk_valist, NULL, &valist);
|
2011-04-20 14:42:48 +02:00
|
|
|
puts_clbk_str_a(&ctx, 1, &nullbyte);
|
2010-04-19 10:57:40 +02:00
|
|
|
|
|
|
|
if(ret<0 || ret==len) {
|
2010-06-06 17:11:09 +02:00
|
|
|
if(count!=MSVCRT__TRUNCATE && count>sizeOfBuffer) {
|
2012-07-26 11:05:32 +02:00
|
|
|
MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE);
|
2010-04-19 10:57:40 +02:00
|
|
|
memset(str, 0, sizeOfBuffer);
|
|
|
|
} else
|
|
|
|
str[len-1] = '\0';
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _vsnprintf_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vsnprintf_s( char *str, MSVCRT_size_t sizeOfBuffer,
|
|
|
|
MSVCRT_size_t count, const char *format, __ms_va_list valist )
|
|
|
|
{
|
|
|
|
return MSVCRT_vsnprintf_s_l(str,sizeOfBuffer, count, format, NULL, valist);
|
|
|
|
}
|
|
|
|
|
2006-11-14 12:29:18 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* vsprintf (MSVCRT.@)
|
|
|
|
*/
|
2009-01-02 21:43:58 +01:00
|
|
|
int CDECL MSVCRT_vsprintf( char *str, const char *format, __ms_va_list valist)
|
2006-11-14 12:29:18 +01:00
|
|
|
{
|
|
|
|
return MSVCRT_vsnprintf(str, INT_MAX, format, valist);
|
|
|
|
}
|
|
|
|
|
2010-01-10 22:37:31 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* vsprintf_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vsprintf_s( char *str, MSVCRT_size_t num, const char *format, __ms_va_list valist)
|
|
|
|
{
|
|
|
|
return MSVCRT_vsnprintf(str, num, format, valist);
|
|
|
|
}
|
|
|
|
|
2009-03-26 12:45:59 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _vscprintf (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
int CDECL MSVCRT__vscprintf( const char *format, __ms_va_list valist )
|
2009-03-26 12:45:59 +01:00
|
|
|
{
|
|
|
|
return MSVCRT_vsnprintf( NULL, INT_MAX, format, valist );
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:30:02 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _snprintf (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL MSVCRT__snprintf(char *str, unsigned int len, const char *format, ...)
|
2006-01-14 17:30:02 +01:00
|
|
|
{
|
|
|
|
int retval;
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_list valist;
|
|
|
|
__ms_va_start(valist, format);
|
2006-01-14 17:30:02 +01:00
|
|
|
retval = MSVCRT_vsnprintf(str, len, format, valist);
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_end(valist);
|
2006-01-14 17:30:02 +01:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-06-10 21:12:20 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _snprintf_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__snprintf_s(char *str, unsigned int len, unsigned int count,
|
|
|
|
const char *format, ...)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
__ms_va_list valist;
|
|
|
|
__ms_va_start(valist, format);
|
|
|
|
retval = MSVCRT_vsnprintf_s_l(str, len, count, format, NULL, valist);
|
|
|
|
__ms_va_end(valist);
|
2010-08-27 01:46:25 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _scprintf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__scprintf(const char *format, ...)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
__ms_va_list valist;
|
|
|
|
__ms_va_start(valist, format);
|
2011-06-03 15:28:32 +02:00
|
|
|
retval = MSVCRT__vscprintf(format, valist);
|
2010-08-27 01:46:25 +02:00
|
|
|
__ms_va_end(valist);
|
2010-06-10 21:12:20 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-04-19 10:57:50 +02:00
|
|
|
/*********************************************************************
|
2010-06-06 16:19:14 +02:00
|
|
|
* _vsnwprintf (MSVCRT.@)
|
2010-04-19 10:57:50 +02:00
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vsnwprintf(MSVCRT_wchar_t *str, MSVCRT_size_t len,
|
|
|
|
const MSVCRT_wchar_t *format, __ms_va_list valist)
|
|
|
|
{
|
2011-04-20 14:42:48 +02:00
|
|
|
static const MSVCRT_wchar_t nullbyte = '\0';
|
|
|
|
struct _str_ctx_w ctx = {len, str};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pf_printf_w(puts_clbk_str_w, &ctx, format, NULL, FALSE, FALSE,
|
2011-05-11 15:39:07 +02:00
|
|
|
arg_clbk_valist, NULL, &valist);
|
2011-04-20 14:42:48 +02:00
|
|
|
puts_clbk_str_w(&ctx, 1, &nullbyte);
|
|
|
|
return ret;
|
2010-04-19 10:57:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2010-06-06 16:19:14 +02:00
|
|
|
* _vsnwprintf_l (MSVCRT.@)
|
2010-04-19 10:57:50 +02:00
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vsnwprintf_l(MSVCRT_wchar_t *str, MSVCRT_size_t len,
|
|
|
|
const MSVCRT_wchar_t *format, MSVCRT__locale_t locale,
|
|
|
|
__ms_va_list valist)
|
|
|
|
{
|
2011-04-20 14:42:48 +02:00
|
|
|
static const MSVCRT_wchar_t nullbyte = '\0';
|
|
|
|
struct _str_ctx_w ctx = {len, str};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pf_printf_w(puts_clbk_str_w, &ctx, format, locale, FALSE, FALSE,
|
2011-05-11 15:39:07 +02:00
|
|
|
arg_clbk_valist, NULL, &valist);
|
2011-04-20 14:42:48 +02:00
|
|
|
puts_clbk_str_w(&ctx, 1, &nullbyte);
|
|
|
|
return ret;
|
2010-04-19 10:57:50 +02:00
|
|
|
}
|
|
|
|
|
2011-08-01 16:08:06 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _vswprintf_p_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vswprintf_p_l(MSVCRT_wchar_t *buffer, MSVCRT_size_t length,
|
|
|
|
const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, __ms_va_list args)
|
|
|
|
{
|
|
|
|
static const MSVCRT_wchar_t nullbyte = '\0';
|
|
|
|
printf_arg args_ctx[MSVCRT__ARGMAX+1];
|
|
|
|
struct _str_ctx_w puts_ctx = {length, buffer};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
memset(args_ctx, 0, sizeof(args_ctx));
|
|
|
|
|
|
|
|
ret = create_positional_ctx_w(args_ctx, format, args);
|
|
|
|
if(ret < 0) {
|
|
|
|
MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0);
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return ret;
|
|
|
|
} else if(ret == 0)
|
2011-09-20 10:32:29 +02:00
|
|
|
ret = pf_printf_w(puts_clbk_str_w, &puts_ctx, format, locale, FALSE, TRUE,
|
2011-08-01 16:08:06 +02:00
|
|
|
arg_clbk_valist, NULL, &args);
|
|
|
|
else
|
|
|
|
ret = pf_printf_w(puts_clbk_str_w, &puts_ctx, format, locale, TRUE, TRUE,
|
|
|
|
arg_clbk_positional, args_ctx, NULL);
|
|
|
|
|
|
|
|
puts_clbk_str_w(&puts_ctx, 1, &nullbyte);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-19 10:57:50 +02:00
|
|
|
/*********************************************************************
|
2010-06-06 16:19:14 +02:00
|
|
|
* _vsnwprintf_s_l (MSVCRT.@)
|
2010-04-19 10:57:50 +02:00
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vsnwprintf_s_l( MSVCRT_wchar_t *str, MSVCRT_size_t sizeOfBuffer,
|
|
|
|
MSVCRT_size_t count, const MSVCRT_wchar_t *format,
|
|
|
|
MSVCRT__locale_t locale, __ms_va_list valist)
|
|
|
|
{
|
2011-04-20 14:42:48 +02:00
|
|
|
static const MSVCRT_wchar_t nullbyte = '\0';
|
|
|
|
struct _str_ctx_w ctx;
|
2010-04-19 10:57:50 +02:00
|
|
|
int len, ret;
|
|
|
|
|
2010-06-07 03:54:14 +02:00
|
|
|
len = sizeOfBuffer;
|
2010-04-19 10:57:50 +02:00
|
|
|
if(count!=-1 && len>count+1)
|
|
|
|
len = count+1;
|
|
|
|
|
2011-04-20 14:42:48 +02:00
|
|
|
ctx.len = len;
|
|
|
|
ctx.buf = str;
|
|
|
|
ret = pf_printf_w(puts_clbk_str_w, &ctx, format, locale, FALSE, TRUE,
|
2011-05-11 15:39:07 +02:00
|
|
|
arg_clbk_valist, NULL, &valist);
|
2011-04-20 14:42:48 +02:00
|
|
|
puts_clbk_str_w(&ctx, 1, &nullbyte);
|
2010-04-19 10:57:50 +02:00
|
|
|
|
|
|
|
if(ret<0 || ret==len) {
|
2010-06-07 03:54:14 +02:00
|
|
|
if(count!=MSVCRT__TRUNCATE && count>sizeOfBuffer) {
|
2012-07-26 11:05:32 +02:00
|
|
|
MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE);
|
2010-06-07 03:54:14 +02:00
|
|
|
memset(str, 0, sizeOfBuffer*sizeof(MSVCRT_wchar_t));
|
2010-04-19 10:57:50 +02:00
|
|
|
} else
|
|
|
|
str[len-1] = '\0';
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2010-06-06 16:19:14 +02:00
|
|
|
* _vsnwprintf_s (MSVCRT.@)
|
2010-04-19 10:57:50 +02:00
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vsnwprintf_s(MSVCRT_wchar_t *str, MSVCRT_size_t sizeOfBuffer,
|
|
|
|
MSVCRT_size_t count, const MSVCRT_wchar_t *format, __ms_va_list valist)
|
|
|
|
{
|
|
|
|
return MSVCRT_vsnwprintf_s_l(str, sizeOfBuffer, count,
|
|
|
|
format, NULL, valist);
|
2005-02-14 21:53:42 +01:00
|
|
|
}
|
|
|
|
|
2006-01-14 17:30:02 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _snwprintf (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL MSVCRT__snwprintf( MSVCRT_wchar_t *str, unsigned int len, const MSVCRT_wchar_t *format, ...)
|
2006-01-14 17:30:02 +01:00
|
|
|
{
|
|
|
|
int retval;
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_list valist;
|
|
|
|
__ms_va_start(valist, format);
|
2006-01-14 17:30:02 +01:00
|
|
|
retval = MSVCRT_vsnwprintf(str, len, format, valist);
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_end(valist);
|
2006-01-14 17:30:02 +01:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2012-01-06 22:09:37 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _snwprintf_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__snwprintf_l( MSVCRT_wchar_t *str, unsigned int len, const MSVCRT_wchar_t *format,
|
|
|
|
MSVCRT__locale_t locale, ...)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
__ms_va_list valist;
|
|
|
|
__ms_va_start(valist, locale);
|
|
|
|
retval = MSVCRT_vsnwprintf_l(str, len, format, locale, valist);
|
|
|
|
__ms_va_end(valist);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-06-10 21:28:01 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _snwprintf_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__snwprintf_s( MSVCRT_wchar_t *str, unsigned int len, unsigned int count,
|
|
|
|
const MSVCRT_wchar_t *format, ...)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
__ms_va_list valist;
|
|
|
|
__ms_va_start(valist, format);
|
|
|
|
retval = MSVCRT_vsnwprintf_s_l(str, len, count, format, NULL, valist);
|
|
|
|
__ms_va_end(valist);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* sprintf (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL MSVCRT_sprintf( char *str, const char *format, ... )
|
2004-06-02 02:35:09 +02:00
|
|
|
{
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_list ap;
|
2004-06-02 02:35:09 +02:00
|
|
|
int r;
|
|
|
|
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_start( ap, format );
|
2005-02-14 21:53:42 +01:00
|
|
|
r = MSVCRT_vsnprintf( str, INT_MAX, format, ap );
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_end( ap );
|
2004-06-02 02:35:09 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-01-10 22:40:40 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* sprintf_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_sprintf_s( char *str, MSVCRT_size_t num, const char *format, ... )
|
|
|
|
{
|
|
|
|
__ms_va_list ap;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
__ms_va_start( ap, format );
|
|
|
|
r = MSVCRT_vsnprintf( str, num, format, ap );
|
|
|
|
__ms_va_end( ap );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-06-10 21:54:30 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _scwprintf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__scwprintf( const MSVCRT_wchar_t *format, ... )
|
|
|
|
{
|
|
|
|
__ms_va_list ap;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
__ms_va_start( ap, format );
|
|
|
|
r = MSVCRT_vsnwprintf( NULL, INT_MAX, format, ap );
|
|
|
|
__ms_va_end( ap );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2005-02-14 21:53:42 +01:00
|
|
|
* swprintf (MSVCRT.@)
|
2001-01-22 03:21:54 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL MSVCRT_swprintf( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ... )
|
2001-01-22 03:21:54 +01:00
|
|
|
{
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_list ap;
|
2005-02-14 21:53:42 +01:00
|
|
|
int r;
|
|
|
|
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_start( ap, format );
|
2005-02-14 21:53:42 +01:00
|
|
|
r = MSVCRT_vsnwprintf( str, INT_MAX, format, ap );
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_end( ap );
|
2005-02-14 21:53:42 +01:00
|
|
|
return r;
|
2001-01-22 03:21:54 +01:00
|
|
|
}
|
|
|
|
|
2010-04-20 21:39:01 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* swprintf_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_swprintf_s(MSVCRT_wchar_t *str, MSVCRT_size_t numberOfElements,
|
|
|
|
const MSVCRT_wchar_t *format, ... )
|
|
|
|
{
|
|
|
|
__ms_va_list ap;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
__ms_va_start(ap, format);
|
2010-06-07 03:54:14 +02:00
|
|
|
r = MSVCRT_vsnwprintf_s(str, numberOfElements, INT_MAX, format, ap);
|
2010-04-20 21:39:01 +02:00
|
|
|
__ms_va_end(ap);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-08-01 13:55:39 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _swprintf_s_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__swprintf_s_l(MSVCRT_wchar_t *str, MSVCRT_size_t numberOfElements,
|
|
|
|
const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, ... )
|
|
|
|
{
|
|
|
|
__ms_va_list ap;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
__ms_va_start(ap, locale);
|
|
|
|
r = MSVCRT_vsnwprintf_s_l(str, numberOfElements, INT_MAX, format, locale, ap);
|
|
|
|
__ms_va_end(ap);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2001-01-22 03:21:54 +01:00
|
|
|
/*********************************************************************
|
2011-07-29 15:10:10 +02:00
|
|
|
* _vswprintf (MSVCRT.@)
|
2001-01-22 03:21:54 +01:00
|
|
|
*/
|
2009-01-02 21:43:58 +01:00
|
|
|
int CDECL MSVCRT_vswprintf( MSVCRT_wchar_t* str, const MSVCRT_wchar_t* format, __ms_va_list args )
|
2001-01-22 03:21:54 +01:00
|
|
|
{
|
2005-02-14 21:53:42 +01:00
|
|
|
return MSVCRT_vsnwprintf( str, INT_MAX, format, args );
|
2001-01-22 03:21:54 +01:00
|
|
|
}
|
|
|
|
|
2011-07-29 15:10:10 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _vswprintf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vswprintf_l( MSVCRT_wchar_t* str, const MSVCRT_wchar_t* format,
|
|
|
|
MSVCRT__locale_t locale, __ms_va_list args )
|
|
|
|
{
|
|
|
|
return MSVCRT_vsnwprintf_l( str, INT_MAX, format, locale, args );
|
|
|
|
}
|
|
|
|
|
2009-03-26 12:45:59 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _vscwprintf (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
int CDECL MSVCRT__vscwprintf( const MSVCRT_wchar_t *format, __ms_va_list args )
|
2009-03-26 12:45:59 +01:00
|
|
|
{
|
|
|
|
return MSVCRT_vsnwprintf( NULL, INT_MAX, format, args );
|
|
|
|
}
|
|
|
|
|
2011-08-01 16:08:06 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _vscwprintf_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__vscwprintf_l( const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, __ms_va_list args )
|
|
|
|
{
|
|
|
|
return MSVCRT_vsnwprintf_l( NULL, INT_MAX, format, locale, args );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _vscwprintf_p_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__vscwprintf_p_l( const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, __ms_va_list args )
|
|
|
|
{
|
|
|
|
return MSVCRT_vswprintf_p_l( NULL, INT_MAX, format, locale, args );
|
|
|
|
}
|
|
|
|
|
2008-10-18 13:59:47 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* vswprintf_s (MSVCRT.@)
|
|
|
|
*/
|
2010-04-19 10:58:00 +02:00
|
|
|
int CDECL MSVCRT_vswprintf_s(MSVCRT_wchar_t* str, MSVCRT_size_t numberOfElements,
|
|
|
|
const MSVCRT_wchar_t* format, __ms_va_list args)
|
2008-10-18 13:59:47 +02:00
|
|
|
{
|
2010-06-07 03:54:14 +02:00
|
|
|
return MSVCRT_vsnwprintf_s(str, numberOfElements, INT_MAX, format, args );
|
2010-04-19 10:58:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _vswprintf_s_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vswprintf_s_l(MSVCRT_wchar_t* str, MSVCRT_size_t numberOfElements,
|
|
|
|
const MSVCRT_wchar_t* format, MSVCRT__locale_t locale, __ms_va_list args)
|
|
|
|
{
|
2010-06-07 03:54:14 +02:00
|
|
|
return MSVCRT_vsnwprintf_s_l(str, numberOfElements, INT_MAX,
|
|
|
|
format, locale, args );
|
2008-10-18 13:59:47 +02:00
|
|
|
}
|
|
|
|
|
2011-04-27 12:09:01 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _vsprintf_p_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vsprintf_p_l(char *buffer, MSVCRT_size_t length, const char *format,
|
|
|
|
MSVCRT__locale_t locale, __ms_va_list args)
|
|
|
|
{
|
|
|
|
static const char nullbyte = '\0';
|
|
|
|
printf_arg args_ctx[MSVCRT__ARGMAX+1];
|
|
|
|
struct _str_ctx_a puts_ctx = {length, buffer};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
memset(args_ctx, 0, sizeof(args_ctx));
|
|
|
|
|
|
|
|
ret = create_positional_ctx_a(args_ctx, format, args);
|
|
|
|
if(ret < 0) {
|
|
|
|
MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0);
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return ret;
|
|
|
|
} else if(ret == 0)
|
|
|
|
ret = pf_printf_a(puts_clbk_str_a, &puts_ctx, format, locale, FALSE, TRUE,
|
2011-05-11 15:39:07 +02:00
|
|
|
arg_clbk_valist, NULL, &args);
|
2011-04-27 12:09:01 +02:00
|
|
|
else
|
|
|
|
ret = pf_printf_a(puts_clbk_str_a, &puts_ctx, format, locale, TRUE, TRUE,
|
|
|
|
arg_clbk_positional, args_ctx, NULL);
|
|
|
|
|
|
|
|
puts_clbk_str_a(&puts_ctx, 1, &nullbyte);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _vsprintf_p (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_vsprintf_p(char *buffer, MSVCRT_size_t length,
|
|
|
|
const char *format, __ms_va_list args)
|
|
|
|
{
|
|
|
|
return MSVCRT_vsprintf_p_l(buffer, length, format, NULL, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _sprintf_p_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_sprintf_p_l(char *buffer, MSVCRT_size_t length,
|
|
|
|
const char *format, MSVCRT__locale_t locale, ...)
|
|
|
|
{
|
|
|
|
__ms_va_list valist;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
__ms_va_start(valist, locale);
|
|
|
|
r = MSVCRT_vsprintf_p_l(buffer, length, format, locale, valist);
|
|
|
|
__ms_va_end(valist);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _swprintf_p_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_swprintf_p_l(MSVCRT_wchar_t *buffer, MSVCRT_size_t length,
|
|
|
|
const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, ...)
|
|
|
|
{
|
|
|
|
__ms_va_list valist;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
__ms_va_start(valist, locale);
|
|
|
|
r = MSVCRT_vswprintf_p_l(buffer, length, format, locale, valist);
|
|
|
|
__ms_va_end(valist);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-03-30 15:34:31 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcscoll_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__wcscoll_l(const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
|
|
|
|
|
|
|
return CompareStringW(locinfo->lc_handle[MSVCRT_LC_COLLATE], 0, str1, -1, str2, -1)-CSTR_EQUAL;
|
|
|
|
}
|
|
|
|
|
2001-01-22 03:21:54 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* wcscoll (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL MSVCRT_wcscoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2013-03-30 15:34:31 +01:00
|
|
|
return MSVCRT__wcscoll_l(str1, str2, NULL);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* wcspbrk (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_wchar_t* CDECL MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wchar_t* accept )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2012-12-17 23:12:14 +01:00
|
|
|
const MSVCRT_wchar_t* p;
|
|
|
|
|
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
for (p = accept; *p; p++) if (*p == *str) return (MSVCRT_wchar_t*)str;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return NULL;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2006-01-14 17:24:49 +01:00
|
|
|
/*********************************************************************
|
2010-11-02 22:03:59 +01:00
|
|
|
* wcstok_s (MSVCRT.@)
|
2006-01-14 17:24:49 +01:00
|
|
|
*/
|
2010-11-02 22:03:59 +01:00
|
|
|
MSVCRT_wchar_t * CDECL wcstok_s( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *delim,
|
|
|
|
MSVCRT_wchar_t **next_token )
|
2006-01-14 17:24:49 +01:00
|
|
|
{
|
|
|
|
MSVCRT_wchar_t *ret;
|
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(delim != NULL)) return NULL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(next_token != NULL)) return NULL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL || *next_token != NULL)) return NULL;
|
|
|
|
|
2010-11-02 22:03:59 +01:00
|
|
|
if (!str) str = *next_token;
|
2006-01-14 17:24:49 +01:00
|
|
|
|
|
|
|
while (*str && strchrW( delim, *str )) str++;
|
|
|
|
if (!*str) return NULL;
|
|
|
|
ret = str++;
|
|
|
|
while (*str && !strchrW( delim, *str )) str++;
|
|
|
|
if (*str) *str++ = 0;
|
2010-11-02 22:03:59 +01:00
|
|
|
*next_token = str;
|
2006-01-14 17:24:49 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-02 22:03:59 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* wcstok (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_wchar_t * CDECL MSVCRT_wcstok( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *delim )
|
|
|
|
{
|
|
|
|
return wcstok_s(str, delim, &msvcrt_get_thread_data()->wcstok_next);
|
|
|
|
}
|
2006-01-14 17:24:49 +01:00
|
|
|
|
2013-07-25 10:14:33 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wctomb_s_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__wctomb_s_l(int *len, char *mbchar, MSVCRT_size_t size,
|
|
|
|
MSVCRT_wchar_t wch, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
BOOL error;
|
|
|
|
int mblen;
|
|
|
|
|
|
|
|
if(!mbchar && size>0) {
|
|
|
|
if(len)
|
|
|
|
*len = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(len)
|
|
|
|
*len = -1;
|
|
|
|
|
|
|
|
if(!MSVCRT_CHECK_PMT(size <= INT_MAX))
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
|
|
|
|
|
|
|
if(!locinfo->lc_codepage) {
|
|
|
|
if(wch > 0xff) {
|
|
|
|
if(mbchar && size>0)
|
|
|
|
memset(mbchar, 0, size);
|
|
|
|
*MSVCRT__errno() = MSVCRT_EILSEQ;
|
|
|
|
return MSVCRT_EILSEQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!MSVCRT_CHECK_PMT_ERR(size >= 1, MSVCRT_ERANGE))
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
|
|
|
|
*mbchar = wch;
|
|
|
|
if(len)
|
|
|
|
*len = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mblen = WideCharToMultiByte(locinfo->lc_codepage, 0, &wch, 1, mbchar, size, NULL, &error);
|
|
|
|
if(!mblen || error) {
|
|
|
|
if(!mblen && GetLastError()==ERROR_INSUFFICIENT_BUFFER) {
|
|
|
|
if(mbchar && size>0)
|
|
|
|
memset(mbchar, 0, size);
|
|
|
|
|
|
|
|
MSVCRT_INVALID_PMT("insufficient buffer size", MSVCRT_ERANGE);
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*MSVCRT__errno() = MSVCRT_EILSEQ;
|
|
|
|
return MSVCRT_EILSEQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(len)
|
|
|
|
*len = mblen;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* wctomb_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_wctomb_s(int *len, char *mbchar, MSVCRT_size_t size, MSVCRT_wchar_t wch)
|
|
|
|
{
|
|
|
|
return MSVCRT__wctomb_s_l(len, mbchar, size, wch, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wctomb_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__wctomb_l(char *dst, MSVCRT_wchar_t ch, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
MSVCRT__wctomb_s_l(&len, dst, dst ? 6 : 0, ch, locale);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* wctomb (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
INT CDECL MSVCRT_wctomb( char *dst, MSVCRT_wchar_t ch )
|
|
|
|
{
|
|
|
|
return MSVCRT__wctomb_l(dst, ch, NULL);
|
|
|
|
}
|
|
|
|
|
2011-04-05 23:47:22 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* wctob (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
INT CDECL MSVCRT_wctob( MSVCRT_wint_t wchar )
|
|
|
|
{
|
|
|
|
char out;
|
|
|
|
BOOL error;
|
2011-11-30 14:34:13 +01:00
|
|
|
UINT codepage = get_locinfo()->lc_codepage;
|
|
|
|
|
|
|
|
if(!codepage) {
|
|
|
|
if (wchar < 0xff)
|
|
|
|
return (signed char)wchar;
|
|
|
|
else
|
|
|
|
return MSVCRT_EOF;
|
|
|
|
} else if(WideCharToMultiByte( codepage, 0, &wchar, 1, &out, 1, NULL, &error ) && !error)
|
2011-04-05 23:47:22 +02:00
|
|
|
return (INT)out;
|
|
|
|
return MSVCRT_EOF;
|
|
|
|
}
|
|
|
|
|
2012-11-29 22:49:42 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* wcrtomb (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT_wcrtomb( char *dst, MSVCRT_wchar_t ch, MSVCRT_mbstate_t *s)
|
|
|
|
{
|
|
|
|
if(s)
|
|
|
|
*s = 0;
|
|
|
|
return MSVCRT_wctomb(dst, ch);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswalnum (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL MSVCRT_iswalnum( MSVCRT_wchar_t wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-11-08 20:16:34 +01:00
|
|
|
return isalnumW( wc );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswalpha (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL MSVCRT_iswalpha( MSVCRT_wchar_t wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-11-08 20:16:34 +01:00
|
|
|
return isalphaW( wc );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2010-04-08 10:24:44 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* iswalpha_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
INT CDECL MSVCRT__iswalpha_l( MSVCRT_wchar_t wc, MSVCRT__locale_t locale )
|
|
|
|
{
|
|
|
|
return isalphaW( wc );
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswcntrl (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL MSVCRT_iswcntrl( MSVCRT_wchar_t wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-11-08 20:16:34 +01:00
|
|
|
return iscntrlW( wc );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswdigit (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL MSVCRT_iswdigit( MSVCRT_wchar_t wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-11-08 20:16:34 +01:00
|
|
|
return isdigitW( wc );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2011-10-06 20:14:23 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _iswdigit_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
INT CDECL MSVCRT__iswdigit_l( MSVCRT_wchar_t wc, MSVCRT__locale_t locale )
|
|
|
|
{
|
|
|
|
return isdigitW( wc );
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswgraph (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL MSVCRT_iswgraph( MSVCRT_wchar_t wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-11-08 20:16:34 +01:00
|
|
|
return isgraphW( wc );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswlower (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL MSVCRT_iswlower( MSVCRT_wchar_t wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-11-08 20:16:34 +01:00
|
|
|
return islowerW( wc );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswprint (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL MSVCRT_iswprint( MSVCRT_wchar_t wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-11-08 20:16:34 +01:00
|
|
|
return isprintW( wc );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswpunct (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL MSVCRT_iswpunct( MSVCRT_wchar_t wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-11-08 20:16:34 +01:00
|
|
|
return ispunctW( wc );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswspace (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL MSVCRT_iswspace( MSVCRT_wchar_t wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-11-08 20:16:34 +01:00
|
|
|
return isspaceW( wc );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswupper (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL MSVCRT_iswupper( MSVCRT_wchar_t wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-11-08 20:16:34 +01:00
|
|
|
return isupperW( wc );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswxdigit (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL MSVCRT_iswxdigit( MSVCRT_wchar_t wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-11-08 20:16:34 +01:00
|
|
|
return isxdigitW( wc );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2008-02-27 09:58:04 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* wcscpy_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
INT CDECL MSVCRT_wcscpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, const MSVCRT_wchar_t *wcSrc)
|
|
|
|
{
|
2008-10-21 22:44:27 +02:00
|
|
|
MSVCRT_size_t size = 0;
|
2008-02-27 09:58:04 +01:00
|
|
|
|
2013-08-02 19:58:57 +02:00
|
|
|
if(!MSVCRT_CHECK_PMT(wcDest)) return MSVCRT_EINVAL;
|
|
|
|
if(!MSVCRT_CHECK_PMT(numElement)) return MSVCRT_EINVAL;
|
2008-02-27 09:58:04 +01:00
|
|
|
|
2008-05-26 17:21:13 +02:00
|
|
|
wcDest[0] = 0;
|
|
|
|
|
2013-08-02 19:58:57 +02:00
|
|
|
if(!MSVCRT_CHECK_PMT(wcSrc)) return MSVCRT_EINVAL;
|
2008-02-27 09:58:04 +01:00
|
|
|
|
|
|
|
size = strlenW(wcSrc) + 1;
|
|
|
|
|
2013-08-02 19:58:57 +02:00
|
|
|
if(!MSVCRT_CHECK_PMT_ERR(size <= numElement, MSVCRT_ERANGE))
|
2008-05-26 17:21:13 +02:00
|
|
|
return MSVCRT_ERANGE;
|
2008-02-27 09:58:04 +01:00
|
|
|
|
|
|
|
memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-10-02 22:00:34 +02:00
|
|
|
|
2013-03-27 16:13:08 +01:00
|
|
|
/******************************************************************
|
|
|
|
* wcsncpy (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_wchar_t* __cdecl MSVCRT_wcsncpy( MSVCRT_wchar_t* s1,
|
|
|
|
const MSVCRT_wchar_t *s2, MSVCRT_size_t n )
|
|
|
|
{
|
|
|
|
MSVCRT_size_t i;
|
|
|
|
|
|
|
|
for(i=0; i<n; i++)
|
|
|
|
if(!(s1[i] = s2[i])) break;
|
|
|
|
for(; i<n; i++)
|
|
|
|
s1[i] = 0;
|
|
|
|
return s1;
|
|
|
|
}
|
|
|
|
|
2008-10-02 22:00:34 +02:00
|
|
|
/******************************************************************
|
|
|
|
* wcsncpy_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
INT CDECL MSVCRT_wcsncpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, const MSVCRT_wchar_t *wcSrc,
|
|
|
|
MSVCRT_size_t count )
|
|
|
|
{
|
2012-04-24 18:44:07 +02:00
|
|
|
WCHAR *p = wcDest;
|
|
|
|
BOOL truncate = (count == MSVCRT__TRUNCATE);
|
|
|
|
|
|
|
|
if(!wcDest && !numElement && !count)
|
|
|
|
return 0;
|
2008-10-02 22:00:34 +02:00
|
|
|
|
|
|
|
if (!wcDest || !numElement)
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
|
|
|
|
if (!wcSrc)
|
|
|
|
{
|
2012-04-24 18:44:07 +02:00
|
|
|
*wcDest = 0;
|
2011-10-04 23:03:03 +02:00
|
|
|
return count ? MSVCRT_EINVAL : 0;
|
2008-10-02 22:00:34 +02:00
|
|
|
}
|
|
|
|
|
2012-04-24 18:44:07 +02:00
|
|
|
while (numElement && count && *wcSrc)
|
2012-04-12 16:19:31 +02:00
|
|
|
{
|
2012-04-24 18:44:07 +02:00
|
|
|
*p++ = *wcSrc++;
|
|
|
|
numElement--;
|
|
|
|
count--;
|
2012-04-12 16:19:31 +02:00
|
|
|
}
|
2012-04-24 18:44:07 +02:00
|
|
|
if (!numElement && truncate)
|
2008-10-02 22:00:34 +02:00
|
|
|
{
|
2012-04-24 18:44:07 +02:00
|
|
|
*(p-1) = 0;
|
|
|
|
return MSVCRT_STRUNCATE;
|
|
|
|
}
|
|
|
|
else if (!numElement)
|
|
|
|
{
|
|
|
|
*wcDest = 0;
|
2008-10-02 22:00:34 +02:00
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
2012-04-24 18:44:07 +02:00
|
|
|
*p = 0;
|
|
|
|
return 0;
|
2008-10-02 22:00:34 +02:00
|
|
|
}
|
2008-10-12 13:34:16 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* wcscat_s (MSVCRT.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
INT CDECL MSVCRT_wcscat_s(MSVCRT_wchar_t* dst, MSVCRT_size_t elem, const MSVCRT_wchar_t* src)
|
|
|
|
{
|
|
|
|
MSVCRT_wchar_t* ptr = dst;
|
|
|
|
|
|
|
|
if (!dst || elem == 0) return MSVCRT_EINVAL;
|
|
|
|
if (!src)
|
|
|
|
{
|
|
|
|
dst[0] = '\0';
|
|
|
|
return MSVCRT_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 MSVCRT_ERANGE;
|
2010-10-18 14:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* wcsncat_s (MSVCRT.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
INT CDECL MSVCRT_wcsncat_s(MSVCRT_wchar_t *dst, MSVCRT_size_t elem,
|
|
|
|
const MSVCRT_wchar_t *src, MSVCRT_size_t count)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t srclen;
|
|
|
|
MSVCRT_wchar_t dststart;
|
2010-10-19 07:24:52 +02:00
|
|
|
INT ret = 0;
|
2010-10-18 14:06:16 +02:00
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(dst != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(elem > 0)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(src != NULL || count == 0)) return MSVCRT_EINVAL;
|
|
|
|
|
2010-10-19 07:24:52 +02:00
|
|
|
if (count == 0)
|
|
|
|
return 0;
|
2010-10-18 14:06:16 +02:00
|
|
|
|
2010-10-19 07:24:52 +02:00
|
|
|
for (dststart = 0; dststart < elem; dststart++)
|
2010-10-18 14:06:16 +02:00
|
|
|
{
|
2010-10-19 07:24:52 +02:00
|
|
|
if (dst[dststart] == '\0')
|
2010-10-18 14:06:16 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dststart == elem)
|
2010-11-15 22:00:10 +01:00
|
|
|
{
|
2012-07-26 11:05:32 +02:00
|
|
|
MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", MSVCRT_EINVAL);
|
2010-10-18 14:06:16 +02:00
|
|
|
return MSVCRT_EINVAL;
|
2010-11-15 22:00:10 +01:00
|
|
|
}
|
2010-10-18 14:06:16 +02:00
|
|
|
|
|
|
|
if (count == MSVCRT__TRUNCATE)
|
|
|
|
{
|
2010-10-19 07:24:52 +02:00
|
|
|
srclen = strlenW(src);
|
|
|
|
if (srclen >= (elem - dststart))
|
2010-10-18 14:06:16 +02:00
|
|
|
{
|
2010-10-19 07:24:52 +02:00
|
|
|
srclen = elem - dststart - 1;
|
|
|
|
ret = MSVCRT_STRUNCATE;
|
2010-10-18 14:06:16 +02:00
|
|
|
}
|
|
|
|
}
|
2010-10-19 07:24:52 +02:00
|
|
|
else
|
|
|
|
srclen = min(strlenW(src), count);
|
2010-10-18 14:06:16 +02:00
|
|
|
if (srclen < (elem - dststart))
|
|
|
|
{
|
|
|
|
memcpy(&dst[dststart], src, srclen*sizeof(MSVCRT_wchar_t));
|
2011-03-30 15:45:21 +02:00
|
|
|
dst[dststart+srclen] = '\0';
|
2010-10-19 07:24:52 +02:00
|
|
|
return ret;
|
2010-10-18 14:06:16 +02:00
|
|
|
}
|
2012-07-26 11:05:32 +02:00
|
|
|
MSVCRT_INVALID_PMT("dst[elem] is too small", MSVCRT_ERANGE);
|
2010-10-18 14:06:16 +02:00
|
|
|
dst[0] = '\0';
|
|
|
|
return MSVCRT_ERANGE;
|
2008-10-12 13:34:16 +02:00
|
|
|
}
|
2010-04-27 08:42:32 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
2010-06-06 16:19:14 +02:00
|
|
|
* _wcstoi64_l (MSVCRT.@)
|
2010-04-27 08:42:32 +02:00
|
|
|
*
|
|
|
|
* FIXME: locale parameter is ignored
|
|
|
|
*/
|
|
|
|
__int64 CDECL MSVCRT__wcstoi64_l(const MSVCRT_wchar_t *nptr,
|
|
|
|
MSVCRT_wchar_t **endptr, int base, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
BOOL negative = FALSE;
|
|
|
|
__int64 ret = 0;
|
|
|
|
|
|
|
|
TRACE("(%s %p %d %p)\n", debugstr_w(nptr), endptr, base, locale);
|
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(nptr != NULL)) return 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
|
2010-04-27 08:42:32 +02:00
|
|
|
|
|
|
|
while(isspaceW(*nptr)) nptr++;
|
|
|
|
|
|
|
|
if(*nptr == '-') {
|
|
|
|
negative = TRUE;
|
|
|
|
nptr++;
|
|
|
|
} else if(*nptr == '+')
|
|
|
|
nptr++;
|
|
|
|
|
|
|
|
if((base==0 || base==16) && *nptr=='0' && tolowerW(*(nptr+1))=='x') {
|
|
|
|
base = 16;
|
|
|
|
nptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(base == 0) {
|
|
|
|
if(*nptr=='0')
|
|
|
|
base = 8;
|
|
|
|
else
|
|
|
|
base = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(*nptr) {
|
2013-03-09 08:56:40 +01:00
|
|
|
MSVCRT_wchar_t cur = tolowerW(*nptr);
|
2010-04-27 08:42:32 +02:00
|
|
|
int v;
|
|
|
|
|
|
|
|
if(isdigitW(cur)) {
|
|
|
|
if(cur >= '0'+base)
|
|
|
|
break;
|
|
|
|
v = cur-'0';
|
|
|
|
} else {
|
|
|
|
if(cur<'a' || cur>='a'+base-10)
|
|
|
|
break;
|
|
|
|
v = cur-'a'+10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(negative)
|
|
|
|
v = -v;
|
|
|
|
|
|
|
|
nptr++;
|
|
|
|
|
|
|
|
if(!negative && (ret>MSVCRT_I64_MAX/base || ret*base>MSVCRT_I64_MAX-v)) {
|
|
|
|
ret = MSVCRT_I64_MAX;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
} else if(negative && (ret<MSVCRT_I64_MIN/base || ret*base<MSVCRT_I64_MIN-v)) {
|
|
|
|
ret = MSVCRT_I64_MIN;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
} else
|
|
|
|
ret = ret*base + v;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(endptr)
|
|
|
|
*endptr = (MSVCRT_wchar_t*)nptr;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2010-04-28 17:44:51 +02:00
|
|
|
* _wcstoi64 (MSVCRT.@)
|
2010-04-27 08:42:32 +02:00
|
|
|
*/
|
|
|
|
__int64 CDECL MSVCRT__wcstoi64(const MSVCRT_wchar_t *nptr,
|
|
|
|
MSVCRT_wchar_t **endptr, int base)
|
|
|
|
{
|
|
|
|
return MSVCRT__wcstoi64_l(nptr, endptr, base, NULL);
|
|
|
|
}
|
|
|
|
|
2013-07-28 09:43:59 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcstol_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_long CDECL MSVCRT__wcstol_l(const MSVCRT_wchar_t *s,
|
|
|
|
MSVCRT_wchar_t **end, int base, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
__int64 ret = MSVCRT__wcstoi64_l(s, end, base, locale);
|
|
|
|
|
|
|
|
if(ret > MSVCRT_LONG_MAX) {
|
|
|
|
ret = MSVCRT_LONG_MAX;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}else if(ret < MSVCRT_LONG_MIN) {
|
|
|
|
ret = MSVCRT_LONG_MIN;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-12 11:16:05 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wtoi_l (MSVCRT.@)
|
|
|
|
*/
|
2013-03-27 16:11:23 +01:00
|
|
|
int __cdecl MSVCRT__wtoi_l(const MSVCRT_wchar_t *str, MSVCRT__locale_t locale)
|
2012-12-12 11:16:05 +01:00
|
|
|
{
|
|
|
|
__int64 ret = MSVCRT__wcstoi64_l(str, NULL, 10, locale);
|
|
|
|
|
|
|
|
if(ret > INT_MAX) {
|
|
|
|
ret = INT_MAX;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
} else if(ret < INT_MIN) {
|
|
|
|
ret = INT_MIN;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-27 16:11:23 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wtoi (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int __cdecl MSVCRT__wtoi(const MSVCRT_wchar_t *str)
|
|
|
|
{
|
|
|
|
return MSVCRT__wtoi_l(str, NULL);
|
|
|
|
}
|
|
|
|
|
2013-03-27 16:11:32 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wtol_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_long __cdecl MSVCRT__wtol_l(const MSVCRT_wchar_t *str, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
__int64 ret = MSVCRT__wcstoi64_l(str, NULL, 10, locale);
|
|
|
|
|
|
|
|
if(ret > MSVCRT_LONG_MAX) {
|
|
|
|
ret = MSVCRT_LONG_MAX;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
} else if(ret < MSVCRT_LONG_MIN) {
|
|
|
|
ret = MSVCRT_LONG_MIN;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wtol (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_long __cdecl MSVCRT__wtol(const MSVCRT_wchar_t *str)
|
|
|
|
{
|
|
|
|
return MSVCRT__wtol_l(str, NULL);
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:42:32 +02:00
|
|
|
/*********************************************************************
|
2010-04-28 17:44:51 +02:00
|
|
|
* _wcstoui64_l (MSVCRT.@)
|
2010-04-27 08:42:32 +02:00
|
|
|
*
|
|
|
|
* FIXME: locale parameter is ignored
|
|
|
|
*/
|
|
|
|
unsigned __int64 CDECL MSVCRT__wcstoui64_l(const MSVCRT_wchar_t *nptr,
|
|
|
|
MSVCRT_wchar_t **endptr, int base, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
BOOL negative = FALSE;
|
|
|
|
unsigned __int64 ret = 0;
|
|
|
|
|
|
|
|
TRACE("(%s %p %d %p)\n", debugstr_w(nptr), endptr, base, locale);
|
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(nptr != NULL)) return 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
|
2010-04-27 08:42:32 +02:00
|
|
|
|
|
|
|
while(isspaceW(*nptr)) nptr++;
|
|
|
|
|
|
|
|
if(*nptr == '-') {
|
|
|
|
negative = TRUE;
|
|
|
|
nptr++;
|
|
|
|
} else if(*nptr == '+')
|
|
|
|
nptr++;
|
|
|
|
|
|
|
|
if((base==0 || base==16) && *nptr=='0' && tolowerW(*(nptr+1))=='x') {
|
|
|
|
base = 16;
|
|
|
|
nptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(base == 0) {
|
|
|
|
if(*nptr=='0')
|
|
|
|
base = 8;
|
|
|
|
else
|
|
|
|
base = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(*nptr) {
|
2013-03-09 08:56:40 +01:00
|
|
|
MSVCRT_wchar_t cur = tolowerW(*nptr);
|
2010-04-27 08:42:32 +02:00
|
|
|
int v;
|
|
|
|
|
2013-03-09 08:56:40 +01:00
|
|
|
if(isdigitW(cur)) {
|
2010-04-27 08:42:32 +02:00
|
|
|
if(cur >= '0'+base)
|
|
|
|
break;
|
|
|
|
v = *nptr-'0';
|
|
|
|
} else {
|
|
|
|
if(cur<'a' || cur>='a'+base-10)
|
|
|
|
break;
|
|
|
|
v = cur-'a'+10;
|
|
|
|
}
|
|
|
|
|
|
|
|
nptr++;
|
|
|
|
|
|
|
|
if(ret>MSVCRT_UI64_MAX/base || ret*base>MSVCRT_UI64_MAX-v) {
|
|
|
|
ret = MSVCRT_UI64_MAX;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
} else
|
|
|
|
ret = ret*base + v;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(endptr)
|
|
|
|
*endptr = (MSVCRT_wchar_t*)nptr;
|
|
|
|
|
|
|
|
return negative ? -ret : ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2010-04-28 17:44:51 +02:00
|
|
|
* _wcstoui64 (MSVCRT.@)
|
2010-04-27 08:42:32 +02:00
|
|
|
*/
|
|
|
|
unsigned __int64 CDECL MSVCRT__wcstoui64(const MSVCRT_wchar_t *nptr,
|
|
|
|
MSVCRT_wchar_t **endptr, int base)
|
|
|
|
{
|
|
|
|
return MSVCRT__wcstoui64_l(nptr, endptr, base, NULL);
|
|
|
|
}
|
2010-09-29 09:57:52 +02:00
|
|
|
|
2013-03-27 16:13:21 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcstoul_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_ulong __cdecl MSVCRT__wcstoul_l(const MSVCRT_wchar_t *s,
|
|
|
|
MSVCRT_wchar_t **end, int base, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
__int64 ret = MSVCRT__wcstoui64_l(s, end, base, locale);
|
|
|
|
|
|
|
|
if(ret > MSVCRT_ULONG_MAX) {
|
|
|
|
ret = MSVCRT_ULONG_MAX;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* wcstoul (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_ulong __cdecl MSVCRT_wcstoul(const MSVCRT_wchar_t *s, MSVCRT_wchar_t **end, int base)
|
|
|
|
{
|
|
|
|
return MSVCRT__wcstoul_l(s, end, base, NULL);
|
|
|
|
}
|
|
|
|
|
2010-09-29 09:57:52 +02:00
|
|
|
/******************************************************************
|
|
|
|
* wcsnlen (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT_wcsnlen(const MSVCRT_wchar_t *s, MSVCRT_size_t maxlen)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < maxlen; i++)
|
|
|
|
if (!s[i]) break;
|
|
|
|
return i;
|
|
|
|
}
|
2011-05-12 11:36:56 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _towupper_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__towupper_l(MSVCRT_wint_t c, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return toupperW(c);
|
|
|
|
}
|
|
|
|
|
2013-03-27 16:12:52 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* towupper (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_towupper(MSVCRT_wint_t c)
|
|
|
|
{
|
|
|
|
return MSVCRT__towupper_l(c, NULL);
|
|
|
|
}
|
|
|
|
|
2011-05-12 11:36:56 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _towlower_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__towlower_l(MSVCRT_wint_t c, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return tolowerW(c);
|
|
|
|
}
|
2013-03-27 16:12:52 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* towlower (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_towlower(MSVCRT_wint_t c)
|
|
|
|
{
|
|
|
|
return MSVCRT__towlower_l(c, NULL);
|
|
|
|
}
|