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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
|
|
|
|
2001-04-23 20:20:55 +02:00
|
|
|
#include "msvcrt.h"
|
2001-04-11 01:25:25 +02:00
|
|
|
#include "msvcrt/stdlib.h"
|
|
|
|
#include "msvcrt/string.h"
|
2001-01-11 00:59:25 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
/* INTERNAL: MSVCRT_malloc() based strndup */
|
2001-04-10 23:16:07 +02:00
|
|
|
char* msvcrt_strndup(const char* buf, unsigned int size)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char* ret;
|
|
|
|
unsigned int len = strlen(buf), max_len;
|
|
|
|
|
|
|
|
max_len = size <= len? size : len + 1;
|
|
|
|
|
|
|
|
ret = MSVCRT_malloc(max_len);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
memcpy(ret,buf,max_len);
|
|
|
|
ret[max_len] = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strdec (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char* _strdec(const char* str1, const char* str2)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* Hmm. While the docs suggest that the following should work... */
|
|
|
|
/* return (str2<=str1?0:str2-1); */
|
|
|
|
/* ...Version 2.50.4170 (NT) from win98 constantly decrements! */
|
|
|
|
str1 = str1; /* remove warning */
|
|
|
|
return (char *)str2-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* _mbsdup (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
* _strdup (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char* _strdup(const char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char * ret = MSVCRT_malloc(strlen(str)+1);
|
|
|
|
if (ret) strcpy( ret, str );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strinc (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char* _strinc(const char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return (char*)str+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strnextc (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
unsigned int _strnextc(const char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return (unsigned int)*str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strninc (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Return a pointer to the 'n'th character in a string
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char* _strninc(char* str, unsigned int n)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return str + n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strnset (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char* _strnset(char* str, int value, unsigned int len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (len > 0 && str)
|
|
|
|
while (*str && len--)
|
|
|
|
*str++ = value;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strrev (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char* _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.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char* _strset(char* str, int value)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char *ptr = str;
|
|
|
|
while (*ptr)
|
|
|
|
*ptr++ = value;
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strncnt (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
unsigned int _strncnt(char* str, unsigned int max)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
unsigned int len = strlen(str);
|
|
|
|
return (len > max? max : len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strspnp (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char* _strspnp(char* str1, char* str2)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
str1 += strspn(str1,str2);
|
|
|
|
return *str1? str1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _swab (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
void _swab(char* src, char* dst, int len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (len > 1)
|
|
|
|
{
|
|
|
|
len = (unsigned)len >> 1;
|
|
|
|
|
|
|
|
while (len--) {
|
|
|
|
*dst++ = src[1];
|
|
|
|
*dst++ = *src++;
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|