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"
|
|
|
|
|
2006-01-14 17:40:29 +01:00
|
|
|
#include <stdlib.h>
|
2001-04-23 20:20:55 +02:00
|
|
|
#include "msvcrt.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.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
char* CDECL _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
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strnset (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
char* CDECL _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.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
char* CDECL _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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* atof (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_atof( const char *str )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
|
|
|
return atof( str );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* 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
|
|
|
{
|
|
|
|
return strtod( str, end );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* 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
|
|
|
{
|
|
|
|
/* FIXME: handle Windows locale */
|
|
|
|
return strcoll( str1, str2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strxfrm (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_size_t CDECL MSVCRT_strxfrm( char *dest, const char *src, MSVCRT_size_t len )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
|
|
|
/* FIXME: handle Windows locale */
|
|
|
|
return strxfrm( dest, src, len );
|
|
|
|
}
|
|
|
|
|
2005-05-23 12:27:58 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _stricoll (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL MSVCRT__stricoll( const char* str1, const char* str2 )
|
2005-05-23 12:27:58 +02:00
|
|
|
{
|
|
|
|
/* FIXME: handle collates */
|
|
|
|
TRACE("str1 %s str2 %s\n", debugstr_a(str1), debugstr_a(str2));
|
|
|
|
return lstrcmpiA( str1, str2 );
|
|
|
|
}
|
2006-12-17 18:56:50 +01:00
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* _atoldbl (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__atoldbl(_LDOUBLE * value, char * str)
|
|
|
|
{
|
|
|
|
/* FIXME needs error checking for huge/small values */
|
|
|
|
#ifdef HAVE_STRTOLD
|
|
|
|
TRACE("str %s value %p\n",str,value);
|
|
|
|
value->x = strtold(str,0);
|
|
|
|
#else
|
|
|
|
FIXME("stub, str %s value %p\n",str,value);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|