2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* MSVCRT string functions
|
|
|
|
*
|
|
|
|
* Copyright 1996,1998 Marcus Meissner
|
|
|
|
* Copyright 1996 Jukka Iivonen
|
|
|
|
* Copyright 1997,2000 Uwe Bonnes
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2006-12-17 18:56:50 +01:00
|
|
|
#define _ISOC99_SOURCE
|
|
|
|
#include "config.h"
|
2010-04-26 12:33:28 +02:00
|
|
|
#include "wine/port.h"
|
2006-12-17 18:56:50 +01:00
|
|
|
|
2006-01-14 17:40:29 +01:00
|
|
|
#include <stdlib.h>
|
2010-05-14 12:14:12 +02:00
|
|
|
#include <stdio.h>
|
2010-04-26 12:33:28 +02:00
|
|
|
#include <math.h>
|
|
|
|
#include <limits.h>
|
2009-08-31 21:36:45 +02:00
|
|
|
#include <errno.h>
|
2001-04-23 20:20:55 +02:00
|
|
|
#include "msvcrt.h"
|
2011-05-12 11:39:10 +02:00
|
|
|
#include "winnls.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-07-11 20:56:41 +02:00
|
|
|
* _mbsdup (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
* _strdup (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
char* CDECL MSVCRT__strdup(const char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2006-06-21 10:55:11 +02:00
|
|
|
if(str)
|
|
|
|
{
|
|
|
|
char * ret = MSVCRT_malloc(strlen(str)+1);
|
|
|
|
if (ret) strcpy( ret, str );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else return 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2010-10-11 12:25:23 +02:00
|
|
|
/*********************************************************************
|
2011-05-12 11:38:41 +02:00
|
|
|
* _strlwr_s_l (MSVCRT.@)
|
2010-10-11 12:25:23 +02:00
|
|
|
*/
|
2011-05-12 11:38:41 +02:00
|
|
|
int CDECL _strlwr_s_l(char *str, MSVCRT_size_t len, MSVCRT__locale_t locale)
|
2010-10-11 12:25:23 +02:00
|
|
|
{
|
|
|
|
char *ptr = str;
|
|
|
|
|
|
|
|
if (!str || !len)
|
|
|
|
{
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (len && *ptr)
|
|
|
|
{
|
|
|
|
len--;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
{
|
|
|
|
str[0] = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*str)
|
|
|
|
{
|
2011-06-03 15:28:56 +02:00
|
|
|
*str = MSVCRT__tolower_l((unsigned char)*str, locale);
|
2010-10-11 12:25:23 +02:00
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-12 11:38:41 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _strlwr_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _strlwr_s(char *str, MSVCRT_size_t len)
|
|
|
|
{
|
|
|
|
return _strlwr_s_l(str, len, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strlwr_l (MSVCRT.@)
|
|
|
|
*/
|
2011-05-16 16:22:46 +02:00
|
|
|
char* CDECL _strlwr_l(char *str, MSVCRT__locale_t locale)
|
2011-05-12 11:38:41 +02:00
|
|
|
{
|
2011-05-16 16:22:46 +02:00
|
|
|
_strlwr_s_l(str, -1, locale);
|
|
|
|
return str;
|
2011-05-12 11:38:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strlwr (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
char* CDECL MSVCRT__strlwr(char *str)
|
2011-05-12 11:38:41 +02:00
|
|
|
{
|
2011-05-16 16:22:46 +02:00
|
|
|
_strlwr_s_l(str, -1, NULL);
|
|
|
|
return str;
|
2011-05-12 11:38:41 +02:00
|
|
|
}
|
|
|
|
|
2011-05-12 11:38:52 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _strupr_s_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _strupr_s_l(char *str, MSVCRT_size_t len, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
char *ptr = str;
|
|
|
|
|
|
|
|
if (!str || !len)
|
|
|
|
{
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (len && *ptr)
|
|
|
|
{
|
|
|
|
len--;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
{
|
|
|
|
str[0] = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*str)
|
|
|
|
{
|
2011-06-03 15:28:56 +02:00
|
|
|
*str = MSVCRT__toupper_l((unsigned char)*str, locale);
|
2011-05-12 11:38:52 +02:00
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strupr_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _strupr_s(char *str, MSVCRT_size_t len)
|
|
|
|
{
|
|
|
|
return _strupr_s_l(str, len, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strupr_l (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
char* CDECL MSVCRT__strupr_l(char *str, MSVCRT__locale_t locale)
|
2011-05-12 11:38:52 +02:00
|
|
|
{
|
2011-05-16 16:22:46 +02:00
|
|
|
_strupr_s_l(str, -1, locale);
|
|
|
|
return str;
|
2011-05-12 11:38:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strupr (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
char* CDECL MSVCRT__strupr(char *str)
|
2011-05-12 11:38:52 +02:00
|
|
|
{
|
2011-05-16 16:22:46 +02:00
|
|
|
_strupr_s_l(str, -1, NULL);
|
|
|
|
return str;
|
2011-05-12 11:38:52 +02:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _strnset (MSVCRT.@)
|
|
|
|
*/
|
2010-03-29 00:00:26 +02:00
|
|
|
char* CDECL MSVCRT__strnset(char* str, int value, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (len > 0 && str)
|
|
|
|
while (*str && len--)
|
|
|
|
*str++ = value;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strrev (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
char* CDECL MSVCRT__strrev(char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char * p1;
|
|
|
|
char * p2;
|
|
|
|
|
|
|
|
if (str && *str)
|
|
|
|
for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
|
|
|
|
{
|
|
|
|
*p1 ^= *p2;
|
|
|
|
*p2 ^= *p1;
|
|
|
|
*p1 ^= *p2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strset (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
char* CDECL _strset(char* str, int value)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char *ptr = str;
|
|
|
|
while (*ptr)
|
|
|
|
*ptr++ = value;
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:24:49 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strtok (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
char * CDECL MSVCRT_strtok( char *str, const char *delim )
|
2006-01-14 17:24:49 +01:00
|
|
|
{
|
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
if (!(str = data->strtok_next)) return NULL;
|
|
|
|
|
|
|
|
while (*str && strchr( delim, *str )) str++;
|
|
|
|
if (!*str) return NULL;
|
|
|
|
ret = str++;
|
|
|
|
while (*str && !strchr( delim, *str )) str++;
|
|
|
|
if (*str) *str++ = 0;
|
|
|
|
data->strtok_next = str;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-26 14:09:59 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* strtok_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
char * CDECL MSVCRT_strtok_s(char *str, const char *delim, char **ctx)
|
|
|
|
{
|
2010-10-29 15:39:14 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(delim != NULL) || !MSVCRT_CHECK_PMT(ctx != NULL) ||
|
|
|
|
!MSVCRT_CHECK_PMT(str != NULL || *ctx != NULL)) {
|
2010-04-26 14:09:59 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!str)
|
|
|
|
str = *ctx;
|
|
|
|
|
|
|
|
while(*str && strchr(delim, *str))
|
|
|
|
str++;
|
|
|
|
if(!*str)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*ctx = str+1;
|
|
|
|
while(**ctx && !strchr(delim, **ctx))
|
|
|
|
(*ctx)++;
|
|
|
|
if(**ctx)
|
|
|
|
*(*ctx)++ = 0;
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
2006-01-14 17:24:49 +01:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _swab (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void CDECL MSVCRT__swab(char* src, char* dst, int len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (len > 1)
|
|
|
|
{
|
|
|
|
len = (unsigned)len >> 1;
|
|
|
|
|
|
|
|
while (len--) {
|
2005-08-19 12:01:42 +02:00
|
|
|
char s0 = src[0];
|
|
|
|
char s1 = src[1];
|
|
|
|
*dst++ = s1;
|
|
|
|
*dst++ = s0;
|
|
|
|
src = src + 2;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-01-14 17:40:29 +01:00
|
|
|
|
2010-04-21 11:26:22 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* strtod_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t locale)
|
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
2010-04-26 12:33:28 +02:00
|
|
|
unsigned __int64 d=0, hlp;
|
2010-05-09 15:07:33 +02:00
|
|
|
unsigned fpcontrol;
|
2010-04-26 12:33:28 +02:00
|
|
|
int exp=0, sign=1;
|
|
|
|
const char *p;
|
2010-04-21 11:26:22 +02:00
|
|
|
double ret;
|
2010-07-22 12:35:08 +02:00
|
|
|
BOOL found_digit = FALSE;
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2010-10-29 15:39:25 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) {
|
2010-04-21 11:26:22 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-26 12:33:28 +02:00
|
|
|
if(!locale)
|
2011-05-24 17:22:32 +02:00
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
2010-04-26 12:33:28 +02:00
|
|
|
|
2010-04-21 11:26:22 +02:00
|
|
|
/* FIXME: use *_l functions */
|
|
|
|
p = str;
|
|
|
|
while(isspace(*p))
|
|
|
|
p++;
|
2010-04-26 12:33:28 +02:00
|
|
|
|
|
|
|
if(*p == '-') {
|
|
|
|
sign = -1;
|
2010-04-21 11:26:22 +02:00
|
|
|
p++;
|
2010-04-26 12:33:28 +02:00
|
|
|
} else if(*p == '+')
|
2010-04-21 11:26:22 +02:00
|
|
|
p++;
|
2010-04-26 12:33:28 +02:00
|
|
|
|
|
|
|
while(isdigit(*p)) {
|
2010-07-22 12:35:08 +02:00
|
|
|
found_digit = TRUE;
|
2010-04-26 12:33:28 +02:00
|
|
|
hlp = d*10+*(p++)-'0';
|
|
|
|
if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
|
|
|
|
exp++;
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
d = hlp;
|
|
|
|
}
|
|
|
|
while(isdigit(*p)) {
|
|
|
|
exp++;
|
2010-04-21 11:26:22 +02:00
|
|
|
p++;
|
|
|
|
}
|
2010-04-26 12:33:28 +02:00
|
|
|
|
2011-05-24 17:22:32 +02:00
|
|
|
if(*p == *locinfo->lconv->decimal_point)
|
2010-04-21 11:26:22 +02:00
|
|
|
p++;
|
|
|
|
|
2010-04-26 12:33:28 +02:00
|
|
|
while(isdigit(*p)) {
|
2010-07-22 12:35:08 +02:00
|
|
|
found_digit = TRUE;
|
2010-04-26 12:33:28 +02:00
|
|
|
hlp = d*10+*(p++)-'0';
|
|
|
|
if(d>MSVCRT_UI64_MAX/10 || hlp<d)
|
|
|
|
break;
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2010-04-26 12:33:28 +02:00
|
|
|
d = hlp;
|
|
|
|
exp--;
|
|
|
|
}
|
|
|
|
while(isdigit(*p))
|
|
|
|
p++;
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2010-07-22 12:35:08 +02:00
|
|
|
if(!found_digit) {
|
2010-04-21 11:26:22 +02:00
|
|
|
if(end)
|
2010-04-26 12:33:28 +02:00
|
|
|
*end = (char*)str;
|
|
|
|
return 0.0;
|
|
|
|
}
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2010-04-26 12:33:28 +02:00
|
|
|
if(*p=='e' || *p=='E' || *p=='d' || *p=='D') {
|
|
|
|
int e=0, s=1;
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2010-04-26 12:33:28 +02:00
|
|
|
p++;
|
|
|
|
if(*p == '-') {
|
|
|
|
s = -1;
|
|
|
|
p++;
|
|
|
|
} else if(*p == '+')
|
|
|
|
p++;
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2010-04-26 12:33:28 +02:00
|
|
|
if(isdigit(*p)) {
|
|
|
|
while(isdigit(*p)) {
|
|
|
|
if(e>INT_MAX/10 || (e=e*10+*p-'0')<0)
|
|
|
|
e = INT_MAX;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
e *= s;
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2010-04-26 12:33:28 +02:00
|
|
|
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:28 +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:28 +02:00
|
|
|
if((d && ret==0.0) || isinf(ret))
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
|
|
|
|
if(end)
|
|
|
|
*end = (char*)p;
|
|
|
|
|
|
|
|
return ret;
|
2010-04-21 11:26:22 +02:00
|
|
|
}
|
|
|
|
|
2006-01-14 17:40:29 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strtod (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_strtod( const char *str, char **end )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
2010-04-21 11:26:22 +02:00
|
|
|
return MSVCRT_strtod_l( str, end, NULL );
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
2010-04-26 12:33:49 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* atof (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCRT_atof( const char *str )
|
|
|
|
{
|
|
|
|
return MSVCRT_strtod_l(str, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _atof_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCRT__atof_l( const char *str, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return MSVCRT_strtod_l(str, NULL, locale);
|
|
|
|
}
|
|
|
|
|
2011-01-18 17:06:07 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _atoflt_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__atoflt_l( MSVCRT__CRT_FLOAT *value, char *str, MSVCRT__locale_t locale)
|
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
2011-01-18 17:06:07 +01:00
|
|
|
unsigned __int64 d=0, hlp;
|
|
|
|
unsigned fpcontrol;
|
|
|
|
int exp=0, sign=1;
|
|
|
|
const char *p;
|
|
|
|
int ret=0;
|
|
|
|
BOOL found_digit = FALSE;
|
|
|
|
|
|
|
|
if(!locale)
|
2011-05-24 17:22:32 +02:00
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
2011-01-18 17:06:07 +01:00
|
|
|
|
|
|
|
/* FIXME: use *_l functions */
|
|
|
|
p = str;
|
|
|
|
while(isspace(*p))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
if(*p == '-') {
|
|
|
|
sign = -1;
|
|
|
|
p++;
|
|
|
|
} else if(*p == '+')
|
|
|
|
p++;
|
|
|
|
|
|
|
|
while(isdigit(*p)) {
|
|
|
|
found_digit = TRUE;
|
|
|
|
hlp = d*10+*(p++)-'0';
|
|
|
|
if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
|
|
|
|
exp++;
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
d = hlp;
|
|
|
|
}
|
|
|
|
while(isdigit(*p)) {
|
|
|
|
exp++;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
2011-05-24 17:22:32 +02:00
|
|
|
if(*p == *locinfo->lconv->decimal_point)
|
2011-01-18 17:06:07 +01:00
|
|
|
p++;
|
|
|
|
|
|
|
|
while(isdigit(*p)) {
|
|
|
|
found_digit = TRUE;
|
|
|
|
hlp = d*10+*(p++)-'0';
|
|
|
|
if(d>MSVCRT_UI64_MAX/10 || hlp<d)
|
|
|
|
break;
|
|
|
|
|
|
|
|
d = hlp;
|
|
|
|
exp--;
|
|
|
|
}
|
|
|
|
while(isdigit(*p))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
if(!found_digit) {
|
|
|
|
value->f = 0.0;
|
|
|
|
return 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(isdigit(*p)) {
|
|
|
|
while(isdigit(*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--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fpcontrol = _control87(0, 0);
|
|
|
|
_control87(MSVCRT__EM_DENORMAL|MSVCRT__EM_INVALID|MSVCRT__EM_ZERODIVIDE
|
|
|
|
|MSVCRT__EM_OVERFLOW|MSVCRT__EM_UNDERFLOW|MSVCRT__EM_INEXACT, 0xffffffff);
|
|
|
|
|
|
|
|
if(exp>0)
|
|
|
|
value->f = (float)sign*d*powf(10, exp);
|
|
|
|
else
|
|
|
|
value->f = (float)sign*d/powf(10, -exp);
|
|
|
|
|
|
|
|
_control87(fpcontrol, 0xffffffff);
|
|
|
|
|
|
|
|
if((d && value->f==0.0) || isinf(value->f))
|
|
|
|
ret = exp > 0 ? MSVCRT__OVERFLOW : MSVCRT__UNDERFLOW;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-12 11:39:10 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _strcoll_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_strcoll_l( const char* str1, const char* str2, MSVCRT__locale_t locale )
|
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
|
2011-05-12 11:39:10 +02:00
|
|
|
if(!locale)
|
2011-05-24 17:22:32 +02:00
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
2011-05-12 11:39:10 +02:00
|
|
|
|
2011-05-24 17:22:32 +02:00
|
|
|
return CompareStringA(locinfo->lc_handle[MSVCRT_LC_CTYPE], 0, str1, -1, str2, -1)-2;
|
2011-05-12 11:39:10 +02:00
|
|
|
}
|
|
|
|
|
2006-01-14 17:40:29 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strcoll (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL MSVCRT_strcoll( const char* str1, const char* str2 )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
2011-05-12 11:39:10 +02:00
|
|
|
return MSVCRT_strcoll_l(str1, str2, NULL);
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
2011-05-12 11:39:22 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _stricoll_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__stricoll_l( const char* str1, const char* str2, MSVCRT__locale_t locale )
|
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
|
2011-05-12 11:39:22 +02:00
|
|
|
if(!locale)
|
2011-05-24 17:22:32 +02:00
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
2011-05-12 11:39:22 +02:00
|
|
|
|
2011-05-24 17:22:32 +02:00
|
|
|
return CompareStringA(locinfo->lc_handle[MSVCRT_LC_CTYPE], NORM_IGNORECASE,
|
2011-05-12 11:39:22 +02:00
|
|
|
str1, -1, str2, -1)-2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _stricoll (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__stricoll( const char* str1, const char* str2 )
|
|
|
|
{
|
|
|
|
return MSVCRT__stricoll_l(str1, str2, NULL);
|
|
|
|
}
|
|
|
|
|
2011-05-12 11:39:31 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _strncoll_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_strncoll_l( const char* str1, const char* str2, MSVCRT_size_t count, MSVCRT__locale_t locale )
|
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
|
2011-05-12 11:39:31 +02:00
|
|
|
if(!locale)
|
2011-05-24 17:22:32 +02:00
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
2011-05-12 11:39:31 +02:00
|
|
|
|
2011-05-24 17:22:32 +02:00
|
|
|
return CompareStringA(locinfo->lc_handle[MSVCRT_LC_CTYPE], 0, str1, count, str2, count)-2;
|
2011-05-12 11:39:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strncoll (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_strncoll( const char* str1, const char* str2, MSVCRT_size_t count )
|
|
|
|
{
|
|
|
|
return MSVCRT_strncoll_l(str1, str2, count, NULL);
|
|
|
|
}
|
|
|
|
|
2011-05-12 11:39:43 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _strnicoll_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__strnicoll_l( const char* str1, const char* str2, MSVCRT_size_t count, MSVCRT__locale_t locale )
|
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
|
2011-05-12 11:39:43 +02:00
|
|
|
if(!locale)
|
2011-05-24 17:22:32 +02:00
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
2011-05-12 11:39:43 +02:00
|
|
|
|
2011-05-24 17:22:32 +02:00
|
|
|
return CompareStringA(locinfo->lc_handle[MSVCRT_LC_CTYPE], NORM_IGNORECASE,
|
2011-05-12 11:39:43 +02:00
|
|
|
str1, count, str2, count)-2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strnicoll (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__strnicoll( const char* str1, const char* str2, MSVCRT_size_t count )
|
|
|
|
{
|
|
|
|
return MSVCRT__strnicoll_l(str1, str2, count, NULL);
|
|
|
|
}
|
|
|
|
|
2007-11-15 16:11:26 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strcpy_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_strcpy_s( char* dst, MSVCRT_size_t elem, const char* src )
|
|
|
|
{
|
|
|
|
MSVCRT_size_t i;
|
2008-02-27 12:26:15 +01:00
|
|
|
if(!elem) return MSVCRT_EINVAL;
|
|
|
|
if(!dst) return MSVCRT_EINVAL;
|
2007-11-15 16:11:26 +01:00
|
|
|
if(!src)
|
|
|
|
{
|
|
|
|
dst[0] = '\0';
|
2008-02-27 12:26:15 +01:00
|
|
|
return MSVCRT_EINVAL;
|
2007-11-15 16:11:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < elem; i++)
|
|
|
|
{
|
|
|
|
if((dst[i] = src[i]) == '\0') return 0;
|
|
|
|
}
|
|
|
|
dst[0] = '\0';
|
2008-02-27 12:26:15 +01:00
|
|
|
return MSVCRT_ERANGE;
|
2007-11-15 16:11:26 +01:00
|
|
|
}
|
|
|
|
|
2007-11-16 11:36:03 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strcat_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_strcat_s( char* dst, MSVCRT_size_t elem, const char* src )
|
|
|
|
{
|
|
|
|
MSVCRT_size_t i, j;
|
2008-02-27 12:26:15 +01:00
|
|
|
if(!dst) return MSVCRT_EINVAL;
|
|
|
|
if(elem == 0) return MSVCRT_EINVAL;
|
2007-11-16 11:36:03 +01:00
|
|
|
if(!src)
|
|
|
|
{
|
|
|
|
dst[0] = '\0';
|
2008-02-27 12:26:15 +01:00
|
|
|
return MSVCRT_EINVAL;
|
2007-11-16 11:36:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < elem; i++)
|
|
|
|
{
|
|
|
|
if(dst[i] == '\0')
|
|
|
|
{
|
|
|
|
for(j = 0; (j + i) < elem; j++)
|
|
|
|
{
|
|
|
|
if((dst[j + i] = src[j]) == '\0') return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Set the first element to 0, not the first element after the skipped part */
|
|
|
|
dst[0] = '\0';
|
2008-02-27 12:26:15 +01:00
|
|
|
return MSVCRT_ERANGE;
|
2007-11-16 11:36:03 +01:00
|
|
|
}
|
|
|
|
|
2010-11-15 01:04:42 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strncat_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_strncat_s( char* dst, MSVCRT_size_t elem, const char* src, MSVCRT_size_t count )
|
|
|
|
{
|
|
|
|
MSVCRT_size_t i, j;
|
|
|
|
if(!MSVCRT_CHECK_PMT(dst != 0) || !MSVCRT_CHECK_PMT(elem != 0))
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
if(!MSVCRT_CHECK_PMT(src != 0))
|
|
|
|
{
|
|
|
|
dst[0] = '\0';
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < elem; i++)
|
|
|
|
{
|
|
|
|
if(dst[i] == '\0')
|
|
|
|
{
|
|
|
|
for(j = 0; (j + i) < elem; j++)
|
|
|
|
{
|
|
|
|
if(count == MSVCRT__TRUNCATE && j + i == elem - 1)
|
|
|
|
{
|
|
|
|
dst[j + i] = '\0';
|
|
|
|
return MSVCRT_STRUNCATE;
|
|
|
|
}
|
|
|
|
if(j == count || (dst[j + i] = src[j]) == '\0')
|
|
|
|
{
|
|
|
|
dst[j + i] = '\0';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Set the first element to 0, not the first element after the skipped part */
|
|
|
|
dst[0] = '\0';
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:40:29 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strxfrm (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_size_t CDECL MSVCRT_strxfrm( char *dest, const char *src, MSVCRT_size_t len )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
|
|
|
/* FIXME: handle Windows locale */
|
|
|
|
return strxfrm( dest, src, len );
|
|
|
|
}
|
|
|
|
|
2006-12-17 18:56:50 +01:00
|
|
|
/********************************************************************
|
|
|
|
* _atoldbl (MSVCRT.@)
|
|
|
|
*/
|
2007-09-19 17:52:40 +02:00
|
|
|
int CDECL MSVCRT__atoldbl(MSVCRT__LDOUBLE *value, const char *str)
|
2006-12-17 18:56:50 +01:00
|
|
|
{
|
|
|
|
/* FIXME needs error checking for huge/small values */
|
|
|
|
#ifdef HAVE_STRTOLD
|
2010-12-01 22:26:26 +01:00
|
|
|
long double ld;
|
2006-12-17 18:56:50 +01:00
|
|
|
TRACE("str %s value %p\n",str,value);
|
2010-12-01 22:26:26 +01:00
|
|
|
ld = strtold(str,0);
|
|
|
|
memcpy(value, &ld, 10);
|
2006-12-17 18:56:50 +01:00
|
|
|
#else
|
|
|
|
FIXME("stub, str %s value %p\n",str,value);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
2007-09-19 17:52:40 +02:00
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* __STRINGTOLD (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL __STRINGTOLD( MSVCRT__LDOUBLE *value, char **endptr, const char *str, int flags )
|
|
|
|
{
|
|
|
|
#ifdef HAVE_STRTOLD
|
2010-12-01 22:26:26 +01:00
|
|
|
long double ld;
|
2007-09-19 17:52:40 +02:00
|
|
|
FIXME("%p %p %s %x partial stub\n", value, endptr, str, flags );
|
2010-12-01 22:26:26 +01:00
|
|
|
ld = strtold(str,0);
|
|
|
|
memcpy(value, &ld, 10);
|
2007-09-19 17:52:40 +02:00
|
|
|
#else
|
|
|
|
FIXME("%p %p %s %x stub\n", value, endptr, str, flags );
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-31 21:36:45 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* strtol (MSVCRT.@)
|
|
|
|
*/
|
2009-09-01 22:34:50 +02:00
|
|
|
MSVCRT_long CDECL MSVCRT_strtol(const char* nptr, char** end, int base)
|
2009-08-31 21:36:45 +02:00
|
|
|
{
|
|
|
|
/* wrapper to forward libc error code to msvcrt's error codes */
|
|
|
|
long ret;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
ret = strtol(nptr, end, base);
|
|
|
|
switch (errno)
|
|
|
|
{
|
|
|
|
case ERANGE: *MSVCRT__errno() = MSVCRT_ERANGE; break;
|
|
|
|
case EINVAL: *MSVCRT__errno() = MSVCRT_EINVAL; break;
|
|
|
|
default:
|
|
|
|
/* cope with the fact that we may use 64bit long integers on libc
|
|
|
|
* while msvcrt always uses 32bit long integers
|
|
|
|
*/
|
|
|
|
if (ret > MSVCRT_LONG_MAX)
|
|
|
|
{
|
|
|
|
ret = MSVCRT_LONG_MAX;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
else if (ret < -MSVCRT_LONG_MAX - 1)
|
|
|
|
{
|
|
|
|
ret = -MSVCRT_LONG_MAX - 1;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* strtoul (MSVCRT.@)
|
|
|
|
*/
|
2009-09-01 22:34:50 +02:00
|
|
|
MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base)
|
2009-08-31 21:36:45 +02:00
|
|
|
{
|
|
|
|
/* wrapper to forward libc error code to msvcrt's error codes */
|
|
|
|
unsigned long ret;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
ret = strtoul(nptr, end, base);
|
|
|
|
switch (errno)
|
|
|
|
{
|
|
|
|
case ERANGE: *MSVCRT__errno() = MSVCRT_ERANGE; break;
|
|
|
|
case EINVAL: *MSVCRT__errno() = MSVCRT_EINVAL; break;
|
|
|
|
default:
|
|
|
|
/* cope with the fact that we may use 64bit long integers on libc
|
|
|
|
* while msvcrt always uses 32bit long integers
|
|
|
|
*/
|
|
|
|
if (ret > MSVCRT_ULONG_MAX)
|
|
|
|
{
|
|
|
|
ret = MSVCRT_ULONG_MAX;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-03-24 22:39:28 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* strnlen (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT_strnlen(const char *s, MSVCRT_size_t maxlen)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t i;
|
|
|
|
|
|
|
|
for(i=0; i<maxlen; i++)
|
|
|
|
if(!s[i]) break;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
2010-03-29 00:04:03 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
2010-04-28 17:44:51 +02:00
|
|
|
* _strtoi64_l (MSVCRT.@)
|
2010-03-29 00:04:03 +02:00
|
|
|
*
|
|
|
|
* FIXME: locale parameter is ignored
|
|
|
|
*/
|
|
|
|
__int64 CDECL MSVCRT_strtoi64_l(const char *nptr, char **endptr, int base, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
BOOL negative = FALSE;
|
|
|
|
__int64 ret = 0;
|
|
|
|
|
|
|
|
TRACE("(%s %p %d %p)\n", nptr, endptr, base, locale);
|
|
|
|
|
2010-10-29 15:39:25 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(nptr != NULL) || !MSVCRT_CHECK_PMT(base == 0 || base >= 2) ||
|
|
|
|
!MSVCRT_CHECK_PMT(base <= 36)) {
|
2010-03-29 00:04:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(isspace(*nptr)) nptr++;
|
|
|
|
|
|
|
|
if(*nptr == '-') {
|
|
|
|
negative = TRUE;
|
|
|
|
nptr++;
|
|
|
|
} else if(*nptr == '+')
|
|
|
|
nptr++;
|
|
|
|
|
|
|
|
if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') {
|
|
|
|
base = 16;
|
|
|
|
nptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(base == 0) {
|
|
|
|
if(*nptr=='0')
|
|
|
|
base = 8;
|
|
|
|
else
|
|
|
|
base = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(*nptr) {
|
|
|
|
char cur = tolower(*nptr);
|
|
|
|
int v;
|
|
|
|
|
|
|
|
if(isdigit(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;
|
2010-04-27 08:42:32 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
2010-03-29 00:04:03 +02:00
|
|
|
} else if(negative && (ret<MSVCRT_I64_MIN/base || ret*base<MSVCRT_I64_MIN-v)) {
|
|
|
|
ret = MSVCRT_I64_MIN;
|
2010-04-27 08:42:32 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
2010-03-29 00:04:03 +02:00
|
|
|
} else
|
|
|
|
ret = ret*base + v;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(endptr)
|
|
|
|
*endptr = (char*)nptr;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2010-04-28 17:44:51 +02:00
|
|
|
* _strtoi64 (MSVCRT.@)
|
2010-03-29 00:04:03 +02:00
|
|
|
*/
|
|
|
|
__int64 CDECL MSVCRT_strtoi64(const char *nptr, char **endptr, int base)
|
|
|
|
{
|
|
|
|
return MSVCRT_strtoi64_l(nptr, endptr, base, NULL);
|
|
|
|
}
|
2010-03-29 00:04:32 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
2010-04-28 17:44:51 +02:00
|
|
|
* _strtoui64_l (MSVCRT.@)
|
2010-03-29 00:04:32 +02:00
|
|
|
*
|
|
|
|
* FIXME: locale parameter is ignored
|
|
|
|
*/
|
|
|
|
unsigned __int64 CDECL MSVCRT_strtoui64_l(const char *nptr, char **endptr, int base, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
BOOL negative = FALSE;
|
|
|
|
unsigned __int64 ret = 0;
|
|
|
|
|
|
|
|
TRACE("(%s %p %d %p)\n", nptr, endptr, base, locale);
|
|
|
|
|
2010-10-29 15:39:25 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(nptr != NULL) || !MSVCRT_CHECK_PMT(base == 0 || base >= 2) ||
|
|
|
|
!MSVCRT_CHECK_PMT(base <= 36)) {
|
2010-03-29 00:04:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(isspace(*nptr)) nptr++;
|
|
|
|
|
|
|
|
if(*nptr == '-') {
|
|
|
|
negative = TRUE;
|
|
|
|
nptr++;
|
|
|
|
} else if(*nptr == '+')
|
|
|
|
nptr++;
|
|
|
|
|
|
|
|
if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') {
|
|
|
|
base = 16;
|
|
|
|
nptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(base == 0) {
|
|
|
|
if(*nptr=='0')
|
|
|
|
base = 8;
|
|
|
|
else
|
|
|
|
base = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(*nptr) {
|
|
|
|
char cur = tolower(*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;
|
2010-04-27 08:42:32 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
2010-03-29 00:04:32 +02:00
|
|
|
} else
|
|
|
|
ret = ret*base + v;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(endptr)
|
|
|
|
*endptr = (char*)nptr;
|
|
|
|
|
|
|
|
return negative ? -ret : ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2010-04-28 17:44:51 +02:00
|
|
|
* _strtoui64 (MSVCRT.@)
|
2010-03-29 00:04:32 +02:00
|
|
|
*/
|
|
|
|
unsigned __int64 CDECL MSVCRT_strtoui64(const char *nptr, char **endptr, int base)
|
|
|
|
{
|
|
|
|
return MSVCRT_strtoui64_l(nptr, endptr, base, NULL);
|
|
|
|
}
|
2010-05-05 13:37:33 +02:00
|
|
|
|
2010-10-11 12:25:15 +02:00
|
|
|
/*********************************************************************
|
2010-11-15 21:59:55 +01:00
|
|
|
* _ltoa_s (MSVCRT.@)
|
2010-10-11 12:25:15 +02:00
|
|
|
*/
|
2010-11-15 21:59:55 +01:00
|
|
|
int CDECL _ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
|
2010-10-11 12:25:15 +02:00
|
|
|
{
|
2010-11-15 21:59:55 +01:00
|
|
|
MSVCRT_ulong val;
|
|
|
|
unsigned int digit;
|
2010-10-11 12:25:15 +02:00
|
|
|
int is_negative;
|
|
|
|
char buffer[33], *pos;
|
|
|
|
size_t len;
|
|
|
|
|
2010-11-11 22:30:25 +01:00
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
|
|
|
|
!MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
|
2010-10-11 12:25:15 +02:00
|
|
|
{
|
|
|
|
if (str && size)
|
|
|
|
str[0] = '\0';
|
|
|
|
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value < 0 && radix == 10)
|
|
|
|
{
|
|
|
|
is_negative = 1;
|
|
|
|
val = -value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
is_negative = 0;
|
|
|
|
val = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = buffer + 32;
|
|
|
|
*pos = '\0';
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
digit = val % radix;
|
|
|
|
val /= radix;
|
|
|
|
|
|
|
|
if (digit < 10)
|
|
|
|
*--pos = '0' + digit;
|
|
|
|
else
|
|
|
|
*--pos = 'a' + digit - 10;
|
|
|
|
}
|
|
|
|
while (val != 0);
|
|
|
|
|
|
|
|
if (is_negative)
|
|
|
|
*--pos = '-';
|
|
|
|
|
|
|
|
len = buffer + 33 - pos;
|
|
|
|
if (len > size)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
char *p = str;
|
|
|
|
|
|
|
|
/* Copy the temporary buffer backwards up to the available number of
|
|
|
|
* characters. Don't copy the negative sign if present. */
|
|
|
|
|
|
|
|
if (is_negative)
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pos = buffer + 31, i = 0; i < size; i++)
|
|
|
|
*p++ = *pos--;
|
|
|
|
|
|
|
|
str[0] = '\0';
|
2010-11-11 22:30:25 +01:00
|
|
|
MSVCRT_INVALID_PMT("str[size] is too small");
|
2010-10-11 12:25:15 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(str, pos, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-02 22:02:52 +01:00
|
|
|
/*********************************************************************
|
2010-11-15 21:59:55 +01:00
|
|
|
* _ltow_s (MSVCRT.@)
|
2010-11-02 22:02:52 +01:00
|
|
|
*/
|
2010-11-15 21:59:55 +01:00
|
|
|
int CDECL _ltow_s(MSVCRT_long value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
|
2010-11-02 22:02:52 +01:00
|
|
|
{
|
2010-11-15 21:59:55 +01:00
|
|
|
MSVCRT_ulong val;
|
|
|
|
unsigned int digit;
|
2010-11-02 22:02:52 +01:00
|
|
|
int is_negative;
|
|
|
|
MSVCRT_wchar_t buffer[33], *pos;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
|
|
|
|
!MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
|
|
|
|
{
|
|
|
|
if (str && size)
|
|
|
|
str[0] = '\0';
|
|
|
|
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value < 0 && radix == 10)
|
|
|
|
{
|
|
|
|
is_negative = 1;
|
|
|
|
val = -value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
is_negative = 0;
|
|
|
|
val = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = buffer + 32;
|
|
|
|
*pos = '\0';
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
digit = val % radix;
|
|
|
|
val /= radix;
|
|
|
|
|
|
|
|
if (digit < 10)
|
|
|
|
*--pos = '0' + digit;
|
|
|
|
else
|
|
|
|
*--pos = 'a' + digit - 10;
|
|
|
|
}
|
|
|
|
while (val != 0);
|
|
|
|
|
|
|
|
if (is_negative)
|
|
|
|
*--pos = '-';
|
|
|
|
|
|
|
|
len = buffer + 33 - pos;
|
|
|
|
if (len > size)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
MSVCRT_wchar_t *p = str;
|
|
|
|
|
|
|
|
/* Copy the temporary buffer backwards up to the available number of
|
|
|
|
* characters. Don't copy the negative sign if present. */
|
|
|
|
|
|
|
|
if (is_negative)
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pos = buffer + 31, i = 0; i < size; i++)
|
|
|
|
*p++ = *pos--;
|
|
|
|
|
|
|
|
MSVCRT_INVALID_PMT("str[size] is too small");
|
|
|
|
str[0] = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(str, pos, len * sizeof(MSVCRT_wchar_t));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-15 21:59:55 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _itoa_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _itoa_s(int value, char *str, MSVCRT_size_t size, int radix)
|
|
|
|
{
|
|
|
|
return _ltoa_s(value, str, size, radix);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _itow_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _itow_s(int value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
|
|
|
|
{
|
|
|
|
return _ltow_s(value, str, size, radix);
|
|
|
|
}
|
|
|
|
|
2010-05-05 13:37:33 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _ui64toa_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__ui64toa_s(unsigned __int64 value, char *str,
|
|
|
|
MSVCRT_size_t size, int radix)
|
|
|
|
{
|
|
|
|
char buffer[65], *pos;
|
|
|
|
int digit;
|
|
|
|
|
2010-11-11 22:30:25 +01:00
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
|
|
|
|
!MSVCRT_CHECK_PMT(radix>=2) || !MSVCRT_CHECK_PMT(radix<=36)) {
|
2010-05-05 13:37:33 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = buffer+64;
|
|
|
|
*pos = '\0';
|
|
|
|
|
|
|
|
do {
|
|
|
|
digit = value%radix;
|
|
|
|
value /= radix;
|
|
|
|
|
|
|
|
if(digit < 10)
|
|
|
|
*--pos = '0'+digit;
|
|
|
|
else
|
|
|
|
*--pos = 'a'+digit-10;
|
|
|
|
}while(value != 0);
|
|
|
|
|
|
|
|
if(buffer-pos+65 > size) {
|
2010-11-11 22:30:25 +01:00
|
|
|
MSVCRT_INVALID_PMT("str[size] is too small");
|
2010-05-05 13:37:33 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(str, pos, buffer-pos+65);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-05-14 12:14:12 +02:00
|
|
|
|
2010-12-29 08:13:53 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ui64tow_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__ui64tow_s( unsigned __int64 value, MSVCRT_wchar_t *str,
|
|
|
|
MSVCRT_size_t size, int radix )
|
|
|
|
{
|
|
|
|
MSVCRT_wchar_t buffer[65], *pos;
|
|
|
|
int digit;
|
|
|
|
|
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
|
|
|
|
!MSVCRT_CHECK_PMT(radix>=2) || !MSVCRT_CHECK_PMT(radix<=36)) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = &buffer[64];
|
|
|
|
*pos = '\0';
|
|
|
|
|
|
|
|
do {
|
|
|
|
digit = value % radix;
|
|
|
|
value = value / radix;
|
|
|
|
if (digit < 10)
|
|
|
|
*--pos = '0' + digit;
|
|
|
|
else
|
|
|
|
*--pos = 'a' + digit - 10;
|
|
|
|
} while (value != 0);
|
|
|
|
|
|
|
|
if(buffer-pos+65 > size) {
|
|
|
|
MSVCRT_INVALID_PMT("str[size] is too small");
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(str, pos, buffer-pos+65);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-21 09:57:44 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _ultoa_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _ultoa_s(MSVCRT_ulong value, char *str, MSVCRT_size_t size, int radix)
|
|
|
|
{
|
|
|
|
MSVCRT_ulong digit;
|
|
|
|
char buffer[33], *pos;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (!str || !size || radix < 2 || radix > 36)
|
|
|
|
{
|
|
|
|
if (str && size)
|
|
|
|
str[0] = '\0';
|
|
|
|
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = buffer + 32;
|
|
|
|
*pos = '\0';
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
digit = value % radix;
|
|
|
|
value /= radix;
|
|
|
|
|
|
|
|
if (digit < 10)
|
|
|
|
*--pos = '0' + digit;
|
|
|
|
else
|
|
|
|
*--pos = 'a' + digit - 10;
|
|
|
|
}
|
|
|
|
while (value != 0);
|
|
|
|
|
|
|
|
len = buffer + 33 - pos;
|
|
|
|
if (len > size)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
char *p = str;
|
|
|
|
|
|
|
|
/* Copy the temporary buffer backwards up to the available number of
|
|
|
|
* characters. */
|
|
|
|
|
|
|
|
for (pos = buffer + 31, i = 0; i < size; i++)
|
|
|
|
*p++ = *pos--;
|
|
|
|
|
|
|
|
str[0] = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(str, pos, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-15 22:00:01 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _i64toa_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _i64toa_s(__int64 value, char *str, MSVCRT_size_t size, int radix)
|
|
|
|
{
|
|
|
|
unsigned __int64 val;
|
|
|
|
unsigned int digit;
|
|
|
|
int is_negative;
|
|
|
|
char buffer[65], *pos;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
|
|
|
|
!MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
|
|
|
|
{
|
|
|
|
if (str && size)
|
|
|
|
str[0] = '\0';
|
|
|
|
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value < 0 && radix == 10)
|
|
|
|
{
|
|
|
|
is_negative = 1;
|
|
|
|
val = -value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
is_negative = 0;
|
|
|
|
val = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = buffer + 64;
|
|
|
|
*pos = '\0';
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
digit = val % radix;
|
|
|
|
val /= radix;
|
|
|
|
|
|
|
|
if (digit < 10)
|
|
|
|
*--pos = '0' + digit;
|
|
|
|
else
|
|
|
|
*--pos = 'a' + digit - 10;
|
|
|
|
}
|
|
|
|
while (val != 0);
|
|
|
|
|
|
|
|
if (is_negative)
|
|
|
|
*--pos = '-';
|
|
|
|
|
|
|
|
len = buffer + 65 - pos;
|
|
|
|
if (len > size)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
char *p = str;
|
|
|
|
|
|
|
|
/* Copy the temporary buffer backwards up to the available number of
|
|
|
|
* characters. Don't copy the negative sign if present. */
|
|
|
|
|
|
|
|
if (is_negative)
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pos = buffer + 63, i = 0; i < size; i++)
|
|
|
|
*p++ = *pos--;
|
|
|
|
|
|
|
|
str[0] = '\0';
|
|
|
|
MSVCRT_INVALID_PMT("str[size] is too small");
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(str, pos, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _i64tow_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _i64tow_s(__int64 value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
|
|
|
|
{
|
|
|
|
unsigned __int64 val;
|
|
|
|
unsigned int digit;
|
|
|
|
int is_negative;
|
|
|
|
MSVCRT_wchar_t buffer[65], *pos;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
|
|
|
|
!MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
|
|
|
|
{
|
|
|
|
if (str && size)
|
|
|
|
str[0] = '\0';
|
|
|
|
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value < 0 && radix == 10)
|
|
|
|
{
|
|
|
|
is_negative = 1;
|
|
|
|
val = -value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
is_negative = 0;
|
|
|
|
val = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = buffer + 64;
|
|
|
|
*pos = '\0';
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
digit = val % radix;
|
|
|
|
val /= radix;
|
|
|
|
|
|
|
|
if (digit < 10)
|
|
|
|
*--pos = '0' + digit;
|
|
|
|
else
|
|
|
|
*--pos = 'a' + digit - 10;
|
|
|
|
}
|
|
|
|
while (val != 0);
|
|
|
|
|
|
|
|
if (is_negative)
|
|
|
|
*--pos = '-';
|
|
|
|
|
|
|
|
len = buffer + 65 - pos;
|
|
|
|
if (len > size)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
MSVCRT_wchar_t *p = str;
|
|
|
|
|
|
|
|
/* Copy the temporary buffer backwards up to the available number of
|
|
|
|
* characters. Don't copy the negative sign if present. */
|
|
|
|
|
|
|
|
if (is_negative)
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pos = buffer + 63, i = 0; i < size; i++)
|
|
|
|
*p++ = *pos--;
|
|
|
|
|
|
|
|
MSVCRT_INVALID_PMT("str[size] is too small");
|
|
|
|
str[0] = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(str, pos, len * sizeof(MSVCRT_wchar_t));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-14 12:14:12 +02:00
|
|
|
#define I10_OUTPUT_MAX_PREC 21
|
|
|
|
/* Internal structure used by $I10_OUTPUT */
|
|
|
|
struct _I10_OUTPUT_DATA {
|
|
|
|
short pos;
|
|
|
|
char sign;
|
|
|
|
BYTE len;
|
|
|
|
char str[I10_OUTPUT_MAX_PREC+1]; /* add space for '\0' */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* $I10_OUTPUT (MSVCRT.@)
|
2010-12-01 22:26:26 +01:00
|
|
|
* ld80 - long double (Intel 80 bit FP in 12 bytes) to be printed to data
|
2010-05-14 12:14:12 +02:00
|
|
|
* prec - precision of part, we're interested in
|
|
|
|
* flag - 0 for first prec digits, 1 for fractional part
|
|
|
|
* data - data to be populated
|
|
|
|
*
|
|
|
|
* return value
|
|
|
|
* 0 if given double is NaN or INF
|
|
|
|
* 1 otherwise
|
|
|
|
*
|
|
|
|
* FIXME
|
|
|
|
* Native sets last byte of data->str to '0' or '9', I don't know what
|
|
|
|
* it means. Current implementation sets it always to '0'.
|
|
|
|
*/
|
2010-12-01 22:26:26 +01:00
|
|
|
int CDECL MSVCRT_I10_OUTPUT(MSVCRT__LDOUBLE ld80, int prec, int flag, struct _I10_OUTPUT_DATA *data)
|
2010-05-14 12:14:12 +02:00
|
|
|
{
|
|
|
|
static const char inf_str[] = "1#INF";
|
|
|
|
static const char nan_str[] = "1#QNAN";
|
|
|
|
|
2010-12-01 22:26:26 +01:00
|
|
|
/* MS' long double type wants 12 bytes for Intel's 80 bit FP format.
|
|
|
|
* Some UNIX have sizeof(long double) == 16, yet only 80 bit are used.
|
|
|
|
* Assume long double uses 80 bit FP, never seen 128 bit FP. */
|
|
|
|
long double ld = 0;
|
|
|
|
double d;
|
2010-05-14 12:14:12 +02:00
|
|
|
char format[8];
|
|
|
|
char buf[I10_OUTPUT_MAX_PREC+9]; /* 9 = strlen("0.e+0000") + '\0' */
|
|
|
|
char *p;
|
|
|
|
|
2010-12-01 22:26:26 +01:00
|
|
|
memcpy(&ld, &ld80, 10);
|
|
|
|
d = ld;
|
2010-05-14 12:14:12 +02:00
|
|
|
TRACE("(%lf %d %x %p)\n", d, prec, flag, data);
|
|
|
|
|
|
|
|
if(d<0) {
|
|
|
|
data->sign = '-';
|
|
|
|
d = -d;
|
|
|
|
} else
|
|
|
|
data->sign = ' ';
|
|
|
|
|
|
|
|
if(isinf(d)) {
|
|
|
|
data->pos = 1;
|
|
|
|
data->len = 5;
|
|
|
|
memcpy(data->str, inf_str, sizeof(inf_str));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isnan(d)) {
|
|
|
|
data->pos = 1;
|
|
|
|
data->len = 6;
|
|
|
|
memcpy(data->str, nan_str, sizeof(nan_str));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(flag&1) {
|
|
|
|
int exp = 1+floor(log10(d));
|
|
|
|
|
|
|
|
prec += exp;
|
|
|
|
if(exp < 0)
|
|
|
|
prec--;
|
|
|
|
}
|
|
|
|
prec--;
|
|
|
|
|
|
|
|
if(prec+1 > I10_OUTPUT_MAX_PREC)
|
|
|
|
prec = I10_OUTPUT_MAX_PREC-1;
|
|
|
|
else if(prec < 0) {
|
|
|
|
d = 0.0;
|
|
|
|
prec = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(format, "%%.%dle", prec);
|
|
|
|
sprintf(buf, format, d);
|
|
|
|
|
|
|
|
buf[1] = buf[0];
|
|
|
|
data->pos = atoi(buf+prec+3);
|
|
|
|
if(buf[1] != '0')
|
|
|
|
data->pos++;
|
|
|
|
|
|
|
|
for(p = buf+prec+1; p>buf+1 && *p=='0'; p--);
|
|
|
|
data->len = p-buf;
|
|
|
|
|
|
|
|
memcpy(data->str, buf+1, data->len);
|
|
|
|
data->str[data->len] = '\0';
|
|
|
|
|
|
|
|
if(buf[1]!='0' && prec-data->len+1>0)
|
|
|
|
memcpy(data->str+data->len+1, buf+data->len+1, prec-data->len+1);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#undef I10_OUTPUT_MAX_PREC
|