2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll wide-char functions
|
|
|
|
*
|
|
|
|
* Copyright 1999 Alexandre Julliard
|
|
|
|
* Copyright 2000 Jon Griffiths
|
|
|
|
*/
|
2001-01-22 03:21:54 +01:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
2001-01-11 00:59:25 +01:00
|
|
|
#include "msvcrt.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
2001-04-11 01:25:25 +02:00
|
|
|
#include "msvcrt/stdio.h"
|
|
|
|
#include "msvcrt/stdlib.h"
|
|
|
|
#include "msvcrt/string.h"
|
|
|
|
#include "msvcrt/wctype.h"
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
DEFAULT_DEBUG_CHANNEL(msvcrt);
|
|
|
|
|
2001-01-22 03:21:54 +01:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/* INTERNAL: MSVCRT_malloc() based wstrndup */
|
2001-04-11 01:25:25 +02:00
|
|
|
WCHAR* msvcrt_wstrndup(LPCWSTR buf, unsigned int size)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
WCHAR* ret;
|
|
|
|
unsigned int len = strlenW(buf), max_len;
|
|
|
|
|
|
|
|
max_len = size <= len? size : len + 1;
|
|
|
|
|
|
|
|
ret = MSVCRT_malloc(max_len * sizeof (WCHAR));
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
memcpy(ret,buf,max_len * sizeof (WCHAR));
|
|
|
|
ret[max_len] = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _wcsdup (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
WCHAR* _wcsdup( const WCHAR* str )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-04-11 01:25:25 +02:00
|
|
|
WCHAR* ret = NULL;
|
2001-01-11 00:59:25 +01:00
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
int size = (strlenW(str) + 1) * sizeof(WCHAR);
|
|
|
|
ret = MSVCRT_malloc( size );
|
|
|
|
if (ret) memcpy( ret, str, size );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _wcsicoll (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
INT _wcsicoll( const WCHAR* str1, const WCHAR* str2 )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* FIXME: handle collates */
|
|
|
|
return strcmpiW( str1, str2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _wcsnset (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
WCHAR* _wcsnset( WCHAR* str, WCHAR c, MSVCRT_size_t n )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-04-11 01:25:25 +02:00
|
|
|
WCHAR* ret = str;
|
2001-01-11 00:59:25 +01:00
|
|
|
while ((n-- > 0) && *str) *str++ = c;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _wcsrev (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
WCHAR* _wcsrev( WCHAR* str )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-04-11 01:25:25 +02:00
|
|
|
WCHAR* ret = str;
|
|
|
|
WCHAR* end = str + strlenW(str) - 1;
|
2001-01-11 00:59:25 +01:00
|
|
|
while (end > str)
|
|
|
|
{
|
|
|
|
WCHAR t = *end;
|
|
|
|
*end-- = *str;
|
|
|
|
*str++ = t;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _wcsset (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
WCHAR* _wcsset( WCHAR* str, WCHAR c )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-04-11 01:25:25 +02:00
|
|
|
WCHAR* ret = str;
|
2001-01-11 00:59:25 +01:00
|
|
|
while (*str) *str++ = c;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _vsnwprintf (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _vsnwprintf(WCHAR *str, unsigned int len,
|
2001-01-22 03:21:54 +01:00
|
|
|
const WCHAR *format, va_list valist)
|
|
|
|
{
|
|
|
|
/* If you fix a bug in this function, fix it in ntdll/wcstring.c also! */
|
|
|
|
unsigned int written = 0;
|
|
|
|
const WCHAR *iter = format;
|
|
|
|
char bufa[256], fmtbufa[64], *fmta;
|
|
|
|
|
|
|
|
TRACE("(%d,%s)\n",len,debugstr_w(format));
|
|
|
|
|
|
|
|
while (*iter)
|
|
|
|
{
|
|
|
|
while (*iter && *iter != (WCHAR)L'%')
|
|
|
|
{
|
|
|
|
if (written++ >= len)
|
|
|
|
return -1;
|
|
|
|
*str++ = *iter++;
|
|
|
|
}
|
|
|
|
if (*iter == (WCHAR)L'%')
|
|
|
|
{
|
|
|
|
fmta = fmtbufa;
|
|
|
|
*fmta++ = *iter++;
|
|
|
|
while (*iter == (WCHAR)L'0' ||
|
|
|
|
*iter == (WCHAR)L'+' ||
|
|
|
|
*iter == (WCHAR)L'-' ||
|
|
|
|
*iter == (WCHAR)L' ' ||
|
|
|
|
*iter == (WCHAR)L'0' ||
|
|
|
|
*iter == (WCHAR)L'*' ||
|
|
|
|
*iter == (WCHAR)L'#')
|
|
|
|
{
|
|
|
|
if (*iter == (WCHAR)L'*')
|
|
|
|
{
|
|
|
|
char *buffiter = bufa;
|
|
|
|
int fieldlen = va_arg(valist, int);
|
|
|
|
sprintf(buffiter, "%d", fieldlen);
|
|
|
|
while (*buffiter)
|
|
|
|
*fmta++ = *buffiter++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*fmta++ = *iter;
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (isdigit(*iter))
|
|
|
|
*fmta++ = *iter++;
|
|
|
|
|
|
|
|
if (*iter == (WCHAR)L'.')
|
|
|
|
{
|
|
|
|
*fmta++ = *iter++;
|
|
|
|
if (*iter == (WCHAR)L'*')
|
|
|
|
{
|
|
|
|
char *buffiter = bufa;
|
|
|
|
int fieldlen = va_arg(valist, int);
|
|
|
|
sprintf(buffiter, "%d", fieldlen);
|
|
|
|
while (*buffiter)
|
|
|
|
*fmta++ = *buffiter++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
while (isdigit(*iter))
|
|
|
|
*fmta++ = *iter++;
|
|
|
|
}
|
|
|
|
if (*iter == (WCHAR)L'h' ||
|
|
|
|
*iter == (WCHAR)L'l')
|
|
|
|
{
|
|
|
|
*fmta++ = *iter++;
|
|
|
|
*fmta++ = *iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (*iter)
|
|
|
|
{
|
|
|
|
case (WCHAR)L's':
|
|
|
|
{
|
|
|
|
static const WCHAR none[] = { '(', 'n', 'u', 'l', 'l', ')', 0 };
|
|
|
|
const WCHAR *wstr = va_arg(valist, const WCHAR *);
|
|
|
|
const WCHAR *striter = wstr ? wstr : none;
|
|
|
|
while (*striter)
|
|
|
|
{
|
|
|
|
if (written++ >= len)
|
|
|
|
return -1;
|
|
|
|
*str++ = *striter++;
|
|
|
|
}
|
|
|
|
iter++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case (WCHAR)L'c':
|
|
|
|
if (written++ >= len)
|
|
|
|
return -1;
|
2001-01-22 20:26:42 +01:00
|
|
|
*str++ = (WCHAR)va_arg(valist, int);
|
2001-01-22 03:21:54 +01:00
|
|
|
iter++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
/* For non wc types, use system sprintf and append to wide char output */
|
|
|
|
/* FIXME: for unrecognised types, should ignore % when printing */
|
|
|
|
char *bufaiter = bufa;
|
|
|
|
if (*iter == (WCHAR)L'p')
|
|
|
|
sprintf(bufaiter, "%08lX", va_arg(valist, long));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*fmta++ = *iter;
|
|
|
|
*fmta = '\0';
|
2001-04-16 21:00:42 +02:00
|
|
|
if (*iter == (WCHAR)L'f')
|
|
|
|
sprintf(bufaiter, fmtbufa, va_arg(valist, double));
|
|
|
|
else
|
|
|
|
sprintf(bufaiter, fmtbufa, va_arg(valist, void *));
|
2001-01-22 03:21:54 +01:00
|
|
|
}
|
|
|
|
while (*bufaiter)
|
|
|
|
{
|
|
|
|
if (written++ >= len)
|
|
|
|
return -1;
|
|
|
|
*str++ = *bufaiter++;
|
|
|
|
}
|
|
|
|
iter++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (written >= len)
|
|
|
|
return -1;
|
|
|
|
*str++ = (WCHAR)L'\0';
|
|
|
|
return (int)written;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* vswprintf (MSVCRT.@)
|
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
int MSVCRT_vswprintf( WCHAR* str, const WCHAR* format, va_list args )
|
2001-01-22 03:21:54 +01:00
|
|
|
{
|
2001-04-10 23:16:07 +02:00
|
|
|
return _vsnwprintf( str, INT_MAX, format, args );
|
2001-01-22 03:21:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* wcscoll (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
int MSVCRT_wcscoll( const WCHAR* str1, const WCHAR* str2 )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* FIXME: handle collates */
|
|
|
|
return strcmpW( str1, str2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* wcspbrk (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
WCHAR* MSVCRT_wcspbrk( const WCHAR* str, const WCHAR* accept )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-04-11 01:25:25 +02:00
|
|
|
const WCHAR* p;
|
2001-01-11 00:59:25 +01:00
|
|
|
while (*str)
|
|
|
|
{
|
2001-04-11 01:25:25 +02:00
|
|
|
for (p = accept; *p; p++) if (*p == *str) return (WCHAR*)str;
|
2001-01-11 00:59:25 +01:00
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* wctomb (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
INT MSVCRT_wctomb( char *dst, WCHAR ch )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return WideCharToMultiByte( CP_ACP, 0, &ch, 1, dst, 6, NULL, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswalnum (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
INT MSVCRT_iswalnum( WCHAR wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & (C1_ALPHA|C1_DIGIT|C1_LOWER|C1_UPPER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswalpha (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
INT MSVCRT_iswalpha( WCHAR wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & (C1_ALPHA|C1_LOWER|C1_UPPER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswcntrl (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
INT MSVCRT_iswcntrl( WCHAR wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_CNTRL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswdigit (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
INT MSVCRT_iswdigit( WCHAR wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_DIGIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswgraph (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
INT MSVCRT_iswgraph( WCHAR wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & (C1_ALPHA|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswlower (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
INT MSVCRT_iswlower( WCHAR wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_LOWER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswprint (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
INT MSVCRT_iswprint( WCHAR wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & (C1_ALPHA|C1_BLANK|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswpunct (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
INT MSVCRT_iswpunct( WCHAR wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_PUNCT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswspace (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
INT MSVCRT_iswspace( WCHAR wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_SPACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswupper (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
INT MSVCRT_iswupper( WCHAR wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_UPPER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* iswxdigit (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
INT MSVCRT_iswxdigit( WCHAR wc )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_XDIGIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _itow (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
WCHAR* _itow(int value,WCHAR* out,int base)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char buf[64];
|
|
|
|
_itoa(value, buf, base);
|
|
|
|
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buf, -1, out, 128);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ltow (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
WCHAR* _ltow(long value,WCHAR* out,int base)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
_ltoa(value, buf, base);
|
|
|
|
MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, buf, -1, out, 128);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|