- Sync some changes in strings from libcntpr.

- Move string implementation (in "header" files) into /string dir.
- Copy over libcntpr-specific implementations into _nt.c files (for now, later they could do with a define).
- libcntpr's is now almost fully syncronized and could be merged into the tree except for "except" directory.

svn path=/trunk/; revision=30283
This commit is contained in:
Aleksey Bragin 2007-11-08 21:06:20 +00:00
parent c8a87ec7b8
commit 375959c206
46 changed files with 502 additions and 246 deletions

View file

@ -1,112 +1,144 @@
/* /*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/stdlib/itoa.c * FILE: lib/crt/??????
* PURPOSE: converts a integer to ascii * PURPOSE: Unknown
* PROGRAMER: * PROGRAMER: Unknown
* UPDATE HISTORY: * UPDATE HISTORY:
* 1995: Created * 25/11/05: Added license header
* 1998: Added ltoa by Ariadne
*/ */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h> #include <precomp.h>
/* /*
* @implemented * @implemented
* copy _i64toa from wine cvs 2006 month 05 day 21
*/ */
char* _itoa(int value, char* string, int radix) char *
_i64toa(__int64 value, char *string, int radix)
{ {
char tmp[33]; ULONGLONG val;
char* tp = tmp; int negative;
int i; char buffer[65];
unsigned v; char *pos;
int sign; int digit;
char* sp;
if (radix > 36 || radix <= 1) if (value < 0 && radix == 10) {
{ negative = 1;
__set_errno(EDOM); val = -value;
return 0; } else {
} negative = 0;
val = value;
} /* if */
sign = (radix == 10 && value < 0); pos = &buffer[64];
if (sign) *pos = '\0';
v = -value;
else
v = (unsigned)value;
while (v || tp == tmp)
{
i = v % radix;
v = v / radix;
if (i < 10)
*tp++ = i+'0';
else
*tp++ = i + 'a' - 10;
}
if (string == 0) do {
string = (char*)malloc((tp-tmp)+sign+1); digit = val % radix;
sp = string; val = val / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (val != 0L);
if (sign) if (negative) {
*sp++ = '-'; *--pos = '-';
while (tp > tmp) } /* if */
*sp++ = *--tp;
*sp = 0; memcpy(string, pos, &buffer[64] - pos + 1);
return string; return string;
} }
/*
* @implemented
* copy _i64toa from wine cvs 2006 month 05 day 21
*/
char *
_ui64toa(unsigned __int64 value, char *string, int radix)
{
char buffer[65];
char *pos;
int digit;
pos = &buffer[64];
*pos = '\0';
do {
digit = value % radix;
value = value / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (value != 0L);
memcpy(string, pos, &buffer[64] - pos + 1);
return string;
}
/* /*
* @implemented * @implemented
*/ */
char* _ltoa(long value, char* string, int radix) char *
_itoa(int value, char *string, int radix)
{ {
char tmp[33]; return _ltoa(value, string, radix);
char* tp = tmp;
long i;
unsigned long v;
int sign;
char* sp;
if (radix > 36 || radix <= 1)
{
__set_errno(EDOM);
return 0;
}
sign = (radix == 10 && value < 0);
if (sign)
v = -value;
else
v = (unsigned long)value;
while (v || tp == tmp)
{
i = v % radix;
v = v / radix;
if (i < 10)
*tp++ = i+'0';
else
*tp++ = i + 'a' - 10;
}
if (string == 0)
string = (char*)malloc((tp-tmp)+sign+1);
sp = string;
if (sign)
*sp++ = '-';
while (tp > tmp)
*sp++ = *--tp;
*sp = 0;
return string;
} }
/* /*
* @implemented * @implemented
* copy it from wine 0.9.0 with small modifcations do check for NULL
*/ */
char* ultoa(unsigned long value, char* string, int radix) char *
_ltoa(long value, char *string, int radix)
{
unsigned long val;
int negative;
char buffer[33];
char *pos;
int digit;
if (value < 0 && radix == 10) {
negative = 1;
val = -value;
} else {
negative = 0;
val = value;
} /* if */
pos = &buffer[32];
*pos = '\0';
do {
digit = val % radix;
val = val / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (val != 0L);
if (negative) {
*--pos = '-';
} /* if */
memcpy(string, pos, &buffer[32] - pos + 1);
return string;
}
/*
* @implemented
* copy it from wine 0.9.0 with small modifcations do check for NULL
*/
char *
_ultoa(unsigned long value, char *string, int radix)
{ {
char buffer[33]; char buffer[33];
char *pos; char *pos;
@ -131,5 +163,6 @@ char* ultoa(unsigned long value, char* string, int radix)
} while (value != 0L); } while (value != 0L);
memcpy(string, pos, &buffer[32] - pos + 1); memcpy(string, pos, &buffer[32] - pos + 1);
return string; return string;
} }

View file

@ -1,16 +1,11 @@
/* $Id$ /*
*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/stdlib/itow.c * FILE: lib/sdk/crt/itow.c
* PURPOSE: converts a integer to wchar_t * PURPOSE: converts a integer to wchar_t
* PROGRAMER: * PROGRAMER:
* UPDATE HISTORY: * UPDATE HISTORY:
* 1995: Created
* 1998: Added ltoa by Ariadne
* 2000: derived from ./itoa.c by ea
*/ */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h> #include <precomp.h>
@ -18,18 +13,96 @@
* @implemented * @implemented
* from wine cvs 2006-05-21 * from wine cvs 2006-05-21
*/ */
wchar_t* _itow(int value, wchar_t* string, int radix) wchar_t *
_i64tow(__int64 value, wchar_t *string, int radix)
{ {
return _ltow(value, string, radix); ULONGLONG val;
int negative;
WCHAR buffer[65];
PWCHAR pos;
WCHAR digit;
if (value < 0 && radix == 10) {
negative = 1;
val = -value;
} else {
negative = 0;
val = value;
} /* if */
pos = &buffer[64];
*pos = '\0';
do {
digit = val % radix;
val = val / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (val != 0L);
if (negative) {
*--pos = '-';
} /* if */
if (string != NULL) {
memcpy(string, pos, (&buffer[64] - pos + 1) * sizeof(WCHAR));
} /* if */
return string;
} }
/*
* @implemented
*/
wchar_t *
_ui64tow(unsigned __int64 value, wchar_t *string, int radix)
{
WCHAR buffer[65];
PWCHAR pos;
WCHAR digit;
pos = &buffer[64];
*pos = '\0';
do {
digit = value % radix;
value = value / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (value != 0L);
if (string != NULL) {
memcpy(string, pos, (&buffer[64] - pos + 1) * sizeof(WCHAR));
} /* if */
return string;
}
/* /*
* @implemented * @implemented
* from wine cvs 2006-05-21 * from wine cvs 2006-05-21
*/ */
wchar_t* _ltow(long value, wchar_t* string, int radix) wchar_t *
_itow(int value, wchar_t *string, int radix)
{ {
unsigned long val; return _ltow(value, string, radix);
}
/*
* @implemented
* from wine cvs 2006-05-21
*/
wchar_t *
_ltow(long value, wchar_t *string, int radix)
{
unsigned long val;
int negative; int negative;
WCHAR buffer[33]; WCHAR buffer[33];
PWCHAR pos; PWCHAR pos;
@ -60,17 +133,19 @@ wchar_t* _ltow(long value, wchar_t* string, int radix)
*--pos = '-'; *--pos = '-';
} /* if */ } /* if */
if (str != NULL) { if (string != NULL) {
memcpy(string, pos, (&buffer[32] - pos + 1) * sizeof(WCHAR)); memcpy(string, pos, (&buffer[32] - pos + 1) * sizeof(WCHAR));
} /* if */ } /* if */
return string; return string;
} }
/* /*
* @implemented * @implemented
* from wine cvs 2006-05-21 * from wine cvs 2006-05-21
*/ */
wchar_t* _ultow(unsigned long value, wchar_t* string, int radix) wchar_t *
_ultow(unsigned long value, wchar_t *string, int radix)
{ {
WCHAR buffer[33]; WCHAR buffer[33];
PWCHAR pos; PWCHAR pos;

View file

@ -0,0 +1,60 @@
#define WIN32_NO_STATUS
#include <windows.h>
#include <ndk/umtypes.h>
#include <ndk/rtlfuncs.h>
#include <string.h>
/*
* @implemented
*/
int mbtowc (wchar_t *wchar, const char *mbchar, size_t count)
{
NTSTATUS Status;
ULONG Size;
if (wchar == NULL)
return 0;
Status = RtlMultiByteToUnicodeN (wchar,
sizeof(WCHAR),
&Size,
mbchar,
count);
if (!NT_SUCCESS(Status))
return -1;
return (int)Size;
}
/*
* @implemented
*/
size_t mbstowcs (wchar_t *wcstr, const char *mbstr, size_t count)
{
NTSTATUS Status;
ULONG Size;
ULONG Length;
Length = strlen (mbstr);
if (wcstr == NULL)
{
RtlMultiByteToUnicodeSize (&Size,
mbstr,
Length);
return (size_t)Size;
}
Status = RtlMultiByteToUnicodeN (wcstr,
count,
&Size,
mbstr,
Length);
if (!NT_SUCCESS(Status))
return -1;
return (size_t)Size;
}
/* EOF */

View file

@ -2,6 +2,6 @@
*/ */
#include <string.h> #include <string.h>
#include "internal/tcscat.h" #include "tcscat.h"
/* EOF */ /* EOF */

View file

@ -3,6 +3,6 @@
#define _XINT int #define _XINT int
#include <string.h> #include <string.h>
#include "internal/tcschr.h" #include "tcschr.h"
/* EOF */ /* EOF */

View file

@ -2,6 +2,6 @@
*/ */
#include <string.h> #include <string.h>
#include "internal/tcscmp.h" #include "tcscmp.h"
/* EOF */ /* EOF */

View file

@ -2,6 +2,6 @@
*/ */
#include <string.h> #include <string.h>
#include "internal/tcscpy.h" #include "tcscpy.h"
/* EOF */ /* EOF */

View file

@ -1,4 +1,3 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h> #include <precomp.h>
/* /*

View file

@ -2,6 +2,6 @@
*/ */
#include <string.h> #include <string.h>
#include "internal/tcslen.h" #include "tcslen.h"
/* EOF */ /* EOF */

View file

@ -1,12 +1,3 @@
/*
* The C RunTime DLL
*
* Implements C run-time functionality as known from UNIX.
*
* Copyright 1996,1998 Marcus Meissner
* Copyright 1996 Jukka Iivonen
* Copyright 1997 Uwe Bonnes
*/
#include <precomp.h> #include <precomp.h>

View file

@ -2,6 +2,6 @@
*/ */
#include <string.h> #include <string.h>
#include "internal/tcsncat.h" #include "tcsncat.h"
/* EOF */ /* EOF */

View file

@ -2,6 +2,6 @@
*/ */
#include <string.h> #include <string.h>
#include "internal/tcsncmp.h" #include "tcsncmp.h"
/* EOF */ /* EOF */

View file

@ -1,6 +1,6 @@
/* $Id$ /* $Id$
*/ */
#include <string.h> #include <string.h>
#include "internal/tcsncpy.h" #include "tcsncpy.h"
/* EOF */ /* EOF */

View file

@ -1,4 +1,3 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h> #include <precomp.h>
/* /*

View file

@ -2,6 +2,6 @@
*/ */
#include <string.h> #include <string.h>
#include "internal/tcsnlen.h" #include "tcsnlen.h"
/* EOF */ /* EOF */

View file

@ -3,6 +3,6 @@
#define _XINT int #define _XINT int
#include <string.h> #include <string.h>
#include "internal/tcsrchr.h" #include "tcsrchr.h"
/* EOF */ /* EOF */

View file

@ -13,11 +13,11 @@
/* /*
* @implemented * @implemented
*/ */
char* _strnset (char* szToFill, int szFill, size_t sizeMaxFill) char* _strnset(char* szToFill, int szFill, size_t sizeMaxFill)
{ {
char *t = szToFill; char *t = szToFill;
size_t i = 0; int i = 0;
while( *szToFill != 0 && i < sizeMaxFill) while (*szToFill != 0 && i < (int) sizeMaxFill)
{ {
*szToFill = szFill; *szToFill = szFill;
szToFill++; szToFill++;
@ -30,10 +30,10 @@ char* _strnset (char* szToFill, int szFill, size_t sizeMaxFill)
/* /*
* @implemented * @implemented
*/ */
char* _strset (char* szToFill, int szFill) char* _strset(char* szToFill, int szFill)
{ {
char *t = szToFill; char *t = szToFill;
while( *szToFill != 0 ) while (*szToFill != 0)
{ {
*szToFill = szFill; *szToFill = szFill;
szToFill++; szToFill++;

View file

@ -8,14 +8,12 @@
* 25/11/05: Added license header * 25/11/05: Added license header
*/ */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h> #include <precomp.h>
/* /*
* @implemented * @implemented
*/ */
char *strstr(const char *s, const char *find) char *
strstr(const char *s, const char *find)
{ {
char c, sc; char c, sc;
size_t len; size_t len;
@ -31,5 +29,5 @@ char *strstr(const char *s, const char *find)
} while (strncmp(s, find, len) != 0); } while (strncmp(s, find, len) != 0);
s--; s--;
} }
return (char *)s; return (char *)((size_t)s);
} }

View file

@ -1,4 +1,3 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h> #include <precomp.h>
/* /*
@ -80,11 +79,10 @@ strtol(const char *nptr, char **endptr, int base)
if (any < 0) if (any < 0)
{ {
acc = neg ? LONG_MIN : LONG_MAX; acc = neg ? LONG_MIN : LONG_MAX;
__set_errno(ERANGE);
} }
else if (neg) else if (neg)
acc = -acc; acc = -acc;
if (endptr != 0) if (endptr != 0)
*endptr = any ? (char *)s - 1 : (char *)nptr; *endptr = any ? (char *)((size_t)(s - 1)) : (char *)((size_t)nptr);
return acc; return acc;
} }

View file

@ -1,4 +1,3 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h> #include <precomp.h>
#include <ctype.h> #include <ctype.h>
@ -64,11 +63,10 @@ strtoul(const char *nptr, char **endptr, int base)
if (any < 0) if (any < 0)
{ {
acc = ULONG_MAX; acc = ULONG_MAX;
__set_errno(ERANGE);
} }
else if (neg) else if (neg)
acc = -acc; acc = -acc;
if (endptr != 0) if (endptr != 0)
*endptr = any ? (char *)s - 1 : (char *)nptr; *endptr = any ? (char *)((size_t)(s - 1)) : (char *)((size_t)nptr);
return acc; return acc;
} }

View file

@ -1,24 +1,12 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h> #include <precomp.h>
#if defined (_MSC_VER) unsigned long long
#define UINT64_MAX 0xffffffffffffffff
#endif
/*
* Convert a string to an unsigned long integer.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
UINT64
strtoull(const char *nptr, char **endptr, int base) strtoull(const char *nptr, char **endptr, int base)
{ {
const char *s = nptr; const char *s = nptr;
UINT64 acc; unsigned long long acc;
int c; int c;
UINT64 cutoff; unsigned long long cutoff;
int neg = 0, any, cutlim; int neg = 0, any, cutlim;
/* /*
@ -43,8 +31,8 @@ strtoull(const char *nptr, char **endptr, int base)
} }
if (base == 0) if (base == 0)
base = c == '0' ? 8 : 10; base = c == '0' ? 8 : 10;
cutoff = UINT64_MAX / base; cutoff = (unsigned long long)ULLONG_MAX / (unsigned long long)base;
cutlim = (int)(UINT64_MAX % base); cutlim = (unsigned long long)ULLONG_MAX % (unsigned long long)base;
for (acc = 0, any = 0;; c = *s++) for (acc = 0, any = 0;; c = *s++)
{ {
if (isdigit(c)) if (isdigit(c))
@ -65,12 +53,11 @@ strtoull(const char *nptr, char **endptr, int base)
} }
if (any < 0) if (any < 0)
{ {
acc = UINT64_MAX; acc = ULLONG_MAX;
__set_errno ( ERANGE );
} }
else if (neg) else if (neg)
acc = -acc; acc = -acc;
if (endptr != 0) if (endptr != 0)
*endptr = any ? (char *)s - 1 : (char *)nptr; *endptr = any ? (char *)((size_t)(s - 1)) : (char *)((size_t)nptr);
return acc; return acc;
} }

View file

@ -3,6 +3,6 @@
#define _UNICODE #define _UNICODE
#include <wchar.h> #include <wchar.h>
#include "internal/tcscat.h" #include "tcscat.h"
/* EOF */ /* EOF */

View file

@ -4,6 +4,6 @@
#define _UNICODE #define _UNICODE
#define _XINT wchar_t #define _XINT wchar_t
#include <wchar.h> #include <wchar.h>
#include "internal/tcschr.h" #include "tcschr.h"
/* EOF */ /* EOF */

View file

@ -3,6 +3,6 @@
#define _UNICODE #define _UNICODE
#include <wchar.h> #include <wchar.h>
#include "internal/tcscmp.h" #include "tcscmp.h"
/* EOF */ /* EOF */

View file

@ -3,6 +3,6 @@
#define _UNICODE #define _UNICODE
#include <wchar.h> #include <wchar.h>
#include "internal/tcscpy.h" #include "tcscpy.h"
/* EOF */ /* EOF */

View file

@ -3,6 +3,6 @@
#define _UNICODE #define _UNICODE
#include <wchar.h> #include <wchar.h>
#include "internal/tcslen.h" #include "tcslen.h"
/* EOF */ /* EOF */

View file

@ -3,6 +3,6 @@
#define _UNICODE #define _UNICODE
#include <wchar.h> #include <wchar.h>
#include "internal/tcsncat.h" #include "tcsncat.h"
/* EOF */ /* EOF */

View file

@ -3,6 +3,6 @@
#define _UNICODE #define _UNICODE
#include <wchar.h> #include <wchar.h>
#include "internal/tcsncmp.h" #include "tcsncmp.h"
/* EOF */ /* EOF */

View file

@ -3,6 +3,6 @@
#define _UNICODE #define _UNICODE
#include <wchar.h> #include <wchar.h>
#include "internal/tcsncpy.h" #include "tcsncpy.h"
/* EOF */ /* EOF */

View file

@ -3,6 +3,6 @@
#define _UNICODE #define _UNICODE
#include <wchar.h> #include <wchar.h>
#include "internal/tcsnlen.h" #include "tcsnlen.h"
/* EOF */ /* EOF */

View file

@ -4,6 +4,6 @@
#define _UNICODE #define _UNICODE
#define _XINT wchar_t #define _XINT wchar_t
#include <wchar.h> #include <wchar.h>
#include "internal/tcsrchr.h" #include "tcsrchr.h"
/* EOF */ /* EOF */

View file

@ -9,37 +9,89 @@
*/ */
#include <precomp.h> #include <precomp.h>
/* /*
* @implemented * @implemented
*/ */
long wcstol(const wchar_t *cp,wchar_t **endp,int base) long
wcstol(const wchar_t *nptr, wchar_t **endptr, int base)
{ {
long result = 0,value; const wchar_t *s = nptr;
int sign = 1; unsigned long acc;
int c;
unsigned long cutoff;
int neg = 0, any, cutlim;
if ( *cp == L'-' ) { /*
sign = -1; * Skip white space and pick up leading +/- sign if any.
cp++; * If base is 0, allow 0x for hex and 0 for octal, else
} * assume decimal; if base is already 16, allow 0x.
*/
do {
c = *s++;
} while (iswctype(c, _SPACE));
if (c == '-')
{
neg = 1;
c = *s++;
}
else if (c == L'+')
c = *s++;
if ((base == 0 || base == 16) &&
c == L'0' && (*s == L'x' || *s == L'X'))
{
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == L'0' ? 8 : 10;
if (!base) { /*
base = 10; * Compute the cutoff value between legal numbers and illegal
if (*cp == L'0') { * numbers. That is the largest legal value, divided by the
base = 8; * base. An input number that is greater than this value, if
cp++; * followed by a legal input character, is too big. One that
if ((*cp == L'x') && iswxdigit(cp[1])) { * is equal to this value may be valid or not; the limit
cp++; * between valid and invalid numbers is then based on the last
base = 16; * digit. For instance, if the range for longs is
} * [-2147483648..2147483647] and the input base is 10,
} * cutoff will be set to 214748364 and cutlim to either
} * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
while (iswxdigit(*cp) && (value = iswdigit(*cp) ? *cp-L'0' : (iswlower(*cp) * a value > 214748364, or equal but the next digit is > 7 (or 8),
? towupper(*cp) : *cp)-L'A'+10) < base) { * the number is too big, and we will return a range error.
result = result*base + value; *
cp++; * Set any if any `digits' consumed; make it negative to indicate
} * overflow.
if (endp) */
*endp = (wchar_t *)cp; cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
return result * sign; cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base;
for (acc = 0, any = 0;; c = *s++)
{
if (iswctype(c, _DIGIT))
c -= L'0';
else if (iswctype(c, _ALPHA))
c -= iswctype(c, _UPPER) ? L'A' - 10 : L'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else
{
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0)
{
acc = neg ? LONG_MIN : LONG_MAX;
}
else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = any ? (wchar_t *)((size_t)(s - 1)) : (wchar_t *)((size_t)nptr);
return acc;
} }

View file

@ -0,0 +1,59 @@
#define WIN32_NO_STATUS
#include <windows.h>
#include <ndk/umtypes.h>
#include <ndk/rtlfuncs.h>
/*
* @implemented
*/
int wctomb (char *mbchar, wchar_t wchar)
{
NTSTATUS Status;
ULONG Size;
if (mbchar == NULL)
return 0;
Status = RtlUnicodeToMultiByteN (mbchar,
1,
&Size,
&wchar,
sizeof(WCHAR));
if (!NT_SUCCESS(Status))
return -1;
return (int)Size;
}
/*
* @implemented
*/
size_t wcstombs (char *mbstr, const wchar_t *wcstr, size_t count)
{
NTSTATUS Status;
ULONG Size;
ULONG Length;
Length = wcslen (wcstr);
if (mbstr == NULL)
{
RtlUnicodeToMultiByteSize (&Size,
(wchar_t*)((size_t)wcstr),
Length * sizeof(WCHAR));
return (size_t)Size;
}
Status = RtlUnicodeToMultiByteN (mbstr,
count,
&Size,
(wchar_t*)((size_t)wcstr),
Length * sizeof(WCHAR));
if (!NT_SUCCESS(Status))
return -1;
return (size_t)Size;
}
/* EOF */

View file

@ -1,6 +1,6 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h> #include <precomp.h>
/* /*
* Convert a unicode string to an unsigned long integer. * Convert a unicode string to an unsigned long integer.
* *
@ -23,7 +23,7 @@ wcstoul(const wchar_t *nptr, wchar_t **endptr, int base)
*/ */
do { do {
c = *s++; c = *s++;
} while (iswspace(c)); } while (iswctype(c, _SPACE));
if (c == L'-') if (c == L'-')
{ {
neg = 1; neg = 1;
@ -44,10 +44,10 @@ wcstoul(const wchar_t *nptr, wchar_t **endptr, int base)
cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) for (acc = 0, any = 0;; c = *s++)
{ {
if (iswdigit(c)) if (iswctype(c, _DIGIT))
c -= L'0'; c -= L'0';
else if (iswalpha(c)) else if (iswctype(c, _ALPHA))
c -= iswupper(c) ? L'A' - 10 : L'a' - 10; c -= iswctype(c, _UPPER) ? L'A' - 10 : L'a' - 10;
else else
break; break;
if (c >= base) if (c >= base)
@ -63,38 +63,10 @@ wcstoul(const wchar_t *nptr, wchar_t **endptr, int base)
if (any < 0) if (any < 0)
{ {
acc = ULONG_MAX; acc = ULONG_MAX;
__set_errno(ERANGE);
} }
else if (neg) else if (neg)
acc = -acc; acc = -acc;
if (endptr != 0) if (endptr != 0)
*endptr = any ? (wchar_t *)s - 1 : (wchar_t *)nptr; *endptr = any ? (wchar_t *)((size_t)s - 1) : (wchar_t *)((size_t)nptr);
return acc; return acc;
} }
#if 0
unsigned long wcstoul(const wchar_t *cp,wchar_t **endp,int base)
{
unsigned long result = 0,value;
if (!base) {
base = 10;
if (*cp == L'0') {
base = 8;
cp++;
if ((*cp == L'x') && iswxdigit(cp[1])) {
cp++;
base = 16;
}
}
}
while (iswxdigit(*cp) && (value = iswdigit(*cp) ? *cp-L'0' : (iswlower(*cp)
? towupper(*cp) : *cp)-L'A'+10) < base) {
result = result*base + value;
cp++;
}
if (endp)
*endp = (wchar_t *)cp;
return result;
}
#endif

View file

@ -13,27 +13,33 @@
/* /*
* @implemented * @implemented
*/ */
__int64 _wtoi64(const wchar_t* nptr) __int64
_wtoi64 (const wchar_t *nptr)
{ {
wchar_t* s = (wchar_t*)nptr; int c;
__int64 acc = 0; __int64 value;
int neg = 0; int sign;
while (iswspace((int)*s)) while (iswctype((int)*nptr, _SPACE))
s++; ++nptr;
if (*s == '-') {
neg = 1;
s++;
}
else if (*s == '+')
s++;
while (iswdigit((int)*s)) { c = (int)*nptr++;
acc = 10 * acc + ((int)*s - '0'); sign = c;
s++; if (c == L'-' || c == L'+')
} c = (int)*nptr++;
if (neg) value = 0;
acc *= -1;
return acc; while (iswctype(c, _DIGIT))
{
value = 10 * value + (c - L'0');
c = (int)*nptr++;
}
if (sign == L'-')
return -value;
else
return value;
} }
/* EOF */

View file

@ -1,6 +1,35 @@
#include <string.h>
#include <ctype.h>
#include <basetsd.h>
#define _UNICODE /* Implementation comes from wine/dlls/ntdll/wcstring.c */
#define UNICODE
/*
* @implemented
*/
long
_wtol(const wchar_t *str)
{
unsigned long RunningTotal = 0;
char bMinus = 0;
while (iswctype(*str, _SPACE) ) {
str++;
} /* while */
if (*str == L'+') {
str++;
} else if (*str == L'-') {
bMinus = 1;
str++;
} /* if */
while (*str >= L'0' && *str <= L'9') {
RunningTotal = RunningTotal * 10 + *str - L'0';
str++;
} /* while */
return bMinus ? -RunningTotal : RunningTotal;
}
#include "atol.c"