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"
|
|
|
|
#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
|
|
|
|
2001-01-22 03:21:54 +01:00
|
|
|
|
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
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_wchar_t* CDECL _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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _wcsicoll (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL _wcsicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* FIXME: handle collates */
|
|
|
|
return strcmpiW( str1, str2 );
|
|
|
|
}
|
|
|
|
|
2010-12-03 18:12:23 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcsnicoll (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
INT CDECL _wcsnicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2, MSVCRT_size_t count )
|
|
|
|
{
|
|
|
|
/* FIXME: handle collates */
|
|
|
|
return strncmpiW( str1, str2, count );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_wchar_t* CDECL _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
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_wchar_t* CDECL _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;
|
|
|
|
}
|
|
|
|
|
2010-04-26 12:33:38 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcstod_l - not exported in native msvcrt
|
|
|
|
*/
|
|
|
|
double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end,
|
|
|
|
MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
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;
|
2010-07-22 12:35:08 +02:00
|
|
|
BOOL found_digit = FALSE;
|
2010-04-26 12:33:38 +02:00
|
|
|
|
2010-10-29 15:39:30 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) {
|
2010-04-26 12:33:38 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
locale = get_locale();
|
|
|
|
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
if(*p == *locale->locinfo->lconv->decimal_point)
|
|
|
|
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);
|
|
|
|
|
2010-04-26 12:33:38 +02:00
|
|
|
if(exp>0)
|
|
|
|
ret = (double)sign*d*pow(10, exp);
|
|
|
|
else
|
|
|
|
ret = (double)sign*d/pow(10, -exp);
|
|
|
|
|
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
|
|
|
/*********************************************************************
|
2010-05-06 14:27:57 +02:00
|
|
|
* _wcstombs_l (MSVCRT.@)
|
2010-04-27 08:42:46 +02:00
|
|
|
*/
|
2010-05-06 14:27:57 +02:00
|
|
|
MSVCRT_size_t CDECL MSVCRT__wcstombs_l(char *mbstr, const MSVCRT_wchar_t *wcstr,
|
2010-04-27 08:42:46 +02:00
|
|
|
MSVCRT_size_t count, MSVCRT__locale_t locale)
|
|
|
|
{
|
2010-05-06 14:27:57 +02:00
|
|
|
char default_char = '\0';
|
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)
|
|
|
|
locale = get_locale();
|
|
|
|
|
2010-05-24 10:03:55 +02:00
|
|
|
if(!mbstr)
|
|
|
|
return WideCharToMultiByte(locale->locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS,
|
|
|
|
wcstr, -1, NULL, 0, &default_char, &used_default)-1;
|
2010-04-27 08:42:46 +02:00
|
|
|
|
2010-05-24 10:03:55 +02:00
|
|
|
while(*wcstr) {
|
|
|
|
char buf[3];
|
|
|
|
MSVCRT_size_t i, size;
|
2010-04-27 08:42:46 +02:00
|
|
|
|
2010-05-24 10:03:55 +02:00
|
|
|
size = WideCharToMultiByte(locale->locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS,
|
|
|
|
wcstr, 1, buf, 3, &default_char, &used_default);
|
|
|
|
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];
|
|
|
|
wcstr++;
|
|
|
|
}
|
2010-05-06 14:27:57 +02:00
|
|
|
|
2010-05-24 10:03:55 +02:00
|
|
|
if(tmp < count)
|
|
|
|
mbstr[tmp] = '\0';
|
2010-05-06 14:27:57 +02:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* wcstombs (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT_wcstombs(char *mbstr, const MSVCRT_wchar_t *wcstr,
|
|
|
|
MSVCRT_size_t count)
|
|
|
|
{
|
|
|
|
return MSVCRT__wcstombs_l(mbstr, wcstr, count, NULL);
|
|
|
|
}
|
2010-04-27 08:42:46 +02:00
|
|
|
|
2010-05-06 14:27:57 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wcstombs_s_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT__wcstombs_s_l(MSVCRT_size_t *ret, char *mbstr,
|
|
|
|
MSVCRT_size_t size, const MSVCRT_wchar_t *wcstr,
|
|
|
|
MSVCRT_size_t count, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t conv;
|
|
|
|
|
|
|
|
if(!mbstr && !size) {
|
|
|
|
conv = MSVCRT__wcstombs_l(NULL, wcstr, 0, locale);
|
|
|
|
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
|
|
|
|
2010-10-29 15:39:36 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(wcstr != NULL) || !MSVCRT_CHECK_PMT(mbstr != NULL)) {
|
2010-05-06 14:27:57 +02:00
|
|
|
if(mbstr && size)
|
|
|
|
mbstr[0] = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
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;
|
|
|
|
|
|
|
|
conv = MSVCRT__wcstombs_l(mbstr, wcstr, conv, locale);
|
|
|
|
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 {
|
2010-10-29 15:39:36 +02:00
|
|
|
MSVCRT_INVALID_PMT("mbstr[size] is too small");
|
2010-05-06 14:27:57 +02:00
|
|
|
if(size)
|
|
|
|
mbstr[0] = '\0';
|
2010-04-27 08:42:46 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* wcstombs_s (MSVCRT.@)
|
|
|
|
*/
|
2010-05-06 14:27:57 +02:00
|
|
|
MSVCRT_size_t 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)
|
|
|
|
{
|
|
|
|
return MSVCRT__wcstombs_s_l(ret, mbstr, size, wcstr, count, NULL);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
typedef struct pf_flags_t
|
|
|
|
{
|
|
|
|
char Sign, LeftAlign, Alternate, PadZero;
|
2005-10-27 12:20:08 +02:00
|
|
|
int FieldLength, Precision;
|
2005-02-14 21:53:42 +01:00
|
|
|
char IntegerLength, IntegerDouble;
|
|
|
|
char WideString;
|
|
|
|
char Format;
|
|
|
|
} pf_flags;
|
|
|
|
|
2010-11-07 19:11:32 +01:00
|
|
|
static inline BOOL pf_is_auto_grow(pf_output *out)
|
|
|
|
{
|
|
|
|
return (out->unicode) ? !!out->grow.W : !!out->grow.A;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pf_check_auto_grow(pf_output *out, unsigned delta)
|
|
|
|
{
|
|
|
|
if (pf_is_auto_grow(out) && out->used + delta > out->len)
|
|
|
|
{
|
|
|
|
out->len = max(out->len * 2, out->used + delta);
|
|
|
|
if (out->unicode)
|
|
|
|
{
|
|
|
|
if (out->buf.W != out->grow.W)
|
|
|
|
out->buf.W = MSVCRT_realloc(out->buf.W, out->len * sizeof(WCHAR));
|
|
|
|
else
|
|
|
|
out->buf.W = MSVCRT_malloc(out->len * sizeof(WCHAR));
|
|
|
|
if (!out->buf.W) return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (out->buf.A != out->grow.A)
|
|
|
|
out->buf.A = MSVCRT_realloc(out->buf.A, out->len * sizeof(char));
|
|
|
|
else
|
|
|
|
out->buf.A = MSVCRT_malloc(out->len * sizeof(char));
|
|
|
|
if (!out->buf.A) return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
/*
|
|
|
|
* writes a string of characters to the output
|
|
|
|
* returns -1 if the string doesn't fit in the output buffer
|
|
|
|
* return the length of the string if all characters were written
|
|
|
|
*/
|
|
|
|
static inline int pf_output_stringW( pf_output *out, LPCWSTR str, int len )
|
2004-06-02 02:35:09 +02:00
|
|
|
{
|
2010-11-07 19:11:32 +01:00
|
|
|
int space;
|
2004-06-02 02:35:09 +02:00
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
if( len < 0 )
|
|
|
|
len = strlenW( str );
|
|
|
|
if( out->unicode )
|
2004-06-02 02:35:09 +02:00
|
|
|
{
|
2010-11-07 19:11:32 +01:00
|
|
|
LPWSTR p;
|
2005-02-14 21:53:42 +01:00
|
|
|
|
2010-11-07 19:11:32 +01:00
|
|
|
if(pf_check_auto_grow(out, len) == -1) return -1;
|
|
|
|
space = out->len - out->used;
|
|
|
|
p = out->buf.W + out->used;
|
2005-02-14 21:53:42 +01:00
|
|
|
if( space >= len )
|
2004-06-02 02:35:09 +02:00
|
|
|
{
|
2009-03-26 12:45:59 +01:00
|
|
|
if (out->buf.W) memcpy( p, str, len*sizeof(WCHAR) );
|
2005-02-14 21:53:42 +01:00
|
|
|
out->used += len;
|
|
|
|
return len;
|
2004-06-02 02:35:09 +02:00
|
|
|
}
|
2009-03-26 12:45:59 +01:00
|
|
|
if( space > 0 && out->buf.W )
|
2005-02-14 21:53:42 +01:00
|
|
|
memcpy( p, str, space*sizeof(WCHAR) );
|
|
|
|
out->used += len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int n = WideCharToMultiByte( CP_ACP, 0, str, len, NULL, 0, NULL, NULL );
|
2010-11-07 19:11:32 +01:00
|
|
|
LPSTR p;
|
2005-02-14 21:53:42 +01:00
|
|
|
|
2010-11-07 19:11:32 +01:00
|
|
|
if(pf_check_auto_grow(out, n) == -1) return -1;
|
|
|
|
space = out->len - out->used;
|
|
|
|
p = out->buf.A + out->used;
|
2005-02-14 21:53:42 +01:00
|
|
|
if( space >= n )
|
2004-06-02 02:35:09 +02:00
|
|
|
{
|
2009-03-26 12:45:59 +01:00
|
|
|
if (out->buf.A) WideCharToMultiByte( CP_ACP, 0, str, len, p, n, NULL, NULL );
|
2005-02-14 21:53:42 +01:00
|
|
|
out->used += n;
|
|
|
|
return len;
|
|
|
|
}
|
2009-03-26 12:45:59 +01:00
|
|
|
if( space > 0 && out->buf.A )
|
2005-02-14 21:53:42 +01:00
|
|
|
WideCharToMultiByte( CP_ACP, 0, str, len, p, space, NULL, NULL );
|
|
|
|
out->used += n;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2004-06-02 02:35:09 +02:00
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
static inline int pf_output_stringA( pf_output *out, LPCSTR str, int len )
|
|
|
|
{
|
2010-11-07 19:11:32 +01:00
|
|
|
int space;
|
2004-06-02 02:35:09 +02:00
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
if( len < 0 )
|
|
|
|
len = strlen( str );
|
|
|
|
if( !out->unicode )
|
|
|
|
{
|
2010-11-07 19:11:32 +01:00
|
|
|
LPSTR p;
|
2004-06-02 02:35:09 +02:00
|
|
|
|
2010-11-07 19:11:32 +01:00
|
|
|
if (pf_check_auto_grow(out, len) == -1) return -1;
|
|
|
|
p = out->buf.A + out->used;
|
|
|
|
space = out->len - out->used;
|
2005-02-14 21:53:42 +01:00
|
|
|
if( space >= len )
|
|
|
|
{
|
2009-03-26 12:45:59 +01:00
|
|
|
if (out->buf.A) memcpy( p, str, len );
|
2005-02-14 21:53:42 +01:00
|
|
|
out->used += len;
|
|
|
|
return len;
|
|
|
|
}
|
2009-03-26 12:45:59 +01:00
|
|
|
if( space > 0 && out->buf.A )
|
2005-02-14 21:53:42 +01:00
|
|
|
memcpy( p, str, space );
|
|
|
|
out->used += len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int n = MultiByteToWideChar( CP_ACP, 0, str, len, NULL, 0 );
|
2010-11-07 19:11:32 +01:00
|
|
|
LPWSTR p;
|
2004-06-02 02:35:09 +02:00
|
|
|
|
2010-11-07 19:11:32 +01:00
|
|
|
if (pf_check_auto_grow(out, n) == -1) return -1;
|
|
|
|
p = out->buf.W + out->used;
|
|
|
|
space = out->len - out->used;
|
2005-02-14 21:53:42 +01:00
|
|
|
if( space >= n )
|
|
|
|
{
|
2009-03-26 12:45:59 +01:00
|
|
|
if (out->buf.W) MultiByteToWideChar( CP_ACP, 0, str, len, p, n );
|
2005-02-14 21:53:42 +01:00
|
|
|
out->used += n;
|
|
|
|
return len;
|
|
|
|
}
|
2009-03-26 12:45:59 +01:00
|
|
|
if( space > 0 && out->buf.W )
|
2005-02-14 21:53:42 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, str, len, p, space );
|
|
|
|
out->used += n;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-11-14 04:55:02 +01:00
|
|
|
/* pf_fill: takes care of signs, alignment, zero and field padding */
|
2005-02-14 21:53:42 +01:00
|
|
|
static inline int pf_fill( pf_output *out, int len, pf_flags *flags, char left )
|
|
|
|
{
|
|
|
|
int i, r = 0;
|
|
|
|
|
2005-12-26 13:01:38 +01:00
|
|
|
if( flags->Sign && !( flags->Format == 'd' || flags->Format == 'i' ) )
|
|
|
|
flags->Sign = 0;
|
|
|
|
|
|
|
|
if( left && flags->Sign )
|
|
|
|
{
|
|
|
|
flags->FieldLength--;
|
|
|
|
if( flags->PadZero )
|
|
|
|
r = pf_output_stringA( out, &flags->Sign, 1 );
|
|
|
|
}
|
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
if( ( !left && flags->LeftAlign ) ||
|
2005-12-20 11:49:05 +01:00
|
|
|
( left && !flags->LeftAlign ))
|
2005-02-14 21:53:42 +01:00
|
|
|
{
|
|
|
|
for( i=0; (i<(flags->FieldLength-len)) && (r>=0); i++ )
|
|
|
|
{
|
2005-12-20 11:49:05 +01:00
|
|
|
if( left && flags->PadZero )
|
2005-02-14 21:53:42 +01:00
|
|
|
r = pf_output_stringA( out, "0", 1 );
|
|
|
|
else
|
|
|
|
r = pf_output_stringA( out, " ", 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-26 13:01:38 +01:00
|
|
|
if( left && flags->Sign && !flags->PadZero )
|
|
|
|
r = pf_output_stringA( out, &flags->Sign, 1 );
|
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pf_output_format_W( pf_output *out, LPCWSTR str,
|
|
|
|
int len, pf_flags *flags )
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
if( len < 0 )
|
|
|
|
len = strlenW( str );
|
|
|
|
|
2005-10-27 12:20:08 +02:00
|
|
|
if (flags->Precision >= 0 && flags->Precision < len)
|
|
|
|
len = flags->Precision;
|
2005-02-25 20:16:46 +01:00
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
r = pf_fill( out, len, flags, 1 );
|
|
|
|
|
|
|
|
if( r>=0 )
|
|
|
|
r = pf_output_stringW( out, str, len );
|
|
|
|
|
|
|
|
if( r>=0 )
|
|
|
|
r = pf_fill( out, len, flags, 0 );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pf_output_format_A( pf_output *out, LPCSTR str,
|
|
|
|
int len, pf_flags *flags )
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
if( len < 0 )
|
|
|
|
len = strlen( str );
|
|
|
|
|
2005-10-27 12:20:08 +02:00
|
|
|
if (flags->Precision >= 0 && flags->Precision < len)
|
|
|
|
len = flags->Precision;
|
2005-02-25 20:16:46 +01:00
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
r = pf_fill( out, len, flags, 1 );
|
|
|
|
|
|
|
|
if( r>=0 )
|
|
|
|
r = pf_output_stringA( out, str, len );
|
|
|
|
|
|
|
|
if( r>=0 )
|
|
|
|
r = pf_fill( out, len, flags, 0 );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-05-16 18:18:51 +02:00
|
|
|
static int pf_handle_string_format( pf_output *out, const void* str, int len,
|
|
|
|
pf_flags *flags, BOOL capital_letter)
|
|
|
|
{
|
|
|
|
if(str == NULL) /* catch NULL pointer */
|
|
|
|
return pf_output_format_A( out, "(null)", -1, flags);
|
|
|
|
|
|
|
|
/* prefixes take priority over %c,%s vs. %C,%S, so we handle them first */
|
|
|
|
if(flags->WideString || flags->IntegerLength == 'l')
|
|
|
|
return pf_output_format_W( out, str, len, flags);
|
|
|
|
if(flags->IntegerLength == 'h')
|
|
|
|
return pf_output_format_A( out, str, len, flags);
|
|
|
|
|
|
|
|
/* %s,%c -> chars in ansi functions & wchars in unicode
|
|
|
|
* %S,%C -> wchars in ansi functions & chars in unicode */
|
|
|
|
if( capital_letter == out->unicode) /* either both TRUE or both FALSE */
|
|
|
|
return pf_output_format_A( out, str, len, flags);
|
|
|
|
else
|
|
|
|
return pf_output_format_W( out, str, len, flags);
|
|
|
|
}
|
|
|
|
|
2005-12-26 13:01:38 +01:00
|
|
|
static inline BOOL pf_is_integer_format( char fmt )
|
|
|
|
{
|
|
|
|
static const char float_fmts[] = "diouxX";
|
|
|
|
if (!fmt)
|
|
|
|
return FALSE;
|
|
|
|
return strchr( float_fmts, fmt ) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
static inline BOOL pf_is_double_format( char fmt )
|
|
|
|
{
|
2005-12-19 21:26:46 +01:00
|
|
|
static const char float_fmts[] = "aeEfgG";
|
2005-02-14 21:53:42 +01:00
|
|
|
if (!fmt)
|
|
|
|
return FALSE;
|
|
|
|
return strchr( float_fmts, fmt ) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL pf_is_valid_format( char fmt )
|
|
|
|
{
|
2005-12-19 21:26:46 +01:00
|
|
|
static const char float_fmts[] = "acCdeEfgGinouxX";
|
2005-02-14 21:53:42 +01:00
|
|
|
if (!fmt)
|
|
|
|
return FALSE;
|
|
|
|
return strchr( float_fmts, fmt ) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pf_rebuild_format_string( char *p, pf_flags *flags )
|
|
|
|
{
|
|
|
|
*p++ = '%';
|
|
|
|
if( flags->Sign )
|
|
|
|
*p++ = flags->Sign;
|
|
|
|
if( flags->LeftAlign )
|
|
|
|
*p++ = flags->LeftAlign;
|
|
|
|
if( flags->Alternate )
|
|
|
|
*p++ = flags->Alternate;
|
|
|
|
if( flags->PadZero )
|
|
|
|
*p++ = flags->PadZero;
|
|
|
|
if( flags->FieldLength )
|
|
|
|
{
|
|
|
|
sprintf(p, "%d", flags->FieldLength);
|
|
|
|
p += strlen(p);
|
|
|
|
}
|
2005-10-27 12:20:08 +02:00
|
|
|
if( flags->Precision >= 0 )
|
2005-02-14 21:53:42 +01:00
|
|
|
{
|
|
|
|
sprintf(p, ".%d", flags->Precision);
|
|
|
|
p += strlen(p);
|
|
|
|
}
|
|
|
|
*p++ = flags->Format;
|
|
|
|
*p++ = 0;
|
|
|
|
}
|
|
|
|
|
2006-11-14 04:55:02 +01:00
|
|
|
/* pf_integer_conv: prints x to buf, including alternate formats and
|
|
|
|
additional precision digits, but not field characters or the sign */
|
|
|
|
static void pf_integer_conv( char *buf, int buf_len, pf_flags *flags,
|
|
|
|
LONGLONG x )
|
2005-12-26 13:01:38 +01:00
|
|
|
{
|
|
|
|
unsigned int base;
|
2006-06-05 21:50:47 +02:00
|
|
|
const char *digits;
|
2005-12-26 13:01:38 +01:00
|
|
|
|
|
|
|
int i, j, k;
|
2006-11-14 04:55:02 +01:00
|
|
|
char number[40], *tmp = number;
|
|
|
|
|
|
|
|
if( buf_len > sizeof number )
|
|
|
|
tmp = HeapAlloc( GetProcessHeap(), 0, buf_len );
|
2005-12-26 13:01:38 +01:00
|
|
|
|
|
|
|
base = 10;
|
|
|
|
if( flags->Format == 'o' )
|
|
|
|
base = 8;
|
|
|
|
else if( flags->Format == 'x' || flags->Format == 'X' )
|
|
|
|
base = 16;
|
|
|
|
|
|
|
|
if( flags->Format == 'X' )
|
|
|
|
digits = "0123456789ABCDEFX";
|
|
|
|
else
|
|
|
|
digits = "0123456789abcdefx";
|
|
|
|
|
|
|
|
if( x < 0 && ( flags->Format == 'd' || flags->Format == 'i' ) )
|
|
|
|
{
|
|
|
|
x = -x;
|
|
|
|
flags->Sign = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do conversion (backwards) */
|
|
|
|
i = 0;
|
|
|
|
if( x == 0 && flags->Precision )
|
|
|
|
tmp[i++] = '0';
|
|
|
|
else
|
|
|
|
while( x != 0 )
|
|
|
|
{
|
|
|
|
j = (ULONGLONG) x % base;
|
|
|
|
x = (ULONGLONG) x / base;
|
|
|
|
tmp[i++] = digits[j];
|
|
|
|
}
|
|
|
|
k = flags->Precision - i;
|
|
|
|
while( k-- > 0 )
|
|
|
|
tmp[i++] = '0';
|
|
|
|
if( flags->Alternate )
|
|
|
|
{
|
|
|
|
if( base == 16 )
|
|
|
|
{
|
|
|
|
tmp[i++] = digits[16];
|
|
|
|
tmp[i++] = '0';
|
|
|
|
}
|
|
|
|
else if( base == 8 && tmp[i-1] != '0' )
|
|
|
|
tmp[i++] = '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reverse for buf */
|
|
|
|
j = 0;
|
|
|
|
while( i-- > 0 )
|
|
|
|
buf[j++] = tmp[i];
|
|
|
|
buf[j] = '\0';
|
|
|
|
|
|
|
|
/* Adjust precision so pf_fill won't truncate the number later */
|
|
|
|
flags->Precision = strlen( buf );
|
|
|
|
|
2006-11-14 04:55:02 +01:00
|
|
|
if( tmp != number )
|
|
|
|
HeapFree( GetProcessHeap(), 0, tmp );
|
|
|
|
|
2005-12-26 13:01:38 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-13 19:35:37 +02:00
|
|
|
/* pf_fixup_exponent: convert a string containing a 2 digit exponent
|
|
|
|
to 3 digits, accounting for padding, in place. Needed to match
|
|
|
|
the native printf's which always use 3 digits. */
|
|
|
|
static void pf_fixup_exponent( char *buf )
|
|
|
|
{
|
|
|
|
char* tmp = buf;
|
|
|
|
|
|
|
|
while (tmp[0] && toupper(tmp[0]) != 'E')
|
|
|
|
tmp++;
|
|
|
|
|
|
|
|
if (tmp[0] && (tmp[1] == '+' || tmp[1] == '-') &&
|
|
|
|
isdigit(tmp[2]) && isdigit(tmp[3]))
|
|
|
|
{
|
|
|
|
char final;
|
|
|
|
|
|
|
|
if (isdigit(tmp[4]))
|
|
|
|
return; /* Exponent already 3 digits */
|
|
|
|
|
|
|
|
/* We have a 2 digit exponent. Prepend '0' to make it 3 */
|
|
|
|
tmp += 2;
|
|
|
|
final = tmp[2];
|
|
|
|
tmp[2] = tmp[1];
|
|
|
|
tmp[1] = tmp[0];
|
|
|
|
tmp[0] = '0';
|
|
|
|
if (final == '\0')
|
|
|
|
{
|
|
|
|
/* We didn't expand into trailing space, so this string isn't left
|
|
|
|
* justified. Terminate the string and strip a ' ' at the start of
|
|
|
|
* the string if there is one (as there may be if the string is
|
|
|
|
* right justified).
|
|
|
|
*/
|
|
|
|
tmp[3] = '\0';
|
|
|
|
if (buf[0] == ' ')
|
|
|
|
memmove(buf, buf + 1, (tmp - buf) + 3);
|
|
|
|
}
|
|
|
|
/* Otherwise, we expanded into trailing space -> nothing to do */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* pf_vsnprintf (INTERNAL)
|
|
|
|
*
|
|
|
|
* implements both A and W vsnprintf functions
|
|
|
|
*/
|
2010-11-07 19:11:32 +01:00
|
|
|
int pf_vsnprintf( pf_output *out, const WCHAR *format,
|
|
|
|
MSVCRT__locale_t locale, BOOL valid, __ms_va_list valist )
|
2005-02-14 21:53:42 +01:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
LPCWSTR q, p = format;
|
|
|
|
pf_flags flags;
|
|
|
|
|
2010-04-19 10:57:14 +02:00
|
|
|
if(!locale)
|
|
|
|
locale = get_locale();
|
|
|
|
|
2005-04-14 13:32:53 +02:00
|
|
|
TRACE("format is %s\n",debugstr_w(format));
|
2005-02-14 21:53:42 +01:00
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
q = strchrW( p, '%' );
|
|
|
|
|
|
|
|
/* there's no % characters left, output the rest of the string */
|
|
|
|
if( !q )
|
|
|
|
{
|
|
|
|
r = pf_output_stringW(out, p, -1);
|
|
|
|
if( r<0 )
|
|
|
|
return r;
|
|
|
|
p += r;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* there's characters before the %, output them */
|
|
|
|
if( q != p )
|
|
|
|
{
|
|
|
|
r = pf_output_stringW(out, p, q - p);
|
|
|
|
if( r<0 )
|
|
|
|
return r;
|
|
|
|
p = q;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we must be at a % now, skip over it */
|
|
|
|
assert( *p == '%' );
|
|
|
|
p++;
|
|
|
|
|
|
|
|
/* output a single % character */
|
|
|
|
if( *p == '%' )
|
|
|
|
{
|
2005-05-10 10:27:38 +02:00
|
|
|
r = pf_output_stringW(out, p++, 1);
|
2005-02-14 21:53:42 +01:00
|
|
|
if( r<0 )
|
|
|
|
return r;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse the flags */
|
|
|
|
memset( &flags, 0, sizeof flags );
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if( *p == '+' || *p == ' ' )
|
2005-12-21 20:07:03 +01:00
|
|
|
{
|
|
|
|
if ( flags.Sign != '+' )
|
|
|
|
flags.Sign = *p;
|
|
|
|
}
|
2005-02-14 21:53:42 +01:00
|
|
|
else if( *p == '-' )
|
|
|
|
flags.LeftAlign = *p;
|
|
|
|
else if( *p == '0' )
|
|
|
|
flags.PadZero = *p;
|
|
|
|
else if( *p == '#' )
|
|
|
|
flags.Alternate = *p;
|
|
|
|
else
|
2004-06-02 02:35:09 +02:00
|
|
|
break;
|
2005-02-14 21:53:42 +01:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* deal with the field width specifier */
|
|
|
|
flags.FieldLength = 0;
|
2007-01-29 23:53:46 +01:00
|
|
|
if( *p == '*' )
|
2005-04-14 13:32:53 +02:00
|
|
|
{
|
2005-02-14 21:53:42 +01:00
|
|
|
flags.FieldLength = va_arg( valist, int );
|
2007-01-29 23:53:46 +01:00
|
|
|
if (flags.FieldLength < 0)
|
|
|
|
{
|
|
|
|
flags.LeftAlign = '-';
|
|
|
|
flags.FieldLength = -flags.FieldLength;
|
|
|
|
}
|
2005-04-14 13:32:53 +02:00
|
|
|
p++;
|
|
|
|
}
|
2005-02-14 21:53:42 +01:00
|
|
|
else while( isdigit(*p) )
|
|
|
|
{
|
|
|
|
flags.FieldLength *= 10;
|
|
|
|
flags.FieldLength += *p++ - '0';
|
|
|
|
}
|
2004-06-02 02:35:09 +02:00
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
/* deal with precision */
|
2005-10-27 12:20:08 +02:00
|
|
|
flags.Precision = -1;
|
2005-02-14 21:53:42 +01:00
|
|
|
if( *p == '.' )
|
|
|
|
{
|
2005-10-27 12:20:08 +02:00
|
|
|
flags.Precision = 0;
|
2005-02-14 21:53:42 +01:00
|
|
|
p++;
|
|
|
|
if( *p == '*' )
|
2005-02-25 20:16:46 +01:00
|
|
|
{
|
2005-02-14 21:53:42 +01:00
|
|
|
flags.Precision = va_arg( valist, int );
|
2005-02-25 20:16:46 +01:00
|
|
|
p++;
|
|
|
|
}
|
2005-02-14 21:53:42 +01:00
|
|
|
else while( isdigit(*p) )
|
2004-06-02 02:35:09 +02:00
|
|
|
{
|
2005-02-14 21:53:42 +01:00
|
|
|
flags.Precision *= 10;
|
|
|
|
flags.Precision += *p++ - '0';
|
2004-06-02 02:35:09 +02:00
|
|
|
}
|
2005-02-14 21:53:42 +01:00
|
|
|
}
|
2004-06-02 02:35:09 +02:00
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
/* deal with integer width modifier */
|
|
|
|
while( *p )
|
|
|
|
{
|
2010-09-23 15:28:32 +02:00
|
|
|
if( *p == 'l' && *(p+1) == 'l' )
|
|
|
|
{
|
|
|
|
flags.IntegerDouble++;
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
else if( *p == 'h' || *p == 'l' || *p == 'L' )
|
2004-06-02 02:35:09 +02:00
|
|
|
{
|
2005-12-26 13:00:35 +01:00
|
|
|
flags.IntegerLength = *p;
|
2005-02-14 21:53:42 +01:00
|
|
|
p++;
|
2004-06-02 02:35:09 +02:00
|
|
|
}
|
2005-12-26 13:00:01 +01:00
|
|
|
else if( *p == 'I' )
|
|
|
|
{
|
|
|
|
if( *(p+1) == '6' && *(p+2) == '4' )
|
|
|
|
{
|
|
|
|
flags.IntegerDouble++;
|
|
|
|
p += 3;
|
|
|
|
}
|
|
|
|
else if( *(p+1) == '3' && *(p+2) == '2' )
|
|
|
|
p += 3;
|
|
|
|
else if( isdigit(*(p+1)) || *(p+1) == 0 )
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
p++;
|
|
|
|
}
|
2005-02-14 21:53:42 +01:00
|
|
|
else if( *p == 'w' )
|
|
|
|
flags.WideString = *p++;
|
2005-03-04 11:47:27 +01:00
|
|
|
else if( *p == 'F' )
|
|
|
|
p++; /* ignore */
|
2005-02-14 21:53:42 +01:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.Format = *p;
|
|
|
|
r = 0;
|
|
|
|
|
2008-10-18 13:59:47 +02:00
|
|
|
if (flags.Format == '$')
|
|
|
|
{
|
|
|
|
FIXME("Positional parameters are not supported (%s)\n", wine_dbgstr_w(format));
|
|
|
|
return -1;
|
|
|
|
}
|
2006-05-16 18:18:51 +02:00
|
|
|
/* output a string */
|
|
|
|
if( flags.Format == 's' || flags.Format == 'S' )
|
|
|
|
r = pf_handle_string_format( out, va_arg(valist, const void*), -1,
|
|
|
|
&flags, (flags.Format == 'S') );
|
2005-02-14 21:53:42 +01:00
|
|
|
|
2006-05-16 18:18:51 +02:00
|
|
|
/* output a single character */
|
|
|
|
else if( flags.Format == 'c' || flags.Format == 'C' )
|
2005-02-14 21:53:42 +01:00
|
|
|
{
|
2006-05-16 18:18:51 +02:00
|
|
|
INT ch = va_arg( valist, int );
|
2005-02-14 21:53:42 +01:00
|
|
|
|
2006-05-16 18:18:51 +02:00
|
|
|
r = pf_handle_string_format( out, &ch, 1, &flags, (flags.Format == 'C') );
|
2005-02-14 21:53:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* output a pointer */
|
|
|
|
else if( flags.Format == 'p' )
|
|
|
|
{
|
2009-01-02 21:33:33 +01:00
|
|
|
char pointer[32];
|
|
|
|
void *ptr = va_arg( valist, void * );
|
2005-02-14 21:53:42 +01:00
|
|
|
|
|
|
|
flags.PadZero = 0;
|
|
|
|
if( flags.Alternate )
|
2009-01-08 13:12:24 +01:00
|
|
|
sprintf(pointer, "0X%0*lX", 2 * (int)sizeof(ptr), (ULONG_PTR)ptr);
|
2005-02-14 21:53:42 +01:00
|
|
|
else
|
2009-01-08 13:12:24 +01:00
|
|
|
sprintf(pointer, "%0*lX", 2 * (int)sizeof(ptr), (ULONG_PTR)ptr);
|
2005-02-14 21:53:42 +01:00
|
|
|
r = pf_output_format_A( out, pointer, -1, &flags );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* deal with %n */
|
|
|
|
else if( flags.Format == 'n' )
|
|
|
|
{
|
|
|
|
int *x = va_arg(valist, int *);
|
|
|
|
*x = out->used;
|
2004-06-02 02:35:09 +02:00
|
|
|
}
|
2005-02-14 21:53:42 +01:00
|
|
|
|
2005-12-26 13:01:38 +01:00
|
|
|
/* deal with 64-bit integers */
|
|
|
|
else if( pf_is_integer_format( flags.Format ) && flags.IntegerDouble )
|
|
|
|
{
|
|
|
|
char number[40], *x = number;
|
|
|
|
|
2006-11-14 04:55:02 +01:00
|
|
|
/* Estimate largest possible required buffer size:
|
|
|
|
* Chooses the larger of the field or precision
|
|
|
|
* Includes extra bytes: 1 byte for null, 1 byte for sign,
|
|
|
|
4 bytes for exponent, 2 bytes for alternate formats, 1 byte
|
|
|
|
for a decimal, and 1 byte for an additional float digit. */
|
|
|
|
int x_len = ((flags.FieldLength > flags.Precision) ?
|
|
|
|
flags.FieldLength : flags.Precision) + 10;
|
2005-12-26 13:01:38 +01:00
|
|
|
|
2006-11-14 04:55:02 +01:00
|
|
|
if( x_len >= sizeof number)
|
|
|
|
x = HeapAlloc( GetProcessHeap(), 0, x_len );
|
|
|
|
|
|
|
|
pf_integer_conv( x, x_len, &flags, va_arg(valist, LONGLONG) );
|
2005-12-26 13:01:38 +01:00
|
|
|
|
|
|
|
r = pf_output_format_A( out, x, -1, &flags );
|
|
|
|
if( x != number )
|
2006-11-14 04:51:17 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, x );
|
2005-12-26 13:01:38 +01:00
|
|
|
}
|
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
/* deal with integers and floats using libc's printf */
|
|
|
|
else if( pf_is_valid_format( flags.Format ) )
|
|
|
|
{
|
2010-04-19 10:57:14 +02:00
|
|
|
char fmt[20], number[40], *x = number, *decimal_point;
|
2005-02-14 21:53:42 +01:00
|
|
|
|
2006-11-14 04:55:02 +01:00
|
|
|
/* Estimate largest possible required buffer size:
|
|
|
|
* Chooses the larger of the field or precision
|
|
|
|
* Includes extra bytes: 1 byte for null, 1 byte for sign,
|
|
|
|
4 bytes for exponent, 2 bytes for alternate formats, 1 byte
|
|
|
|
for a decimal, and 1 byte for an additional float digit. */
|
|
|
|
int x_len = ((flags.FieldLength > flags.Precision) ?
|
|
|
|
flags.FieldLength : flags.Precision) + 10;
|
|
|
|
|
|
|
|
if( x_len >= sizeof number)
|
|
|
|
x = HeapAlloc( GetProcessHeap(), 0, x_len );
|
2005-02-14 21:53:42 +01:00
|
|
|
|
|
|
|
pf_rebuild_format_string( fmt, &flags );
|
|
|
|
|
|
|
|
if( pf_is_double_format( flags.Format ) )
|
2008-07-13 19:35:37 +02:00
|
|
|
{
|
2005-10-28 11:40:16 +02:00
|
|
|
sprintf( x, fmt, va_arg(valist, double) );
|
2008-07-13 19:35:37 +02:00
|
|
|
if (toupper(flags.Format) == 'E' || toupper(flags.Format) == 'G')
|
|
|
|
pf_fixup_exponent( x );
|
|
|
|
}
|
2005-02-14 21:53:42 +01:00
|
|
|
else
|
2005-10-28 11:40:16 +02:00
|
|
|
sprintf( x, fmt, va_arg(valist, int) );
|
2005-02-14 21:53:42 +01:00
|
|
|
|
2010-04-19 10:57:14 +02:00
|
|
|
decimal_point = strchr(x, '.');
|
|
|
|
if(decimal_point)
|
|
|
|
*decimal_point = *locale->locinfo->lconv->decimal_point;
|
|
|
|
|
2005-10-28 11:40:16 +02:00
|
|
|
r = pf_output_stringA( out, x, -1 );
|
2005-02-14 21:53:42 +01:00
|
|
|
if( x != number )
|
2006-11-14 04:51:17 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, x );
|
2010-04-19 10:57:31 +02:00
|
|
|
if(r < 0)
|
|
|
|
return r;
|
2005-02-14 21:53:42 +01:00
|
|
|
}
|
|
|
|
else
|
2010-04-19 10:57:31 +02:00
|
|
|
{
|
|
|
|
if( valid )
|
|
|
|
{
|
|
|
|
MSVCRT__invalid_parameter( NULL, NULL, NULL, 0, 0 );
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
continue;
|
2010-04-19 10:57:31 +02:00
|
|
|
}
|
2005-02-14 21:53:42 +01:00
|
|
|
|
|
|
|
if( r<0 )
|
|
|
|
return r;
|
|
|
|
p++;
|
2004-06-02 02:35:09 +02:00
|
|
|
}
|
2005-02-14 21:53:42 +01:00
|
|
|
|
|
|
|
/* check we reached the end, and null terminate the string */
|
|
|
|
assert( *p == 0 );
|
2006-01-14 17:30:02 +01:00
|
|
|
pf_output_stringW( out, p, 1 );
|
2005-02-14 21:53:42 +01:00
|
|
|
|
|
|
|
return out->used - 1;
|
2004-06-02 02:35:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2010-04-19 10:57:40 +02:00
|
|
|
* vsnprintf_internal (INTERNAL)
|
2004-06-02 02:35:09 +02:00
|
|
|
*/
|
2010-04-19 10:57:40 +02:00
|
|
|
static inline int vsnprintf_internal( char *str, MSVCRT_size_t len, const char *format,
|
|
|
|
MSVCRT__locale_t locale, BOOL valid, __ms_va_list valist )
|
2005-02-14 21:53:42 +01:00
|
|
|
{
|
|
|
|
DWORD sz;
|
|
|
|
LPWSTR formatW = NULL;
|
|
|
|
pf_output out;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
out.unicode = FALSE;
|
|
|
|
out.buf.A = str;
|
2010-11-07 19:11:32 +01:00
|
|
|
out.grow.A = NULL;
|
2005-02-14 21:53:42 +01:00
|
|
|
out.used = 0;
|
|
|
|
out.len = len;
|
|
|
|
|
2009-12-04 10:10:48 +01:00
|
|
|
sz = MultiByteToWideChar( CP_ACP, 0, format, -1, NULL, 0 );
|
|
|
|
formatW = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, format, -1, formatW, sz );
|
2005-02-14 21:53:42 +01:00
|
|
|
|
2010-04-19 10:57:40 +02:00
|
|
|
r = pf_vsnprintf( &out, formatW, locale, valid, valist );
|
2005-02-14 21:53:42 +01:00
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, formatW );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
return vsnprintf_internal(str, len, format, NULL, FALSE, valist);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _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 )
|
|
|
|
{
|
|
|
|
return vsnprintf_internal(str, len, format, locale, FALSE, valist);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _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 )
|
|
|
|
{
|
|
|
|
int len, ret;
|
|
|
|
|
|
|
|
if(sizeOfBuffer<count+1 || count==-1)
|
|
|
|
len = sizeOfBuffer;
|
|
|
|
else
|
|
|
|
len = count+1;
|
|
|
|
|
|
|
|
ret = vsnprintf_internal(str, len, format, locale, TRUE, valist);
|
|
|
|
|
|
|
|
if(ret<0 || ret==len) {
|
2010-06-06 17:11:09 +02:00
|
|
|
if(count!=MSVCRT__TRUNCATE && count>sizeOfBuffer) {
|
2010-10-29 15:39:42 +02:00
|
|
|
MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small");
|
2010-04-19 10:57:40 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
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.@)
|
|
|
|
*/
|
|
|
|
int CDECL _vscprintf( const char *format, __ms_va_list valist )
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
retval = _vscprintf(format, valist);
|
|
|
|
__ms_va_end(valist);
|
2010-06-10 21:12:20 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2005-02-14 21:53:42 +01:00
|
|
|
/*********************************************************************
|
2010-06-06 16:19:14 +02:00
|
|
|
* vsnwprintf_internal (INTERNAL)
|
2005-02-14 21:53:42 +01:00
|
|
|
*/
|
2010-04-19 10:57:50 +02:00
|
|
|
static inline int vsnwprintf_internal(MSVCRT_wchar_t *str, MSVCRT_size_t len,
|
|
|
|
const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, BOOL valid,
|
|
|
|
__ms_va_list valist)
|
2005-02-14 21:53:42 +01:00
|
|
|
{
|
|
|
|
pf_output out;
|
|
|
|
|
|
|
|
out.unicode = TRUE;
|
|
|
|
out.buf.W = str;
|
2010-11-07 19:11:32 +01:00
|
|
|
out.grow.W = NULL;
|
2005-02-14 21:53:42 +01:00
|
|
|
out.used = 0;
|
|
|
|
out.len = len;
|
|
|
|
|
2010-04-19 10:57:50 +02:00
|
|
|
return pf_vsnprintf( &out, format, locale, valid, valist );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
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)
|
|
|
|
{
|
|
|
|
return vsnwprintf_internal(str, len, format, NULL, FALSE, valist);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
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)
|
|
|
|
{
|
|
|
|
return vsnwprintf_internal(str, len, format, locale, FALSE, valist);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
ret = vsnwprintf_internal(str, len, format, locale, TRUE, valist);
|
|
|
|
|
|
|
|
if(ret<0 || ret==len) {
|
2010-06-07 03:54:14 +02:00
|
|
|
if(count!=MSVCRT__TRUNCATE && count>sizeOfBuffer) {
|
2010-10-29 15:39:42 +02:00
|
|
|
MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small");
|
2010-04-19 10:57:50 +02:00
|
|
|
*MSVCRT__errno() = 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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-01-22 03:21:54 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* vswprintf (MSVCRT.@)
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2009-03-26 12:45:59 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _vscwprintf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _vscwprintf( const MSVCRT_wchar_t *format, __ms_va_list args )
|
|
|
|
{
|
|
|
|
return MSVCRT_vsnwprintf( NULL, INT_MAX, format, 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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
/* FIXME: handle collates */
|
|
|
|
return strcmpW( str1, str2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
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
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
const MSVCRT_wchar_t* p;
|
2001-01-11 00:59:25 +01:00
|
|
|
while (*str)
|
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
for (p = accept; *p; p++) if (*p == *str) return (MSVCRT_wchar_t*)str;
|
2001-01-11 00:59:25 +01:00
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2010-11-02 22:03:59 +01:00
|
|
|
if (!MSVCRT_CHECK_PMT(delim != NULL) || !MSVCRT_CHECK_PMT(next_token != NULL) ||
|
|
|
|
!MSVCRT_CHECK_PMT(str != NULL || *next_token != NULL))
|
|
|
|
{
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* wctomb (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
INT CDECL MSVCRT_wctomb( char *dst, MSVCRT_wchar_t ch )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return WideCharToMultiByte( CP_ACP, 0, &ch, 1, dst, 6, NULL, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
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
|
|
|
|
2008-05-26 17:21:13 +02:00
|
|
|
if(!wcDest || !numElement)
|
2008-02-27 09:58:04 +01:00
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
|
2008-05-26 17:21:13 +02:00
|
|
|
wcDest[0] = 0;
|
|
|
|
|
2008-02-27 09:58:04 +01:00
|
|
|
if(!wcSrc)
|
|
|
|
{
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = strlenW(wcSrc) + 1;
|
|
|
|
|
|
|
|
if(size > numElement)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* 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 )
|
|
|
|
{
|
2008-10-21 22:44:27 +02:00
|
|
|
MSVCRT_size_t size = 0;
|
2008-10-02 22:00:34 +02:00
|
|
|
|
|
|
|
if (!wcDest || !numElement)
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
|
|
|
|
wcDest[0] = 0;
|
|
|
|
|
|
|
|
if (!wcSrc)
|
|
|
|
{
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = min(strlenW(wcSrc), count);
|
|
|
|
|
|
|
|
if (size >= numElement)
|
|
|
|
{
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
|
|
|
|
wcDest[size] = '\0';
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
|
2010-11-15 22:00:10 +01:00
|
|
|
if (!MSVCRT_CHECK_PMT(dst != NULL) || !MSVCRT_CHECK_PMT(elem > 0))
|
|
|
|
{
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
2010-10-18 14:06:16 +02:00
|
|
|
return MSVCRT_EINVAL;
|
2010-11-15 22:00:10 +01:00
|
|
|
}
|
|
|
|
if (!MSVCRT_CHECK_PMT(src != NULL || count == 0))
|
2010-10-18 14:06:16 +02:00
|
|
|
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
|
|
|
{
|
|
|
|
MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n");
|
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
|
|
|
}
|
2010-11-15 22:00:10 +01:00
|
|
|
MSVCRT_INVALID_PMT("dst[elem] is too small");
|
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);
|
|
|
|
|
2010-10-29 15:39:30 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(nptr != NULL) || !MSVCRT_CHECK_PMT(base == 0 || base >= 2) ||
|
|
|
|
!MSVCRT_CHECK_PMT(base <= 36)) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
2010-04-27 08:42:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
char cur = tolowerW(*nptr);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
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);
|
|
|
|
|
2010-10-29 15:39:30 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(nptr != NULL) || !MSVCRT_CHECK_PMT(base == 0 || base >= 2) ||
|
|
|
|
!MSVCRT_CHECK_PMT(base <= 36)) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
2010-04-27 08:42:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
char cur = tolowerW(*nptr);
|
|
|
|
int v;
|
|
|
|
|
|
|
|
if(isdigit(cur)) {
|
|
|
|
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
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* 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;
|
|
|
|
}
|