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
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
#include <assert.h>
|
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
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
int CDECL MSVCRT__strlwr_s_l(char *str, MSVCRT_size_t len, MSVCRT__locale_t locale)
|
2010-10-11 12:25:23 +02:00
|
|
|
{
|
2019-12-04 10:04:46 +01:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
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;
|
|
|
|
}
|
|
|
|
|
2019-12-04 10:04:46 +01:00
|
|
|
if(!locale)
|
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
|
|
|
|
|
|
|
if(!locinfo->lc_handle[MSVCRT_LC_CTYPE])
|
|
|
|
{
|
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
if (*str >= 'A' && *str <= 'Z')
|
|
|
|
*str -= 'A' - 'a';
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2010-10-11 12:25:23 +02:00
|
|
|
{
|
2019-12-04 10:04:46 +01:00
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
*str = MSVCRT__tolower_l((unsigned char)*str, locale);
|
|
|
|
str++;
|
|
|
|
}
|
2010-10-11 12:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-12 11:38:41 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _strlwr_s (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
int CDECL MSVCRT__strlwr_s(char *str, MSVCRT_size_t len)
|
2011-05-12 11:38:41 +02:00
|
|
|
{
|
2014-04-16 16:15:07 +02:00
|
|
|
return MSVCRT__strlwr_s_l(str, len, NULL);
|
2011-05-12 11:38:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _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
|
|
|
{
|
2014-04-16 16:15:07 +02:00
|
|
|
MSVCRT__strlwr_s_l(str, -1, locale);
|
2011-05-16 16:22:46 +02:00
|
|
|
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
|
|
|
{
|
2014-04-16 16:15:07 +02:00
|
|
|
MSVCRT__strlwr_s_l(str, -1, NULL);
|
2011-05-16 16:22:46 +02:00
|
|
|
return str;
|
2011-05-12 11:38:41 +02:00
|
|
|
}
|
|
|
|
|
2011-05-12 11:38:52 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _strupr_s_l (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
int CDECL MSVCRT__strupr_s_l(char *str, MSVCRT_size_t len, MSVCRT__locale_t locale)
|
2011-05-12 11:38:52 +02:00
|
|
|
{
|
2018-03-22 18:51:50 +01:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
2011-05-12 11:38:52 +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;
|
|
|
|
}
|
|
|
|
|
2018-03-22 18:51:50 +01:00
|
|
|
if(!locale)
|
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
|
|
|
|
|
|
|
if(!locinfo->lc_handle[MSVCRT_LC_CTYPE])
|
2011-05-12 11:38:52 +02:00
|
|
|
{
|
2018-03-22 18:51:50 +01:00
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
if (*str >= 'a' && *str <= 'z')
|
|
|
|
*str -= 'a' - 'A';
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
*str = MSVCRT__toupper_l((unsigned char)*str, locale);
|
|
|
|
str++;
|
|
|
|
}
|
2011-05-12 11:38:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strupr_s (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
int CDECL MSVCRT__strupr_s(char *str, MSVCRT_size_t len)
|
2011-05-12 11:38:52 +02:00
|
|
|
{
|
2014-04-16 16:15:07 +02:00
|
|
|
return MSVCRT__strupr_s_l(str, len, NULL);
|
2011-05-12 11:38:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _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
|
|
|
{
|
2014-04-16 16:15:07 +02:00
|
|
|
MSVCRT__strupr_s_l(str, -1, locale);
|
2011-05-16 16:22:46 +02:00
|
|
|
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
|
|
|
{
|
2014-04-16 16:15:07 +02:00
|
|
|
MSVCRT__strupr_s_l(str, -1, NULL);
|
2011-05-16 16:22:46 +02:00
|
|
|
return str;
|
2011-05-12 11:38:52 +02:00
|
|
|
}
|
|
|
|
|
2014-09-02 13:50:44 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _strnset_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__strnset_s(char *str, MSVCRT_size_t size, int c, MSVCRT_size_t count)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t i;
|
|
|
|
|
|
|
|
if(!str && !size && !count) return 0;
|
|
|
|
if(!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if(!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
|
|
|
|
|
|
|
|
for(i=0; i<size-1 && i<count; i++) {
|
|
|
|
if(!str[i]) return 0;
|
|
|
|
str[i] = c;
|
|
|
|
}
|
|
|
|
for(; i<size; i++)
|
|
|
|
if(!str[i]) return 0;
|
|
|
|
|
|
|
|
str[0] = 0;
|
|
|
|
MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0);
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(delim != NULL)) return NULL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(ctx != NULL)) return NULL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL || *ctx != NULL)) return NULL;
|
2010-04-26 14:09:59 +02:00
|
|
|
|
|
|
|
if(!str)
|
|
|
|
str = *ctx;
|
|
|
|
|
|
|
|
while(*str && strchr(delim, *str))
|
|
|
|
str++;
|
|
|
|
if(!*str)
|
2016-08-18 11:49:04 +02:00
|
|
|
{
|
|
|
|
*ctx = str;
|
2010-04-26 14:09:59 +02:00
|
|
|
return NULL;
|
2016-08-18 11:49:04 +02:00
|
|
|
}
|
2010-04-26 14:09:59 +02:00
|
|
|
|
|
|
|
*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
|
|
|
|
2019-11-22 16:41:30 +01:00
|
|
|
enum round {
|
|
|
|
ROUND_ZERO, /* only used when dropped part contains only zeros */
|
|
|
|
ROUND_DOWN,
|
|
|
|
ROUND_EVEN,
|
|
|
|
ROUND_UP
|
|
|
|
};
|
|
|
|
|
|
|
|
static double make_double(int sign, int exp, ULONGLONG m, enum round round, int *err)
|
|
|
|
{
|
|
|
|
#define EXP_BITS 11
|
|
|
|
#define MANT_BITS 53
|
|
|
|
ULONGLONG bits = 0;
|
|
|
|
|
|
|
|
TRACE("%c %s *2^%d (round %d)\n", sign == -1 ? '-' : '+', wine_dbgstr_longlong(m), exp, round);
|
|
|
|
if (!m) return sign * 0.0;
|
|
|
|
|
|
|
|
/* make sure that we don't overflow modifying exponent */
|
|
|
|
if (exp > 1<<EXP_BITS)
|
|
|
|
{
|
|
|
|
if (err) *err = MSVCRT_ERANGE;
|
|
|
|
return sign * INFINITY;
|
|
|
|
}
|
|
|
|
if (exp < -(1<<EXP_BITS))
|
|
|
|
{
|
|
|
|
if (err) *err = MSVCRT_ERANGE;
|
|
|
|
return sign * 0.0;
|
|
|
|
}
|
|
|
|
exp += MANT_BITS - 1;
|
|
|
|
|
|
|
|
/* normalize mantissa */
|
|
|
|
while(m < (ULONGLONG)1 << (MANT_BITS-1))
|
|
|
|
{
|
|
|
|
m <<= 1;
|
|
|
|
exp--;
|
|
|
|
}
|
|
|
|
while(m >= (ULONGLONG)1 << MANT_BITS)
|
|
|
|
{
|
|
|
|
if (m & 1 || round != ROUND_ZERO)
|
|
|
|
{
|
|
|
|
if (!(m & 1)) round = ROUND_DOWN;
|
|
|
|
else if(round == ROUND_ZERO) round = ROUND_EVEN;
|
|
|
|
else round = ROUND_UP;
|
|
|
|
}
|
|
|
|
m >>= 1;
|
|
|
|
exp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle subnormal that falls into regular range due to rounding */
|
|
|
|
exp += (1 << (EXP_BITS-1)) - 1;
|
|
|
|
if (!exp && (round == ROUND_UP || (round == ROUND_EVEN && m & 1)))
|
|
|
|
{
|
|
|
|
if (m + 1 >= (ULONGLONG)1 << MANT_BITS)
|
|
|
|
{
|
|
|
|
m++;
|
|
|
|
m >>= 1;
|
|
|
|
exp++;
|
|
|
|
round = ROUND_DOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle subnormals */
|
|
|
|
if (exp <= 0)
|
|
|
|
m >>= 1;
|
|
|
|
while(m && exp<0)
|
|
|
|
{
|
|
|
|
m >>= 1;
|
|
|
|
exp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* round mantissa */
|
|
|
|
if (round == ROUND_UP || (round == ROUND_EVEN && m & 1))
|
|
|
|
{
|
|
|
|
m++;
|
|
|
|
if (m >= (ULONGLONG)1 << MANT_BITS)
|
|
|
|
{
|
|
|
|
exp++;
|
|
|
|
m >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exp >= 1<<EXP_BITS)
|
|
|
|
{
|
|
|
|
if (err) *err = MSVCRT_ERANGE;
|
|
|
|
return sign * INFINITY;
|
|
|
|
}
|
|
|
|
if (!m || exp < 0)
|
|
|
|
{
|
|
|
|
if (err) *err = MSVCRT_ERANGE;
|
|
|
|
return sign * 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sign == -1) bits |= (ULONGLONG)1 << (MANT_BITS + EXP_BITS - 1);
|
|
|
|
bits |= (ULONGLONG)exp << (MANT_BITS - 1);
|
|
|
|
bits |= m & (((ULONGLONG)1 << (MANT_BITS - 1)) - 1);
|
|
|
|
|
|
|
|
TRACE("returning %s\n", wine_dbgstr_longlong(bits));
|
|
|
|
return *((double*)&bits);
|
|
|
|
}
|
|
|
|
|
2019-12-30 13:23:47 +01:00
|
|
|
#if _MSVCR_VER >= 140
|
|
|
|
|
2019-11-22 16:41:30 +01:00
|
|
|
static inline int hex2int(char c)
|
|
|
|
{
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
return c - '0';
|
|
|
|
else if (c >= 'a' && c <= 'f')
|
|
|
|
return c - 'a' + 10;
|
|
|
|
else if (c >= 'A' && c <= 'F')
|
|
|
|
return c - 'A' + 10;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
static double strtod16(MSVCRT_wchar_t get(void *ctx), void unget(void *ctx),
|
|
|
|
void *ctx, int sign, MSVCRT_pthreadlocinfo locinfo, int *err)
|
2019-11-22 16:41:30 +01:00
|
|
|
{
|
2019-12-31 19:19:07 +01:00
|
|
|
BOOL found_digit = FALSE, found_dp = FALSE;
|
2019-11-22 16:41:30 +01:00
|
|
|
enum round round = ROUND_ZERO;
|
2019-12-31 19:19:07 +01:00
|
|
|
MSVCRT_wchar_t nch;
|
2019-11-22 16:41:30 +01:00
|
|
|
ULONGLONG m = 0;
|
|
|
|
int val, exp = 0;
|
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
2019-11-22 16:41:30 +01:00
|
|
|
while(m < MSVCRT_UI64_MAX/16)
|
|
|
|
{
|
2019-12-31 19:19:07 +01:00
|
|
|
val = hex2int(nch);
|
2019-11-22 16:41:30 +01:00
|
|
|
if (val == -1) break;
|
|
|
|
found_digit = TRUE;
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
2019-11-22 16:41:30 +01:00
|
|
|
|
|
|
|
m = m*16 + val;
|
|
|
|
}
|
|
|
|
while(1)
|
|
|
|
{
|
2019-12-31 19:19:07 +01:00
|
|
|
val = hex2int(nch);
|
2019-11-22 16:41:30 +01:00
|
|
|
if (val == -1) break;
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
2019-11-22 16:41:30 +01:00
|
|
|
exp += 4;
|
|
|
|
|
|
|
|
if (val || round != ROUND_ZERO)
|
|
|
|
{
|
|
|
|
if (val < 8) round = ROUND_DOWN;
|
|
|
|
else if (val == 8 && round == ROUND_ZERO) round = ROUND_EVEN;
|
|
|
|
else round = ROUND_UP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
if(nch == *locinfo->lconv->decimal_point)
|
|
|
|
{
|
|
|
|
found_dp = TRUE;
|
|
|
|
nch = get(ctx);
|
|
|
|
}
|
2019-11-22 16:41:30 +01:00
|
|
|
else if (!found_digit)
|
|
|
|
{
|
2019-12-31 19:19:07 +01:00
|
|
|
if(nch!=MSVCRT_WEOF) unget(ctx);
|
|
|
|
unget(ctx);
|
2019-11-22 16:41:30 +01:00
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(m <= MSVCRT_UI64_MAX/16)
|
|
|
|
{
|
2019-12-31 19:19:07 +01:00
|
|
|
val = hex2int(nch);
|
2019-11-22 16:41:30 +01:00
|
|
|
if (val == -1) break;
|
|
|
|
found_digit = TRUE;
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
2019-11-22 16:41:30 +01:00
|
|
|
|
|
|
|
m = m*16 + val;
|
|
|
|
exp -= 4;
|
|
|
|
}
|
|
|
|
while(1)
|
|
|
|
{
|
2019-12-31 19:19:07 +01:00
|
|
|
val = hex2int(nch);
|
2019-11-22 16:41:30 +01:00
|
|
|
if (val == -1) break;
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
2019-11-22 16:41:30 +01:00
|
|
|
|
|
|
|
if (val || round != ROUND_ZERO)
|
|
|
|
{
|
|
|
|
if (val < 8) round = ROUND_DOWN;
|
|
|
|
else if (val == 8 && round == ROUND_ZERO) round = ROUND_EVEN;
|
|
|
|
else round = ROUND_UP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found_digit)
|
|
|
|
{
|
2019-12-31 19:19:07 +01:00
|
|
|
if (nch != MSVCRT_WEOF) unget(ctx);
|
|
|
|
if (found_dp) unget(ctx);
|
|
|
|
unget(ctx);
|
2019-11-22 16:41:30 +01:00
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
if(nch=='p' || nch=='P') {
|
|
|
|
BOOL found_sign = FALSE;
|
2019-11-22 16:41:30 +01:00
|
|
|
int e=0, s=1;
|
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
|
|
|
if(nch == '-') {
|
|
|
|
found_sign = TRUE;
|
2019-11-22 16:41:30 +01:00
|
|
|
s = -1;
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
|
|
|
} else if(nch == '+') {
|
|
|
|
found_sign = TRUE;
|
|
|
|
nch = get(ctx);
|
|
|
|
}
|
|
|
|
if(nch>='0' && nch<='9') {
|
|
|
|
while(nch>='0' && nch<='9') {
|
2020-05-01 11:58:11 +02:00
|
|
|
if(e>INT_MAX/10 || e*10>INT_MAX-nch+'0')
|
2019-11-22 16:41:30 +01:00
|
|
|
e = INT_MAX;
|
2020-05-01 11:58:11 +02:00
|
|
|
else
|
|
|
|
e = e*10+nch-'0';
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
2019-11-22 16:41:30 +01:00
|
|
|
}
|
2019-12-31 19:19:07 +01:00
|
|
|
if((nch!=MSVCRT_WEOF) && (nch < '0' || nch > '9')) unget(ctx);
|
2019-11-22 16:41:30 +01:00
|
|
|
e *= s;
|
|
|
|
|
2020-04-28 19:21:40 +02:00
|
|
|
if(e<0 && exp<INT_MIN-e) exp = INT_MIN;
|
|
|
|
else if(e>0 && exp>INT_MAX-e) exp = INT_MAX;
|
2019-11-22 16:41:30 +01:00
|
|
|
else exp += e;
|
|
|
|
} else {
|
2019-12-31 19:19:07 +01:00
|
|
|
if(nch != MSVCRT_WEOF) unget(ctx);
|
|
|
|
if(found_sign) unget(ctx);
|
|
|
|
unget(ctx);
|
2019-11-22 16:41:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return make_double(sign, exp, m, round, err);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
#define LIMB_DIGITS 9 /* each DWORD stores up to 9 digits */
|
|
|
|
#define LIMB_MAX 1000000000 /* 10^9 */
|
|
|
|
#define BNUM_IDX(i) ((i) & 127)
|
|
|
|
/* bnum represents real number with fixed decimal point (after 2 limbs) */
|
|
|
|
struct bnum {
|
|
|
|
DWORD data[128]; /* circular buffer, base 10 number */
|
|
|
|
int b; /* least significant digit position */
|
|
|
|
int e; /* most significant digit position + 1 */
|
2019-12-30 13:23:47 +01:00
|
|
|
};
|
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
/* Returns integral part of bnum */
|
|
|
|
static inline ULONGLONG bnum_to_mant(struct bnum *b)
|
2019-12-30 13:23:47 +01:00
|
|
|
{
|
2020-04-28 19:21:57 +02:00
|
|
|
ULONGLONG ret = (ULONGLONG)b->data[BNUM_IDX(b->e-1)] * LIMB_MAX;
|
|
|
|
if(b->b != b->e-1) ret += b->data[BNUM_IDX(b->e-2)];
|
|
|
|
return ret;
|
2019-12-30 13:23:47 +01:00
|
|
|
}
|
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
/* Returns TRUE if new most significant limb was added */
|
|
|
|
static inline BOOL bnum_lshift(struct bnum *b, int shift)
|
2019-12-30 13:23:47 +01:00
|
|
|
{
|
2020-04-28 19:21:57 +02:00
|
|
|
DWORD rest = 0;
|
|
|
|
ULONGLONG tmp;
|
|
|
|
int i;
|
2019-12-30 13:23:47 +01:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
/* The limbs number can change by up to 1 so shift <= 29 */
|
|
|
|
assert(shift <= 29);
|
2019-12-30 13:23:47 +01:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
for(i=b->b; i<b->e; i++) {
|
|
|
|
tmp = ((ULONGLONG)b->data[BNUM_IDX(i)] << shift) + rest;
|
|
|
|
rest = tmp / LIMB_MAX;
|
|
|
|
b->data[BNUM_IDX(i)] = tmp % LIMB_MAX;
|
2019-12-30 13:23:47 +01:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
if(i == b->b && !b->data[BNUM_IDX(i)])
|
|
|
|
b->b++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rest) {
|
|
|
|
b->data[BNUM_IDX(b->e)] = rest;
|
|
|
|
b->e++;
|
2019-12-30 13:23:47 +01:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
if(BNUM_IDX(b->b) == BNUM_IDX(b->e)) {
|
|
|
|
if(b->data[BNUM_IDX(b->b)]) b->data[BNUM_IDX(b->b+1)] |= 1;
|
|
|
|
b->b++;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2019-12-30 13:23:47 +01:00
|
|
|
}
|
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
/* Returns TRUE if most significant limb was removed */
|
|
|
|
static inline BOOL bnum_rshift(struct bnum *b, int shift)
|
2019-12-30 13:23:47 +01:00
|
|
|
{
|
2020-04-28 19:21:57 +02:00
|
|
|
DWORD tmp, rest = 0;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Compute LIMB_MAX << shift without accuracy loss */
|
|
|
|
assert(shift <= 9);
|
|
|
|
|
|
|
|
for(i=b->e-1; i>=b->b; i--) {
|
|
|
|
tmp = b->data[BNUM_IDX(i)] & ((1<<shift)-1);
|
|
|
|
b->data[BNUM_IDX(i)] = (b->data[BNUM_IDX(i)] >> shift) + rest;
|
|
|
|
rest = (LIMB_MAX >> shift) * tmp;
|
|
|
|
if(i==b->e-1 && !b->data[BNUM_IDX(i)]) {
|
|
|
|
b->e--;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2019-12-30 13:23:47 +01:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
if(rest) {
|
|
|
|
if(BNUM_IDX(b->b-1) == BNUM_IDX(b->e)) {
|
|
|
|
if(rest) b->data[BNUM_IDX(b->b)] |= 1;
|
|
|
|
} else {
|
|
|
|
b->b--;
|
|
|
|
b->data[BNUM_IDX(b->b)] = rest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2019-12-30 13:23:47 +01:00
|
|
|
}
|
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
static inline void bnum_mult(struct bnum *b, int mult)
|
2019-12-30 13:23:47 +01:00
|
|
|
{
|
2020-04-28 19:21:57 +02:00
|
|
|
DWORD rest = 0;
|
|
|
|
ULONGLONG tmp;
|
|
|
|
int i;
|
2019-12-30 13:23:47 +01:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
assert(mult <= LIMB_MAX);
|
2019-12-30 13:23:47 +01:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
for(i=b->b; i<b->e; i++) {
|
|
|
|
tmp = ((ULONGLONG)b->data[BNUM_IDX(i)] * mult) + rest;
|
|
|
|
rest = tmp / LIMB_MAX;
|
|
|
|
b->data[BNUM_IDX(i)] = tmp % LIMB_MAX;
|
2019-12-18 23:48:11 +01:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
if(i == b->b && !b->data[BNUM_IDX(i)])
|
|
|
|
b->b++;
|
2019-12-30 13:23:47 +01:00
|
|
|
}
|
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
if(rest) {
|
|
|
|
b->data[BNUM_IDX(b->e)] = rest;
|
|
|
|
b->e++;
|
2019-12-30 13:23:47 +01:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
if(BNUM_IDX(b->b) == BNUM_IDX(b->e)) {
|
|
|
|
if(b->data[BNUM_IDX(b->b)]) b->data[BNUM_IDX(b->b+1)] |= 1;
|
|
|
|
b->b++;
|
|
|
|
}
|
2019-12-30 13:23:47 +01:00
|
|
|
}
|
2019-12-18 23:48:11 +01:00
|
|
|
}
|
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
double parse_double(MSVCRT_wchar_t (*get)(void *ctx), void (*unget)(void *ctx),
|
|
|
|
void *ctx, MSVCRT_pthreadlocinfo locinfo, int *err)
|
2010-04-21 11:26:22 +02:00
|
|
|
{
|
2020-04-28 19:21:57 +02:00
|
|
|
static const int p10s[] = { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 };
|
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
#if _MSVCR_VER >= 140
|
|
|
|
MSVCRT_wchar_t _infinity[] = { 'i', 'n', 'f', 'i', 'n', 'i', 't', 'y', 0 };
|
|
|
|
MSVCRT_wchar_t _nan[] = { 'n', 'a', 'n', 0 };
|
|
|
|
MSVCRT_wchar_t *str_match = NULL;
|
|
|
|
int matched=0;
|
|
|
|
#endif
|
|
|
|
BOOL found_digit = FALSE, found_dp = FALSE, found_sign = FALSE;
|
2020-04-28 19:21:57 +02:00
|
|
|
int e2 = 0, dp=0, sign=1, off, limb_digits = 0, i;
|
|
|
|
enum round round = ROUND_ZERO;
|
2019-12-31 19:19:07 +01:00
|
|
|
MSVCRT_wchar_t nch;
|
2020-04-28 19:21:57 +02:00
|
|
|
struct bnum b;
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
|
|
|
if(nch == '-') {
|
|
|
|
found_sign = TRUE;
|
2010-04-26 12:33:28 +02:00
|
|
|
sign = -1;
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
|
|
|
} else if(nch == '+') {
|
|
|
|
found_sign = TRUE;
|
|
|
|
nch = get(ctx);
|
|
|
|
}
|
2010-04-26 12:33:28 +02:00
|
|
|
|
2015-09-29 13:40:12 +02:00
|
|
|
#if _MSVCR_VER >= 140
|
2019-12-31 19:19:07 +01:00
|
|
|
if(nch == _infinity[0] || nch == MSVCRT__toupper(_infinity[0]))
|
|
|
|
str_match = _infinity;
|
|
|
|
if(nch == _nan[0] || nch == MSVCRT__toupper(_nan[0]))
|
|
|
|
str_match = _nan;
|
|
|
|
while(str_match && nch != MSVCRT_WEOF &&
|
|
|
|
(nch == str_match[matched] || nch == MSVCRT__toupper(str_match[matched]))) {
|
|
|
|
nch = get(ctx);
|
|
|
|
matched++;
|
|
|
|
}
|
|
|
|
if(str_match) {
|
|
|
|
int keep = 0;
|
|
|
|
if(matched >= 8) keep = 8;
|
|
|
|
else if(matched >= 3) keep = 3;
|
|
|
|
if(nch != MSVCRT_WEOF) unget(ctx);
|
|
|
|
for (; matched > keep; matched--) {
|
|
|
|
unget(ctx);
|
|
|
|
}
|
|
|
|
if(keep) {
|
|
|
|
if (str_match == _infinity) return sign*INFINITY;
|
|
|
|
if (str_match == _nan) return sign*NAN;
|
2020-01-07 15:35:52 +01:00
|
|
|
} else if(found_sign) {
|
|
|
|
unget(ctx);
|
2019-12-31 19:19:07 +01:00
|
|
|
}
|
2020-01-07 15:35:52 +01:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
return 0.0;
|
2019-12-31 19:19:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(nch == '0') {
|
2020-01-03 19:41:56 +01:00
|
|
|
found_digit = TRUE;
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
|
|
|
if(nch == 'x' || nch == 'X')
|
|
|
|
return strtod16(get, unget, ctx, sign, locinfo, err);
|
2015-09-29 13:40:12 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-04 11:30:24 +02:00
|
|
|
while(nch == '0') {
|
|
|
|
found_digit = TRUE;
|
|
|
|
nch = get(ctx);
|
|
|
|
}
|
2020-04-28 19:21:57 +02:00
|
|
|
|
|
|
|
b.data[0] = 0;
|
|
|
|
b.b = 0;
|
|
|
|
b.e = 1;
|
2019-12-31 19:19:07 +01:00
|
|
|
while(nch>='0' && nch<='9') {
|
2010-07-22 12:35:08 +02:00
|
|
|
found_digit = TRUE;
|
2020-04-28 19:21:57 +02:00
|
|
|
if(limb_digits == LIMB_DIGITS) {
|
|
|
|
if(BNUM_IDX(b.b-1) == BNUM_IDX(b.e)) break;
|
|
|
|
else {
|
|
|
|
b.b--;
|
|
|
|
b.data[BNUM_IDX(b.b)] = 0;
|
|
|
|
limb_digits = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
b.data[BNUM_IDX(b.b)] = b.data[BNUM_IDX(b.b)] * 10 + nch - '0';
|
|
|
|
limb_digits++;
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
2020-04-28 19:21:57 +02:00
|
|
|
dp++;
|
2010-04-26 12:33:28 +02:00
|
|
|
}
|
2019-12-31 19:19:07 +01:00
|
|
|
while(nch>='0' && nch<='9') {
|
2020-04-28 19:21:57 +02:00
|
|
|
if(nch != '0') b.data[BNUM_IDX(b.b)] |= 1;
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
2020-04-28 19:21:57 +02:00
|
|
|
dp++;
|
2010-04-21 11:26:22 +02:00
|
|
|
}
|
2010-04-26 12:33:28 +02:00
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
if(nch == *locinfo->lconv->decimal_point) {
|
|
|
|
found_dp = TRUE;
|
|
|
|
nch = get(ctx);
|
|
|
|
}
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
/* skip leading '0' */
|
|
|
|
if(nch=='0' && !limb_digits && !b.b) {
|
|
|
|
found_digit = TRUE;
|
|
|
|
while(nch == '0') {
|
|
|
|
nch = get(ctx);
|
|
|
|
dp--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
while(nch>='0' && nch<='9') {
|
2010-07-22 12:35:08 +02:00
|
|
|
found_digit = TRUE;
|
2020-04-28 19:21:57 +02:00
|
|
|
if(limb_digits == LIMB_DIGITS) {
|
|
|
|
if(BNUM_IDX(b.b-1) == BNUM_IDX(b.e)) break;
|
|
|
|
else {
|
|
|
|
b.b--;
|
|
|
|
b.data[BNUM_IDX(b.b)] = 0;
|
|
|
|
limb_digits = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
b.data[BNUM_IDX(b.b)] = b.data[BNUM_IDX(b.b)] * 10 + nch - '0';
|
|
|
|
limb_digits++;
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
2010-04-26 12:33:28 +02:00
|
|
|
}
|
2020-04-28 19:21:57 +02:00
|
|
|
while(nch>='0' && nch<='9') {
|
|
|
|
if(nch != '0') b.data[BNUM_IDX(b.b)] |= 1;
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
2020-04-28 19:21:57 +02:00
|
|
|
}
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2010-07-22 12:35:08 +02:00
|
|
|
if(!found_digit) {
|
2019-12-31 19:19:07 +01:00
|
|
|
if(nch != MSVCRT_WEOF) unget(ctx);
|
|
|
|
if(found_dp) unget(ctx);
|
|
|
|
if(found_sign) unget(ctx);
|
2010-04-26 12:33:28 +02:00
|
|
|
return 0.0;
|
|
|
|
}
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
if(nch=='e' || nch=='E' || nch=='d' || nch=='D') {
|
2010-04-26 12:33:28 +02:00
|
|
|
int e=0, s=1;
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
|
|
|
if(nch == '-') {
|
|
|
|
found_sign = TRUE;
|
2010-04-26 12:33:28 +02:00
|
|
|
s = -1;
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
|
|
|
} else if(nch == '+') {
|
|
|
|
found_sign = TRUE;
|
|
|
|
nch = get(ctx);
|
|
|
|
} else {
|
|
|
|
found_sign = FALSE;
|
|
|
|
}
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
if(nch>='0' && nch<='9') {
|
|
|
|
while(nch>='0' && nch<='9') {
|
2020-05-01 11:58:11 +02:00
|
|
|
if(e>INT_MAX/10 || e*10>INT_MAX-nch+'0')
|
2010-04-26 12:33:28 +02:00
|
|
|
e = INT_MAX;
|
2020-05-01 11:58:11 +02:00
|
|
|
else
|
|
|
|
e = e*10+nch-'0';
|
2019-12-31 19:19:07 +01:00
|
|
|
nch = get(ctx);
|
2010-04-26 12:33:28 +02:00
|
|
|
}
|
2020-01-02 19:01:56 +01:00
|
|
|
if(nch != MSVCRT_WEOF) unget(ctx);
|
2010-04-26 12:33:28 +02:00
|
|
|
e *= s;
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
if(e<0 && dp<INT_MIN-e) dp = INT_MIN;
|
|
|
|
else if(e>0 && dp>INT_MAX-e) dp = INT_MAX;
|
|
|
|
else dp += e;
|
2010-04-26 12:33:28 +02:00
|
|
|
} else {
|
2019-12-31 19:19:07 +01:00
|
|
|
if(nch != MSVCRT_WEOF) unget(ctx);
|
|
|
|
if(found_sign) unget(ctx);
|
|
|
|
unget(ctx);
|
2010-04-26 12:33:28 +02:00
|
|
|
}
|
2020-01-02 19:01:56 +01:00
|
|
|
} else if(nch != MSVCRT_WEOF) {
|
|
|
|
unget(ctx);
|
2010-04-26 12:33:28 +02:00
|
|
|
}
|
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
if(!b.data[BNUM_IDX(b.e-1)]) return make_double(sign, 0, 0, ROUND_ZERO, err);
|
|
|
|
|
|
|
|
/* Fill last limb with 0 if needed */
|
|
|
|
if(b.b+1 != b.e) {
|
|
|
|
for(; limb_digits != LIMB_DIGITS; limb_digits++)
|
|
|
|
b.data[BNUM_IDX(b.b)] *= 10;
|
|
|
|
}
|
|
|
|
for(; BNUM_IDX(b.b) < BNUM_IDX(b.e); b.b++) {
|
|
|
|
if(b.data[BNUM_IDX(b.b)]) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* move decimal point to limb boundry */
|
|
|
|
if(limb_digits==dp && b.b==b.e-1)
|
|
|
|
return make_double(sign, 0, b.data[BNUM_IDX(b.e-1)], ROUND_ZERO, err);
|
|
|
|
off = (dp - limb_digits) % LIMB_DIGITS;
|
|
|
|
if(off < 0) off += LIMB_DIGITS;
|
|
|
|
if(off) bnum_mult(&b, p10s[off-1]);
|
|
|
|
|
2019-12-30 13:23:47 +01:00
|
|
|
if(!err) err = MSVCRT__errno();
|
2020-04-28 19:21:57 +02:00
|
|
|
if(dp-1 > MSVCRT_DBL_MAX_10_EXP)
|
|
|
|
return make_double(sign, INT_MAX, 1, ROUND_ZERO, err);
|
2019-12-30 13:23:47 +01:00
|
|
|
/* Count part of exponent stored in denormalized mantissa. */
|
|
|
|
/* Increase exponent range to handle subnormals. */
|
2020-04-28 19:21:57 +02:00
|
|
|
if(dp-1 < MSVCRT_DBL_MIN_10_EXP-MSVCRT_DBL_DIG-18)
|
|
|
|
return make_double(sign, INT_MIN, 1, ROUND_ZERO, err);
|
|
|
|
|
|
|
|
while(dp > 2*LIMB_DIGITS) {
|
|
|
|
if(bnum_rshift(&b, 9)) dp -= LIMB_DIGITS;
|
|
|
|
e2 += 9;
|
|
|
|
}
|
|
|
|
while(dp <= LIMB_DIGITS) {
|
|
|
|
if(bnum_lshift(&b, 29)) dp += LIMB_DIGITS;
|
|
|
|
e2 -= 29;
|
|
|
|
}
|
|
|
|
while(b.data[BNUM_IDX(b.e-1)] < LIMB_MAX/10) {
|
|
|
|
bnum_lshift(&b, 1);
|
|
|
|
e2--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if fractional part is non-zero */
|
|
|
|
/* Caution: it's only correct because bnum_to_mant returns more then 53 bits */
|
|
|
|
for(i=b.e-3; i>=b.b; i--) {
|
|
|
|
if (!b.data[BNUM_IDX(b.b)]) continue;
|
|
|
|
round = ROUND_DOWN;
|
|
|
|
break;
|
|
|
|
}
|
2019-12-30 13:23:47 +01:00
|
|
|
|
2020-04-28 19:21:57 +02:00
|
|
|
return make_double(sign, e2, bnum_to_mant(&b), round, err);
|
2010-04-21 11:26:22 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 19:19:07 +01:00
|
|
|
static MSVCRT_wchar_t strtod_str_get(void *ctx)
|
|
|
|
{
|
|
|
|
const char **p = ctx;
|
|
|
|
if (!**p) return MSVCRT_WEOF;
|
|
|
|
return *(*p)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strtod_str_unget(void *ctx)
|
|
|
|
{
|
|
|
|
const char **p = ctx;
|
|
|
|
(*p)--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline double strtod_helper(const char *str, char **end, MSVCRT__locale_t locale, int *err)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
const char *beg, *p;
|
|
|
|
double ret;
|
|
|
|
|
|
|
|
if (err) *err = 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) {
|
|
|
|
if (end) *end = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!locale)
|
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
|
|
|
|
|
|
|
p = str;
|
|
|
|
while(MSVCRT__isspace_l((unsigned char)*p, locale))
|
|
|
|
p++;
|
|
|
|
beg = p;
|
|
|
|
|
|
|
|
ret = parse_double(strtod_str_get, strtod_str_unget, &p, locinfo, err);
|
|
|
|
if (end) *end = (p == beg ? (char*)str : (char*)p);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-17 15:18:54 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strtod_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCRT_strtod_l(const char *str, char **end, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return strtod_helper(str, end, locale, NULL);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-12-28 18:46:54 +01:00
|
|
|
#if _MSVCR_VER>=120
|
|
|
|
|
2016-02-18 16:10:00 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strtof_l (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT__strtof_l( const char *str, char **end, MSVCRT__locale_t locale )
|
|
|
|
{
|
|
|
|
return MSVCRT_strtod_l(str, end, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strtof (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_strtof( const char *str, char **end )
|
|
|
|
{
|
|
|
|
return MSVCRT__strtof_l(str, end, NULL);
|
|
|
|
}
|
|
|
|
|
2017-12-28 18:46:54 +01:00
|
|
|
#endif /* _MSVCR_VER>=120 */
|
|
|
|
|
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)
|
|
|
|
{
|
2012-12-17 15:18:54 +01:00
|
|
|
double d;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
d = strtod_helper(str, NULL, locale, &err);
|
|
|
|
value->f = d;
|
|
|
|
if(isinf(value->f))
|
|
|
|
return MSVCRT__OVERFLOW;
|
|
|
|
if((d!=0 || err) && value->f>-MSVCRT_FLT_MIN && value->f<MSVCRT_FLT_MIN)
|
|
|
|
return MSVCRT__UNDERFLOW;
|
|
|
|
return 0;
|
2011-01-18 17:06:07 +01:00
|
|
|
}
|
|
|
|
|
2014-04-16 16:15:21 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _atoflt (MSVCR100.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__atoflt(MSVCRT__CRT_FLOAT *value, char *str)
|
|
|
|
{
|
|
|
|
return MSVCRT__atoflt_l(value, str, NULL);
|
|
|
|
}
|
|
|
|
|
2012-12-17 15:19:07 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _atodbl_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__atodbl_l(MSVCRT__CRT_DOUBLE *value, char *str, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
value->x = strtod_helper(str, NULL, locale, &err);
|
|
|
|
if(isinf(value->x))
|
|
|
|
return MSVCRT__OVERFLOW;
|
|
|
|
if((value->x!=0 || err) && value->x>-MSVCRT_DBL_MIN && value->x<MSVCRT_DBL_MIN)
|
|
|
|
return MSVCRT__UNDERFLOW;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _atodbl (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__atodbl(MSVCRT__CRT_DOUBLE *value, char *str)
|
|
|
|
{
|
|
|
|
return MSVCRT__atodbl_l(value, str, NULL);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-01-23 15:10:14 +01:00
|
|
|
if(!locinfo->lc_handle[MSVCRT_LC_COLLATE])
|
2019-10-31 09:35:40 +01:00
|
|
|
return MSVCRT_strcmp(str1, str2);
|
2012-12-18 11:56:35 +01:00
|
|
|
return CompareStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], 0, str1, -1, str2, -1)-CSTR_EQUAL;
|
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
|
|
|
|
2014-01-23 15:10:14 +01:00
|
|
|
if(!locinfo->lc_handle[MSVCRT_LC_COLLATE])
|
2019-03-26 11:31:09 +01:00
|
|
|
return MSVCRT__stricmp(str1, str2);
|
2012-12-18 11:56:35 +01:00
|
|
|
return CompareStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], NORM_IGNORECASE,
|
2012-06-20 23:40:33 +02:00
|
|
|
str1, -1, str2, -1)-CSTR_EQUAL;
|
2011-05-12 11:39:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _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.@)
|
|
|
|
*/
|
2013-04-29 06:45:16 +02:00
|
|
|
int CDECL MSVCRT__strncoll_l( const char* str1, const char* str2, MSVCRT_size_t count, MSVCRT__locale_t locale )
|
2011-05-12 11:39:31 +02:00
|
|
|
{
|
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
|
|
|
|
2014-01-23 15:10:14 +01:00
|
|
|
if(!locinfo->lc_handle[MSVCRT_LC_COLLATE])
|
2019-10-31 09:35:40 +01:00
|
|
|
return MSVCRT_strncmp(str1, str2, count);
|
2018-08-17 18:51:00 +02:00
|
|
|
return CompareStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], 0,
|
|
|
|
str1, MSVCRT_strnlen(str1, count),
|
|
|
|
str2, MSVCRT_strnlen(str2, count))-CSTR_EQUAL;
|
2011-05-12 11:39:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2013-04-29 06:45:16 +02:00
|
|
|
* _strncoll (MSVCRT.@)
|
2011-05-12 11:39:31 +02:00
|
|
|
*/
|
2013-04-29 06:45:16 +02:00
|
|
|
int CDECL MSVCRT__strncoll( const char* str1, const char* str2, MSVCRT_size_t count )
|
2011-05-12 11:39:31 +02:00
|
|
|
{
|
2013-04-29 06:45:16 +02:00
|
|
|
return MSVCRT__strncoll_l(str1, str2, count, NULL);
|
2011-05-12 11:39:31 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-01-23 15:10:14 +01:00
|
|
|
if(!locinfo->lc_handle[MSVCRT_LC_COLLATE])
|
2019-03-26 11:31:13 +01:00
|
|
|
return MSVCRT__strnicmp(str1, str2, count);
|
2012-12-18 11:56:35 +01:00
|
|
|
return CompareStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], NORM_IGNORECASE,
|
2018-08-17 18:51:29 +02:00
|
|
|
str1, MSVCRT_strnlen(str1, count),
|
|
|
|
str2, MSVCRT_strnlen(str2, count))-CSTR_EQUAL;
|
2011-05-12 11:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strnicoll (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__strnicoll( const char* str1, const char* str2, MSVCRT_size_t count )
|
|
|
|
{
|
|
|
|
return MSVCRT__strnicoll_l(str1, str2, count, NULL);
|
|
|
|
}
|
|
|
|
|
2013-03-27 16:12:34 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strncpy (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
char* __cdecl MSVCRT_strncpy(char *dst, const char *src, MSVCRT_size_t len)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t i;
|
|
|
|
|
|
|
|
for(i=0; i<len; i++)
|
|
|
|
if((dst[i] = src[i]) == '\0') break;
|
|
|
|
|
2013-08-13 21:47:20 +02:00
|
|
|
while (i < len) dst[i++] = 0;
|
|
|
|
|
2013-03-27 16:12:34 +01:00
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2017-08-05 18:23:13 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* strcpy (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
char* CDECL MSVCRT_strcpy(char *dst, const char *src)
|
|
|
|
{
|
|
|
|
char *ret = dst;
|
|
|
|
while ((*dst++ = *src++));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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;
|
2012-07-26 11:05:32 +02:00
|
|
|
|
|
|
|
if (!MSVCRT_CHECK_PMT(dst != 0)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(elem != 0)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(src != 0))
|
2010-11-15 01:04:42 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-09-17 14:45:44 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* strncat (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
char* __cdecl MSVCRT_strncat(char *dst, const char *src, MSVCRT_size_t len)
|
|
|
|
{
|
|
|
|
return strncat(dst, src, len);
|
|
|
|
}
|
|
|
|
|
2014-06-12 17:52:40 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _strxfrm_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT__strxfrm_l( char *dest, const char *src,
|
|
|
|
MSVCRT_size_t len, MSVCRT__locale_t locale )
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(!MSVCRT_CHECK_PMT(src)) return INT_MAX;
|
|
|
|
if(!MSVCRT_CHECK_PMT(dest || !len)) return INT_MAX;
|
|
|
|
|
|
|
|
if(len > INT_MAX) {
|
|
|
|
FIXME("len > INT_MAX not supported\n");
|
|
|
|
len = INT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
|
|
|
|
|
|
|
if(!locinfo->lc_handle[MSVCRT_LC_COLLATE]) {
|
|
|
|
MSVCRT_strncpy(dest, src, len);
|
|
|
|
return strlen(src);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = LCMapStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE],
|
|
|
|
LCMAP_SORTKEY, src, -1, NULL, 0);
|
|
|
|
if(!ret) {
|
|
|
|
if(len) dest[0] = 0;
|
|
|
|
*MSVCRT__errno() = MSVCRT_EILSEQ;
|
|
|
|
return INT_MAX;
|
|
|
|
}
|
|
|
|
if(!len) return ret-1;
|
|
|
|
|
|
|
|
if(ret > len) {
|
|
|
|
dest[0] = 0;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return ret-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LCMapStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE],
|
|
|
|
LCMAP_SORTKEY, src, -1, dest, len) - 1;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-06-12 17:52:40 +02:00
|
|
|
return MSVCRT__strxfrm_l(dest, src, len, NULL);
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-09-17 14:45:29 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* strlen (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t __cdecl MSVCRT_strlen(const char *str)
|
|
|
|
{
|
|
|
|
return strlen(str);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2015-06-08 12:00:55 +02:00
|
|
|
const char *p = nptr;
|
2010-03-29 00:04:03 +02:00
|
|
|
BOOL negative = FALSE;
|
2015-06-08 12:00:55 +02:00
|
|
|
BOOL got_digit = FALSE;
|
2010-03-29 00:04:03 +02:00
|
|
|
__int64 ret = 0;
|
|
|
|
|
2011-09-19 23:29:47 +02:00
|
|
|
TRACE("(%s %p %d %p)\n", debugstr_a(nptr), endptr, base, locale);
|
2010-03-29 00:04:03 +02:00
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(nptr != NULL)) return 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
|
2010-03-29 00:04:03 +02:00
|
|
|
|
2019-11-22 16:41:23 +01:00
|
|
|
while(MSVCRT__isspace_l((unsigned char)*nptr, locale)) nptr++;
|
2010-03-29 00:04:03 +02:00
|
|
|
|
|
|
|
if(*nptr == '-') {
|
|
|
|
negative = TRUE;
|
|
|
|
nptr++;
|
|
|
|
} else if(*nptr == '+')
|
|
|
|
nptr++;
|
|
|
|
|
2019-03-26 11:31:01 +01:00
|
|
|
if((base==0 || base==16) && *nptr=='0' && MSVCRT__tolower_l(*(nptr+1), locale)=='x') {
|
2010-03-29 00:04:03 +02:00
|
|
|
base = 16;
|
|
|
|
nptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(base == 0) {
|
|
|
|
if(*nptr=='0')
|
|
|
|
base = 8;
|
|
|
|
else
|
|
|
|
base = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(*nptr) {
|
2019-03-26 11:31:01 +01:00
|
|
|
char cur = MSVCRT__tolower_l(*nptr, locale);
|
2010-03-29 00:04:03 +02:00
|
|
|
int v;
|
|
|
|
|
2016-02-18 16:09:55 +01:00
|
|
|
if(cur>='0' && cur<='9') {
|
2010-03-29 00:04:03 +02:00
|
|
|
if(cur >= '0'+base)
|
|
|
|
break;
|
|
|
|
v = cur-'0';
|
|
|
|
} else {
|
|
|
|
if(cur<'a' || cur>='a'+base-10)
|
|
|
|
break;
|
|
|
|
v = cur-'a'+10;
|
|
|
|
}
|
2015-06-08 12:00:55 +02:00
|
|
|
got_digit = TRUE;
|
2010-03-29 00:04:03 +02:00
|
|
|
|
|
|
|
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)
|
2015-06-08 12:00:55 +02:00
|
|
|
*endptr = (char*)(got_digit ? nptr : p);
|
2010-03-29 00:04:03 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2012-12-12 11:16:19 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _atoi_l (MSVCRT.@)
|
|
|
|
*/
|
2013-03-27 16:11:49 +01:00
|
|
|
int __cdecl MSVCRT__atoi_l(const char *str, MSVCRT__locale_t locale)
|
2012-12-12 11:16:19 +01:00
|
|
|
{
|
|
|
|
__int64 ret = MSVCRT_strtoi64_l(str, NULL, 10, locale);
|
|
|
|
|
|
|
|
if(ret > INT_MAX) {
|
|
|
|
ret = INT_MAX;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
} else if(ret < INT_MIN) {
|
|
|
|
ret = INT_MIN;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-27 16:11:49 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* atoi (MSVCRT.@)
|
|
|
|
*/
|
2014-04-21 13:08:20 +02:00
|
|
|
#if _MSVCR_VER == 0
|
2013-03-27 16:11:49 +01:00
|
|
|
int __cdecl MSVCRT_atoi(const char *str)
|
|
|
|
{
|
2013-06-04 15:52:10 +02:00
|
|
|
BOOL minus = FALSE;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if(!str)
|
|
|
|
return 0;
|
|
|
|
|
2019-11-22 16:41:23 +01:00
|
|
|
while(MSVCRT__isspace_l((unsigned char)*str, NULL)) str++;
|
2013-06-04 15:52:10 +02:00
|
|
|
|
|
|
|
if(*str == '+') {
|
|
|
|
str++;
|
|
|
|
}else if(*str == '-') {
|
|
|
|
minus = TRUE;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(*str>='0' && *str<='9') {
|
|
|
|
ret = ret*10+*str-'0';
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return minus ? -ret : ret;
|
2013-03-27 16:11:49 +01:00
|
|
|
}
|
2014-04-21 13:08:20 +02:00
|
|
|
#else
|
|
|
|
int CDECL MSVCRT_atoi(const char *str)
|
2014-04-16 16:15:21 +02:00
|
|
|
{
|
|
|
|
return MSVCRT__atoi_l(str, NULL);
|
|
|
|
}
|
2014-04-21 13:08:20 +02:00
|
|
|
#endif
|
2014-04-16 16:15:21 +02:00
|
|
|
|
2018-03-26 21:20:48 +02:00
|
|
|
/******************************************************************
|
|
|
|
* _atoi64_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
__int64 CDECL MSVCRT__atoi64_l(const char *str, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return MSVCRT_strtoi64_l(str, NULL, 10, locale);
|
|
|
|
}
|
|
|
|
|
2018-10-17 15:22:51 +02:00
|
|
|
/******************************************************************
|
|
|
|
* _atoi64 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
__int64 CDECL MSVCRT__atoi64(const char *str)
|
|
|
|
{
|
|
|
|
return MSVCRT_strtoi64_l(str, NULL, 10, NULL);
|
|
|
|
}
|
|
|
|
|
2018-03-26 21:20:22 +02:00
|
|
|
/******************************************************************
|
|
|
|
* _atol_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_long CDECL MSVCRT__atol_l(const char *str, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
__int64 ret = MSVCRT_strtoi64_l(str, NULL, 10, locale);
|
|
|
|
|
2019-03-16 14:48:08 +01:00
|
|
|
if(ret > MSVCRT_LONG_MAX) {
|
|
|
|
ret = MSVCRT_LONG_MAX;
|
2018-03-26 21:20:22 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
2019-03-16 14:48:08 +01:00
|
|
|
} else if(ret < MSVCRT_LONG_MIN) {
|
|
|
|
ret = MSVCRT_LONG_MIN;
|
2018-03-26 21:20:22 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-17 15:23:00 +02:00
|
|
|
/******************************************************************
|
|
|
|
* atol (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_long CDECL MSVCRT_atol(const char *str)
|
|
|
|
{
|
2019-03-16 14:49:08 +01:00
|
|
|
#if _MSVCR_VER == 0
|
|
|
|
return MSVCRT_atoi(str);
|
|
|
|
#else
|
2018-10-17 15:23:00 +02:00
|
|
|
return MSVCRT__atol_l(str, NULL);
|
2019-03-16 14:49:08 +01:00
|
|
|
#endif
|
2018-10-17 15:23:00 +02:00
|
|
|
}
|
|
|
|
|
2017-12-28 18:46:54 +01:00
|
|
|
#if _MSVCR_VER>=120
|
|
|
|
|
2016-02-09 14:29:07 +01:00
|
|
|
/******************************************************************
|
|
|
|
* _atoll_l (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_longlong CDECL MSVCRT__atoll_l(const char* str, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return MSVCRT_strtoi64_l(str, NULL, 10, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* atoll (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_longlong CDECL MSVCRT_atoll(const char* str)
|
|
|
|
{
|
|
|
|
return MSVCRT__atoll_l(str, NULL);
|
|
|
|
}
|
|
|
|
|
2017-12-28 18:46:54 +01:00
|
|
|
#endif /* if _MSVCR_VER>=120 */
|
|
|
|
|
2013-09-25 14:41:40 +02:00
|
|
|
/******************************************************************
|
2015-12-21 11:22:45 +01:00
|
|
|
* _strtol_l (MSVCRT.@)
|
2013-09-25 14:41:40 +02:00
|
|
|
*/
|
2015-12-21 11:22:45 +01:00
|
|
|
MSVCRT_long CDECL MSVCRT__strtol_l(const char* nptr,
|
|
|
|
char** end, int base, MSVCRT__locale_t locale)
|
2013-09-25 14:41:40 +02:00
|
|
|
{
|
2015-12-21 11:22:45 +01:00
|
|
|
__int64 ret = MSVCRT_strtoi64_l(nptr, end, base, locale);
|
2013-09-25 14:41:40 +02:00
|
|
|
|
|
|
|
if(ret > MSVCRT_LONG_MAX) {
|
|
|
|
ret = MSVCRT_LONG_MAX;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
} else if(ret < MSVCRT_LONG_MIN) {
|
|
|
|
ret = MSVCRT_LONG_MIN;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-12-21 11:22:45 +01:00
|
|
|
/******************************************************************
|
|
|
|
* strtol (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_long CDECL MSVCRT_strtol(const char* nptr, char** end, int base)
|
|
|
|
{
|
|
|
|
return MSVCRT__strtol_l(nptr, end, base, NULL);
|
|
|
|
}
|
|
|
|
|
2013-09-25 14:41:52 +02:00
|
|
|
/******************************************************************
|
2014-09-02 17:42:33 +02:00
|
|
|
* _strtoul_l (MSVCRT.@)
|
2013-09-25 14:41:52 +02:00
|
|
|
*/
|
2014-09-02 17:42:33 +02:00
|
|
|
MSVCRT_ulong CDECL MSVCRT_strtoul_l(const char* nptr, char** end, int base, MSVCRT__locale_t locale)
|
2013-09-25 14:41:52 +02:00
|
|
|
{
|
2014-09-02 17:42:33 +02:00
|
|
|
__int64 ret = MSVCRT_strtoi64_l(nptr, end, base, locale);
|
2013-09-25 14:41:52 +02:00
|
|
|
|
|
|
|
if(ret > MSVCRT_ULONG_MAX) {
|
|
|
|
ret = MSVCRT_ULONG_MAX;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}else if(ret < -(__int64)MSVCRT_ULONG_MAX) {
|
|
|
|
ret = 1;
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-09-02 17:42:33 +02:00
|
|
|
/******************************************************************
|
|
|
|
* strtoul (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base)
|
|
|
|
{
|
|
|
|
return MSVCRT_strtoul_l(nptr, end, 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)
|
|
|
|
{
|
2015-06-08 12:00:55 +02:00
|
|
|
const char *p = nptr;
|
2010-03-29 00:04:32 +02:00
|
|
|
BOOL negative = FALSE;
|
2015-06-08 12:00:55 +02:00
|
|
|
BOOL got_digit = FALSE;
|
2010-03-29 00:04:32 +02:00
|
|
|
unsigned __int64 ret = 0;
|
|
|
|
|
2011-09-19 23:29:47 +02:00
|
|
|
TRACE("(%s %p %d %p)\n", debugstr_a(nptr), endptr, base, locale);
|
2010-03-29 00:04:32 +02:00
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(nptr != NULL)) return 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
|
|
|
|
if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
|
2010-03-29 00:04:32 +02:00
|
|
|
|
2019-11-22 16:41:23 +01:00
|
|
|
while(MSVCRT__isspace_l((unsigned char)*nptr, locale)) nptr++;
|
2010-03-29 00:04:32 +02:00
|
|
|
|
|
|
|
if(*nptr == '-') {
|
|
|
|
negative = TRUE;
|
|
|
|
nptr++;
|
|
|
|
} else if(*nptr == '+')
|
|
|
|
nptr++;
|
|
|
|
|
2019-03-26 11:31:01 +01:00
|
|
|
if((base==0 || base==16) && *nptr=='0' && MSVCRT__tolower_l(*(nptr+1), locale)=='x') {
|
2010-03-29 00:04:32 +02:00
|
|
|
base = 16;
|
|
|
|
nptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(base == 0) {
|
|
|
|
if(*nptr=='0')
|
|
|
|
base = 8;
|
|
|
|
else
|
|
|
|
base = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(*nptr) {
|
2019-03-26 11:31:01 +01:00
|
|
|
char cur = MSVCRT__tolower_l(*nptr, locale);
|
2010-03-29 00:04:32 +02:00
|
|
|
int v;
|
|
|
|
|
2016-02-18 16:09:55 +01:00
|
|
|
if(cur>='0' && cur<='9') {
|
2010-03-29 00:04:32 +02:00
|
|
|
if(cur >= '0'+base)
|
|
|
|
break;
|
|
|
|
v = *nptr-'0';
|
|
|
|
} else {
|
|
|
|
if(cur<'a' || cur>='a'+base-10)
|
|
|
|
break;
|
|
|
|
v = cur-'a'+10;
|
|
|
|
}
|
2015-06-08 12:00:55 +02:00
|
|
|
got_digit = TRUE;
|
2010-03-29 00:04:32 +02:00
|
|
|
|
|
|
|
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)
|
2015-06-08 12:00:55 +02:00
|
|
|
*endptr = (char*)(got_digit ? nptr : p);
|
2010-03-29 00:04:32 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2013-10-15 16:29:00 +02:00
|
|
|
static int ltoa_helper(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;
|
2013-09-27 08:43:20 +02:00
|
|
|
BOOL is_negative;
|
2010-10-11 12:25:15 +02:00
|
|
|
char buffer[33], *pos;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (value < 0 && radix == 10)
|
|
|
|
{
|
2013-09-27 08:43:20 +02:00
|
|
|
is_negative = TRUE;
|
2010-10-11 12:25:15 +02:00
|
|
|
val = -value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-27 08:43:20 +02:00
|
|
|
is_negative = FALSE;
|
2010-10-11 12:25:15 +02:00
|
|
|
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';
|
2012-07-26 11:05:32 +02:00
|
|
|
MSVCRT_INVALID_PMT("str[size] is too small", MSVCRT_ERANGE);
|
2010-10-11 12:25:15 +02:00
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(str, pos, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-15 16:29:00 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _ltoa_s (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
int CDECL MSVCRT__ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
|
2013-10-15 16:29:00 +02:00
|
|
|
{
|
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
|
|
|
|
{
|
|
|
|
str[0] = '\0';
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ltoa_helper(value, str, size, radix);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
int CDECL MSVCRT__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;
|
2013-09-27 08:43:20 +02:00
|
|
|
BOOL is_negative;
|
2010-11-02 22:02:52 +01:00
|
|
|
MSVCRT_wchar_t buffer[33], *pos;
|
|
|
|
size_t len;
|
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
|
2010-11-02 22:02:52 +01:00
|
|
|
{
|
2012-07-26 11:05:32 +02:00
|
|
|
str[0] = '\0';
|
2010-11-02 22:02:52 +01:00
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value < 0 && radix == 10)
|
|
|
|
{
|
2013-09-27 08:43:20 +02:00
|
|
|
is_negative = TRUE;
|
2010-11-02 22:02:52 +01:00
|
|
|
val = -value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-27 08:43:20 +02:00
|
|
|
is_negative = FALSE;
|
2010-11-02 22:02:52 +01:00
|
|
|
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--;
|
|
|
|
|
|
|
|
str[0] = '\0';
|
2012-07-26 11:05:32 +02:00
|
|
|
MSVCRT_INVALID_PMT("str[size] is too small", MSVCRT_ERANGE);
|
2010-11-02 22:02:52 +01:00
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(str, pos, len * sizeof(MSVCRT_wchar_t));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-15 21:59:55 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _itoa_s (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
int CDECL MSVCRT__itoa_s(int value, char *str, MSVCRT_size_t size, int radix)
|
2010-11-15 21:59:55 +01:00
|
|
|
{
|
2014-04-16 16:15:07 +02:00
|
|
|
return MSVCRT__ltoa_s(value, str, size, radix);
|
2010-11-15 21:59:55 +01:00
|
|
|
}
|
|
|
|
|
2013-10-01 11:28:09 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _itoa (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
char* CDECL MSVCRT__itoa(int value, char *str, int radix)
|
2013-10-01 11:28:09 +02:00
|
|
|
{
|
2013-10-15 16:29:00 +02:00
|
|
|
return ltoa_helper(value, str, MSVCRT_SIZE_MAX, radix) ? NULL : str;
|
2013-10-01 11:28:09 +02:00
|
|
|
}
|
|
|
|
|
2010-11-15 21:59:55 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _itow_s (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
int CDECL MSVCRT__itow_s(int value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
|
2010-11-15 21:59:55 +01:00
|
|
|
{
|
2014-04-16 16:15:07 +02:00
|
|
|
return MSVCRT__ltow_s(value, str, size, radix);
|
2010-11-15 21:59:55 +01:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
|
|
|
|
{
|
|
|
|
str[0] = '\0';
|
2010-05-05 13:37:33 +02:00
|
|
|
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) {
|
2012-07-26 11:05:32 +02:00
|
|
|
MSVCRT_INVALID_PMT("str[size] is too small", MSVCRT_EINVAL);
|
2010-05-05 13:37:33 +02:00
|
|
|
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;
|
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
|
|
|
|
{
|
|
|
|
str[0] = '\0';
|
2010-12-29 08:13:53 +01:00
|
|
|
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) {
|
2012-07-26 11:05:32 +02:00
|
|
|
MSVCRT_INVALID_PMT("str[size] is too small", MSVCRT_EINVAL);
|
2010-12-29 08:13:53 +01:00
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-03-25 13:37:29 +01:00
|
|
|
memcpy(str, pos, (buffer-pos+65)*sizeof(MSVCRT_wchar_t));
|
2010-12-29 08:13:53 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-21 09:57:44 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _ultoa_s (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
int CDECL MSVCRT__ultoa_s(MSVCRT_ulong value, char *str, MSVCRT_size_t size, int radix)
|
2010-10-21 09:57:44 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-28 21:53:38 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ultow_s (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
int CDECL MSVCRT__ultow_s(MSVCRT_ulong value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
|
2011-11-28 21:53:38 +01:00
|
|
|
{
|
|
|
|
MSVCRT_ulong digit;
|
|
|
|
WCHAR 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;
|
|
|
|
WCHAR *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;
|
|
|
|
}
|
|
|
|
|
2013-03-25 13:37:29 +01:00
|
|
|
memcpy(str, pos, len * sizeof(MSVCRT_wchar_t));
|
2011-11-28 21:53:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-15 22:00:01 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _i64toa_s (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
int CDECL MSVCRT__i64toa_s(__int64 value, char *str, MSVCRT_size_t size, int radix)
|
2010-11-15 22:00:01 +01:00
|
|
|
{
|
|
|
|
unsigned __int64 val;
|
|
|
|
unsigned int digit;
|
2013-09-27 08:43:20 +02:00
|
|
|
BOOL is_negative;
|
2010-11-15 22:00:01 +01:00
|
|
|
char buffer[65], *pos;
|
|
|
|
size_t len;
|
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
|
2010-11-15 22:00:01 +01:00
|
|
|
{
|
2012-07-26 11:05:32 +02:00
|
|
|
str[0] = '\0';
|
2010-11-15 22:00:01 +01:00
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value < 0 && radix == 10)
|
|
|
|
{
|
2013-09-27 08:43:20 +02:00
|
|
|
is_negative = TRUE;
|
2010-11-15 22:00:01 +01:00
|
|
|
val = -value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-27 08:43:20 +02:00
|
|
|
is_negative = FALSE;
|
2010-11-15 22:00:01 +01:00
|
|
|
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';
|
2012-07-26 11:05:32 +02:00
|
|
|
MSVCRT_INVALID_PMT("str[size] is too small", MSVCRT_ERANGE);
|
2010-11-15 22:00:01 +01:00
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(str, pos, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _i64tow_s (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
int CDECL MSVCRT__i64tow_s(__int64 value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
|
2010-11-15 22:00:01 +01:00
|
|
|
{
|
|
|
|
unsigned __int64 val;
|
|
|
|
unsigned int digit;
|
2013-09-27 08:43:20 +02:00
|
|
|
BOOL is_negative;
|
2010-11-15 22:00:01 +01:00
|
|
|
MSVCRT_wchar_t buffer[65], *pos;
|
|
|
|
size_t len;
|
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(size > 0)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(radix >= 2 && radix <= 36))
|
2010-11-15 22:00:01 +01:00
|
|
|
{
|
2012-07-26 11:05:32 +02:00
|
|
|
str[0] = '\0';
|
2010-11-15 22:00:01 +01:00
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value < 0 && radix == 10)
|
|
|
|
{
|
2013-09-27 08:43:20 +02:00
|
|
|
is_negative = TRUE;
|
2010-11-15 22:00:01 +01:00
|
|
|
val = -value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-27 08:43:20 +02:00
|
|
|
is_negative = FALSE;
|
2010-11-15 22:00:01 +01:00
|
|
|
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--;
|
|
|
|
|
|
|
|
str[0] = '\0';
|
2012-07-26 11:05:32 +02:00
|
|
|
MSVCRT_INVALID_PMT("str[size] is too small", MSVCRT_ERANGE);
|
2010-11-15 22:00:01 +01:00
|
|
|
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
|
2012-12-14 05:01:48 +01:00
|
|
|
|
2013-09-17 14:44:56 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* memcmp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int __cdecl MSVCRT_memcmp(const void *ptr1, const void *ptr2, MSVCRT_size_t n)
|
|
|
|
{
|
|
|
|
return memcmp(ptr1, ptr2, n);
|
|
|
|
}
|
|
|
|
|
2012-12-14 05:01:48 +01:00
|
|
|
/*********************************************************************
|
2012-12-24 12:10:21 +01:00
|
|
|
* memcpy (MSVCRT.@)
|
2012-12-14 05:01:48 +01:00
|
|
|
*/
|
2013-09-17 14:44:56 +02:00
|
|
|
void * __cdecl MSVCRT_memcpy(void *dst, const void *src, MSVCRT_size_t n)
|
2012-12-14 05:01:48 +01:00
|
|
|
{
|
2013-09-17 14:44:56 +02:00
|
|
|
return memmove(dst, src, n);
|
2012-12-14 05:01:48 +01:00
|
|
|
}
|
2012-12-24 12:10:21 +01:00
|
|
|
|
2013-09-17 14:45:11 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* memmove (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void * __cdecl MSVCRT_memmove(void *dst, const void *src, MSVCRT_size_t n)
|
|
|
|
{
|
|
|
|
return memmove(dst, src, n);
|
|
|
|
}
|
|
|
|
|
2013-03-27 16:11:59 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* memset (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void* __cdecl MSVCRT_memset(void *dst, int c, MSVCRT_size_t n)
|
|
|
|
{
|
|
|
|
return memset(dst, c, n);
|
|
|
|
}
|
|
|
|
|
2013-03-27 16:12:09 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strchr (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
char* __cdecl MSVCRT_strchr(const char *str, int c)
|
|
|
|
{
|
|
|
|
return strchr(str, c);
|
|
|
|
}
|
|
|
|
|
2013-09-17 14:45:53 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* strrchr (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
char* __cdecl MSVCRT_strrchr(const char *str, int c)
|
|
|
|
{
|
|
|
|
return strrchr(str, c);
|
|
|
|
}
|
|
|
|
|
2013-06-21 15:39:23 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* memchr (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void* __cdecl MSVCRT_memchr(const void *ptr, int c, MSVCRT_size_t n)
|
|
|
|
{
|
|
|
|
return memchr(ptr, c, n);
|
|
|
|
}
|
|
|
|
|
2013-09-17 14:45:20 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* strcmp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int __cdecl MSVCRT_strcmp(const char *str1, const char *str2)
|
|
|
|
{
|
2019-10-31 09:35:40 +01:00
|
|
|
while (*str1 && *str1 == *str2) { str1++; str2++; }
|
2020-01-16 11:37:03 +01:00
|
|
|
if ((unsigned char)*str1 > (unsigned char)*str2) return 1;
|
|
|
|
if ((unsigned char)*str1 < (unsigned char)*str2) return -1;
|
2019-10-31 09:35:40 +01:00
|
|
|
return 0;
|
2013-09-17 14:45:20 +02:00
|
|
|
}
|
|
|
|
|
2013-03-27 16:12:19 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strncmp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int __cdecl MSVCRT_strncmp(const char *str1, const char *str2, MSVCRT_size_t len)
|
|
|
|
{
|
2019-10-31 09:35:40 +01:00
|
|
|
if (!len) return 0;
|
|
|
|
while (--len && *str1 && *str1 == *str2) { str1++; str2++; }
|
2020-01-16 11:37:03 +01:00
|
|
|
return (unsigned char)*str1 - (unsigned char)*str2;
|
2013-03-27 16:12:19 +01:00
|
|
|
}
|
|
|
|
|
2012-12-24 12:10:21 +01:00
|
|
|
/*********************************************************************
|
2012-12-26 12:04:59 +01:00
|
|
|
* _strnicmp_l (MSVCRT.@)
|
2012-12-24 12:10:21 +01:00
|
|
|
*/
|
2012-12-26 12:04:59 +01:00
|
|
|
int __cdecl MSVCRT__strnicmp_l(const char *s1, const char *s2,
|
|
|
|
MSVCRT_size_t count, MSVCRT__locale_t locale)
|
2012-12-24 12:10:21 +01:00
|
|
|
{
|
2020-03-09 13:54:29 +01:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
2014-09-03 14:43:02 +02:00
|
|
|
int c1, c2;
|
2012-12-24 12:10:21 +01:00
|
|
|
|
2013-01-28 11:40:36 +01:00
|
|
|
if(s1==NULL || s2==NULL)
|
2012-12-24 12:10:21 +01:00
|
|
|
return MSVCRT__NLSCMPERROR;
|
|
|
|
|
2012-12-26 12:04:59 +01:00
|
|
|
if(!count)
|
|
|
|
return 0;
|
|
|
|
|
2020-03-09 13:54:29 +01:00
|
|
|
if(!locale)
|
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
|
|
|
|
|
|
|
if(!locinfo->lc_handle[MSVCRT_LC_CTYPE])
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
if ((c1 = *s1++) >= 'A' && c1 <= 'Z')
|
|
|
|
c1 -= 'A' - 'a';
|
|
|
|
if ((c2 = *s2++) >= 'A' && c2 <= 'Z')
|
|
|
|
c2 -= 'A' - 'a';
|
|
|
|
}while(--count && c1 && c1==c2);
|
|
|
|
|
|
|
|
return c1-c2;
|
|
|
|
}
|
|
|
|
|
2012-12-24 12:10:21 +01:00
|
|
|
do {
|
2020-03-09 13:54:29 +01:00
|
|
|
c1 = MSVCRT__tolower_l((unsigned char)*s1++, locale);
|
|
|
|
c2 = MSVCRT__tolower_l((unsigned char)*s2++, locale);
|
2012-12-26 12:04:59 +01:00
|
|
|
}while(--count && c1 && c1==c2);
|
2012-12-24 12:10:21 +01:00
|
|
|
|
|
|
|
return c1-c2;
|
|
|
|
}
|
|
|
|
|
2012-12-26 12:04:59 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _stricmp_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int __cdecl MSVCRT__stricmp_l(const char *s1, const char *s2, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return MSVCRT__strnicmp_l(s1, s2, -1, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strnicmp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int __cdecl MSVCRT__strnicmp(const char *s1, const char *s2, MSVCRT_size_t count)
|
|
|
|
{
|
|
|
|
return MSVCRT__strnicmp_l(s1, s2, count, NULL);
|
|
|
|
}
|
|
|
|
|
2012-12-24 12:10:21 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _stricmp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int __cdecl MSVCRT__stricmp(const char *s1, const char *s2)
|
|
|
|
{
|
2012-12-26 12:04:59 +01:00
|
|
|
return MSVCRT__strnicmp_l(s1, s2, -1, NULL);
|
2012-12-24 12:10:21 +01:00
|
|
|
}
|
2013-09-17 14:46:07 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strstr (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
char* __cdecl MSVCRT_strstr(const char *haystack, const char *needle)
|
|
|
|
{
|
2019-10-28 13:29:15 +01:00
|
|
|
MSVCRT_size_t i, j, len, needle_len, lps_len;
|
|
|
|
BYTE lps[256];
|
|
|
|
|
|
|
|
needle_len = MSVCRT_strlen(needle);
|
|
|
|
if (!needle_len) return (char*)haystack;
|
|
|
|
lps_len = needle_len > ARRAY_SIZE(lps) ? ARRAY_SIZE(lps) : needle_len;
|
|
|
|
|
|
|
|
lps[0] = 0;
|
|
|
|
len = 0;
|
|
|
|
i = 1;
|
|
|
|
while (i < lps_len)
|
|
|
|
{
|
|
|
|
if (needle[i] == needle[len]) lps[i++] = ++len;
|
|
|
|
else if (len) len = lps[len-1];
|
|
|
|
else lps[i++] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = j = 0;
|
|
|
|
while (haystack[i])
|
|
|
|
{
|
|
|
|
while (j < lps_len && haystack[i] && haystack[i] == needle[j])
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == needle_len) return (char*)haystack + i - j;
|
|
|
|
else if (j)
|
|
|
|
{
|
|
|
|
if (j == ARRAY_SIZE(lps) && !MSVCRT_strncmp(haystack + i, needle + j, needle_len - j))
|
|
|
|
return (char*)haystack + i - j;
|
|
|
|
j = lps[j-1];
|
|
|
|
}
|
|
|
|
else if (haystack[i]) i++;
|
|
|
|
}
|
|
|
|
return NULL;
|
2013-09-17 14:46:07 +02:00
|
|
|
}
|
2017-11-08 10:26:16 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _memicmp_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int __cdecl MSVCRT__memicmp_l(const char *s1, const char *s2, MSVCRT_size_t len, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
#if _MSVCR_VER == 0 || _MSVCR_VER >= 80
|
|
|
|
if (!s1 || !s2)
|
|
|
|
{
|
|
|
|
if (len)
|
|
|
|
MSVCRT_INVALID_PMT(NULL, EINVAL);
|
|
|
|
return len ? MSVCRT__NLSCMPERROR : 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while (len--)
|
|
|
|
{
|
|
|
|
if ((ret = MSVCRT__tolower_l(*s1, locale) - MSVCRT__tolower_l(*s2, locale)))
|
|
|
|
break;
|
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _memicmp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int __cdecl MSVCRT__memicmp(const char *s1, const char *s2, MSVCRT_size_t len)
|
|
|
|
{
|
|
|
|
return MSVCRT__memicmp_l(s1, s2, len, NULL);
|
|
|
|
}
|
2018-10-17 15:23:29 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strcspn (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t __cdecl MSVCRT_strcspn(const char *str, const char *reject)
|
|
|
|
{
|
2019-10-28 13:29:01 +01:00
|
|
|
BOOL rejects[256];
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
memset(rejects, 0, sizeof(rejects));
|
|
|
|
|
|
|
|
p = reject;
|
|
|
|
while(*p)
|
|
|
|
{
|
|
|
|
rejects[(unsigned char)*p] = TRUE;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = str;
|
|
|
|
while(*p && !rejects[(unsigned char)*p]) p++;
|
|
|
|
return p - str;
|
2018-10-17 15:23:29 +02:00
|
|
|
}
|
2018-10-17 15:23:37 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strpbrk (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
char* __cdecl MSVCRT_strpbrk(const char *str, const char *accept)
|
|
|
|
{
|
|
|
|
return strpbrk(str, accept);
|
|
|
|
}
|
2018-10-30 14:01:09 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __strncnt (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t __cdecl MSVCRT___strncnt(const char *str, MSVCRT_size_t size)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t ret = 0;
|
|
|
|
|
|
|
|
#if _MSVCR_VER >= 140
|
|
|
|
while (*str++ && size--)
|
|
|
|
#else
|
|
|
|
while (size-- && *str++)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2019-03-29 14:06:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef _CRTDLL
|
|
|
|
/*********************************************************************
|
|
|
|
* _strdec (CRTDLL.@)
|
|
|
|
*/
|
|
|
|
char * CDECL _strdec(const char *str1, const char *str2)
|
|
|
|
{
|
|
|
|
return (char *)(str2 - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strinc (CRTDLL.@)
|
|
|
|
*/
|
|
|
|
char * CDECL _strinc(const char *str)
|
|
|
|
{
|
|
|
|
return (char *)(str + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strnextc (CRTDLL.@)
|
|
|
|
*/
|
|
|
|
unsigned int CDECL _strnextc(const char *str)
|
|
|
|
{
|
|
|
|
return (unsigned char)str[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strninc (CRTDLL.@)
|
|
|
|
*/
|
|
|
|
char * CDECL _strninc(const char *str, size_t len)
|
|
|
|
{
|
|
|
|
return (char *)(str + len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strspnp (CRTDLL.@)
|
|
|
|
*/
|
|
|
|
char * CDECL _strspnp( const char *str1, const char *str2)
|
|
|
|
{
|
|
|
|
str1 += strspn( str1, str2 );
|
|
|
|
return *str1 ? (char*)str1 : NULL;
|
|
|
|
}
|
|
|
|
#endif
|