mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 17:45:41 +00:00
Share more duplicated functions
svn path=/trunk/; revision=17734
This commit is contained in:
parent
6ce05ab58e
commit
48fe1fb84b
26 changed files with 1099 additions and 1084 deletions
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
/* DEPENDENCIES **************************************************************/
|
/* DEPENDENCIES **************************************************************/
|
||||||
#include <ntnls.h>
|
#include <ntnls.h>
|
||||||
|
#include "extypes.h"
|
||||||
|
#include "rtltypes.h"
|
||||||
|
|
||||||
/* PROTOTYPES ****************************************************************/
|
/* PROTOTYPES ****************************************************************/
|
||||||
|
|
||||||
|
|
|
@ -42,27 +42,6 @@
|
||||||
<file>sscanf.c</file>
|
<file>sscanf.c</file>
|
||||||
<file>swprintf.c</file>
|
<file>swprintf.c</file>
|
||||||
</directory>
|
</directory>
|
||||||
<directory name="stdlib">
|
|
||||||
<file>abs.c</file>
|
|
||||||
<file>atoi64.c</file>
|
|
||||||
<file>atoi.c</file>
|
|
||||||
<file>atol.c</file>
|
|
||||||
<file>bsearch.c</file>
|
|
||||||
<file>itoa.c</file>
|
|
||||||
<file>itow.c</file>
|
|
||||||
<file>labs.c</file>
|
|
||||||
<file>lfind.c</file>
|
|
||||||
<file>mbstowcs.c</file>
|
|
||||||
<file>splitp.c</file>
|
|
||||||
<file>strtol.c</file>
|
|
||||||
<file>strtoul.c</file>
|
|
||||||
<file>wcstol.c</file>
|
|
||||||
<file>wcstombs.c</file>
|
|
||||||
<file>wcstoul.c</file>
|
|
||||||
<file>wtoi64.c</file>
|
|
||||||
<file>wtoi.c</file>
|
|
||||||
<file>wtol.c</file>
|
|
||||||
</directory>
|
|
||||||
<directory name="def">
|
<directory name="def">
|
||||||
<file>ntdll.rc</file>
|
<file>ntdll.rc</file>
|
||||||
</directory>
|
</directory>
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
|
||||||
#include <ntdll.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @implemented
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
abs(int j)
|
|
||||||
{
|
|
||||||
return j<0 ? -j : j;
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
|
||||||
#include <ntdll.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @implemented
|
|
||||||
*/
|
|
||||||
long
|
|
||||||
labs(long j)
|
|
||||||
{
|
|
||||||
return j<0 ? -j : j;
|
|
||||||
}
|
|
10
reactos/lib/string/abs.c
Normal file
10
reactos/lib/string/abs.c
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @implemented
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
abs(int j)
|
||||||
|
{
|
||||||
|
return j<0 ? -j : j;
|
||||||
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
#include <string.h>
|
||||||
#include <ntdll.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
atoi(const char *str)
|
atoi(const char *str)
|
||||||
{
|
{
|
||||||
return (int)strtol(str, 0, 10);
|
return (int)strtol(str, 0, 10);
|
||||||
}
|
}
|
|
@ -1,43 +1,36 @@
|
||||||
/* $Id$
|
#include <string.h>
|
||||||
*
|
#include <ctype.h>
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
|
||||||
* PROJECT: ReactOS kernel
|
/*
|
||||||
* FILE: lib/ntdll/stdlib/atoi64.c
|
* @implemented
|
||||||
* PURPOSE: converts an ascii string to 64 bit integer
|
*/
|
||||||
*/
|
__int64
|
||||||
|
_atoi64 (const char *nptr)
|
||||||
#include <ntdll.h>
|
{
|
||||||
|
int c;
|
||||||
/*
|
__int64 value;
|
||||||
* @implemented
|
int sign;
|
||||||
*/
|
|
||||||
__int64
|
while (isspace((int)*nptr))
|
||||||
_atoi64 (const char *nptr)
|
++nptr;
|
||||||
{
|
|
||||||
int c;
|
c = (int)*nptr++;
|
||||||
__int64 value;
|
sign = c;
|
||||||
int sign;
|
if (c == '-' || c == '+')
|
||||||
|
c = (int)*nptr++;
|
||||||
while (isspace((int)*nptr))
|
|
||||||
++nptr;
|
value = 0;
|
||||||
|
|
||||||
c = (int)*nptr++;
|
while (isdigit(c))
|
||||||
sign = c;
|
{
|
||||||
if (c == '-' || c == '+')
|
value = 10 * value + (c - '0');
|
||||||
c = (int)*nptr++;
|
c = (int)*nptr++;
|
||||||
|
}
|
||||||
value = 0;
|
|
||||||
|
if (sign == '-')
|
||||||
while (isdigit(c))
|
return -value;
|
||||||
{
|
else
|
||||||
value = 10 * value + (c - '0');
|
return value;
|
||||||
c = (int)*nptr++;
|
}
|
||||||
}
|
|
||||||
|
/* EOF */
|
||||||
if (sign == '-')
|
|
||||||
return -value;
|
|
||||||
else
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* EOF */
|
|
|
@ -1,11 +1,11 @@
|
||||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
#include <string.h>
|
||||||
#include <ntdll.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
long
|
long
|
||||||
atol(const char *str)
|
atol(const char *str)
|
||||||
{
|
{
|
||||||
return strtol(str, 0, 10);
|
return strtol(str, 0, 10);
|
||||||
}
|
}
|
|
@ -1,28 +1,27 @@
|
||||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
#include <string.h>
|
||||||
#include <ntdll.h>
|
|
||||||
|
/*
|
||||||
/*
|
* @implemented
|
||||||
* @implemented
|
*/
|
||||||
*/
|
void *
|
||||||
void *
|
bsearch(const void *key, const void *base0, size_t nelem,
|
||||||
bsearch(const void *key, const void *base0, size_t nelem,
|
size_t size, int (*cmp)(const void *ck, const void *ce))
|
||||||
size_t size, int (*cmp)(const void *ck, const void *ce))
|
{
|
||||||
{
|
char *base = (char *)base0;
|
||||||
char *base = (char *)base0;
|
int lim, cmpval;
|
||||||
int lim, cmpval;
|
void *p;
|
||||||
void *p;
|
|
||||||
|
for (lim = nelem; lim != 0; lim >>= 1)
|
||||||
for (lim = nelem; lim != 0; lim >>= 1)
|
{
|
||||||
{
|
p = base + (lim >> 1) * size;
|
||||||
p = base + (lim >> 1) * size;
|
cmpval = (*cmp)(key, p);
|
||||||
cmpval = (*cmp)(key, p);
|
if (cmpval == 0)
|
||||||
if (cmpval == 0)
|
return p;
|
||||||
return p;
|
if (cmpval > 0)
|
||||||
if (cmpval > 0)
|
{ /* key > p: move right */
|
||||||
{ /* key > p: move right */
|
base = (char *)p + size;
|
||||||
base = (char *)p + size;
|
lim--;
|
||||||
lim--;
|
} /* else move left */
|
||||||
} /* else move left */
|
}
|
||||||
}
|
return 0;
|
||||||
return 0;
|
}
|
||||||
}
|
|
|
@ -1,183 +1,167 @@
|
||||||
/*
|
#include <string.h>
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
#include <stdlib.h>
|
||||||
* PROJECT: ReactOS system libraries
|
|
||||||
* FILE: lib/ntdll/stdlib/itoa.c
|
/*
|
||||||
* PURPOSE: converts an integer to ascii
|
* @implemented
|
||||||
* PROGRAMER:
|
*/
|
||||||
* UPDATE HISTORY:
|
char *
|
||||||
* 1995: Created
|
_i64toa(__int64 value, char *string, int radix)
|
||||||
* 1998: Added ltoa Boudewijn Dekker
|
{
|
||||||
* 2003: Corrected ltoa implementation - Steven Edwards
|
char tmp[65];
|
||||||
*/
|
char *tp = tmp;
|
||||||
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
|
__int64 i;
|
||||||
* Copyright 2000 Alexandre Julliard
|
unsigned __int64 v;
|
||||||
* Copyright 2000 Jon Griffiths
|
__int64 sign;
|
||||||
* Copyright 2003 Thomas Mertes
|
char *sp;
|
||||||
*/
|
|
||||||
|
if (radix > 36 || radix <= 1)
|
||||||
#include <ntdll.h>
|
{
|
||||||
|
return 0;
|
||||||
/*
|
}
|
||||||
* @implemented
|
|
||||||
*/
|
sign = (radix == 10 && value < 0);
|
||||||
char *
|
if (sign)
|
||||||
_i64toa(__int64 value, char *string, int radix)
|
v = -value;
|
||||||
{
|
else
|
||||||
char tmp[65];
|
v = (unsigned __int64)value;
|
||||||
char *tp = tmp;
|
while (v || tp == tmp)
|
||||||
__int64 i;
|
{
|
||||||
unsigned __int64 v;
|
i = v % radix;
|
||||||
__int64 sign;
|
v = v / radix;
|
||||||
char *sp;
|
if (i < 10)
|
||||||
|
*tp++ = i+'0';
|
||||||
if (radix > 36 || radix <= 1)
|
else
|
||||||
{
|
*tp++ = i + 'a' - 10;
|
||||||
return 0;
|
}
|
||||||
}
|
|
||||||
|
sp = string;
|
||||||
sign = (radix == 10 && value < 0);
|
if (sign)
|
||||||
if (sign)
|
*sp++ = '-';
|
||||||
v = -value;
|
while (tp > tmp)
|
||||||
else
|
*sp++ = *--tp;
|
||||||
v = (unsigned __int64)value;
|
*sp = 0;
|
||||||
while (v || tp == tmp)
|
return string;
|
||||||
{
|
}
|
||||||
i = v % radix;
|
|
||||||
v = v / radix;
|
|
||||||
if (i < 10)
|
/*
|
||||||
*tp++ = i+'0';
|
* @implemented
|
||||||
else
|
*/
|
||||||
*tp++ = i + 'a' - 10;
|
char *
|
||||||
}
|
_ui64toa(unsigned __int64 value, char *string, int radix)
|
||||||
|
{
|
||||||
sp = string;
|
char tmp[65];
|
||||||
if (sign)
|
char *tp = tmp;
|
||||||
*sp++ = '-';
|
__int64 i;
|
||||||
while (tp > tmp)
|
unsigned __int64 v;
|
||||||
*sp++ = *--tp;
|
char *sp;
|
||||||
*sp = 0;
|
|
||||||
return string;
|
if (radix > 36 || radix <= 1)
|
||||||
}
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
/*
|
|
||||||
* @implemented
|
v = (unsigned __int64)value;
|
||||||
*/
|
while (v || tp == tmp)
|
||||||
char *
|
{
|
||||||
_ui64toa(unsigned __int64 value, char *string, int radix)
|
i = v % radix;
|
||||||
{
|
v = v / radix;
|
||||||
char tmp[65];
|
if (i < 10)
|
||||||
char *tp = tmp;
|
*tp++ = i+'0';
|
||||||
__int64 i;
|
else
|
||||||
unsigned __int64 v;
|
*tp++ = i + 'a' - 10;
|
||||||
char *sp;
|
}
|
||||||
|
|
||||||
if (radix > 36 || radix <= 1)
|
sp = string;
|
||||||
{
|
while (tp > tmp)
|
||||||
return 0;
|
*sp++ = *--tp;
|
||||||
}
|
*sp = 0;
|
||||||
|
return string;
|
||||||
v = (unsigned __int64)value;
|
}
|
||||||
while (v || tp == tmp)
|
|
||||||
{
|
|
||||||
i = v % radix;
|
/*
|
||||||
v = v / radix;
|
* @implemented
|
||||||
if (i < 10)
|
*/
|
||||||
*tp++ = i+'0';
|
char *
|
||||||
else
|
_itoa(int value, char *string, int radix)
|
||||||
*tp++ = i + 'a' - 10;
|
{
|
||||||
}
|
return _ltoa(value, string, radix);
|
||||||
|
}
|
||||||
sp = string;
|
|
||||||
while (tp > tmp)
|
|
||||||
*sp++ = *--tp;
|
/*
|
||||||
*sp = 0;
|
* @implemented
|
||||||
return string;
|
*/
|
||||||
}
|
char *
|
||||||
|
_ltoa(long value, char *string, int radix)
|
||||||
|
{
|
||||||
/*
|
unsigned long val;
|
||||||
* @implemented
|
int negative;
|
||||||
*/
|
char buffer[33];
|
||||||
char *
|
char *pos;
|
||||||
_itoa(int value, char *string, int radix)
|
int digit;
|
||||||
{
|
|
||||||
return _ltoa(value, string, radix);
|
if (value < 0 && radix == 10) {
|
||||||
}
|
negative = 1;
|
||||||
|
val = -value;
|
||||||
|
} else {
|
||||||
/*
|
negative = 0;
|
||||||
* @implemented
|
val = value;
|
||||||
*/
|
} /* if */
|
||||||
char *
|
|
||||||
_ltoa(long value, char *string, int radix)
|
pos = &buffer[32];
|
||||||
{
|
*pos = '\0';
|
||||||
unsigned long val;
|
|
||||||
int negative;
|
do {
|
||||||
char buffer[33];
|
digit = val % radix;
|
||||||
char *pos;
|
val = val / radix;
|
||||||
int digit;
|
if (digit < 10) {
|
||||||
|
*--pos = '0' + digit;
|
||||||
if (value < 0 && radix == 10) {
|
} else {
|
||||||
negative = 1;
|
*--pos = 'a' + digit - 10;
|
||||||
val = -value;
|
} /* if */
|
||||||
} else {
|
} while (val != 0L);
|
||||||
negative = 0;
|
|
||||||
val = value;
|
if (negative) {
|
||||||
} /* if */
|
*--pos = '-';
|
||||||
|
} /* if */
|
||||||
pos = &buffer[32];
|
|
||||||
*pos = '\0';
|
memcpy(string, pos, &buffer[32] - pos + 1);
|
||||||
|
return string;
|
||||||
do {
|
}
|
||||||
digit = val % radix;
|
|
||||||
val = val / radix;
|
|
||||||
if (digit < 10) {
|
/*
|
||||||
*--pos = '0' + digit;
|
* @implemented
|
||||||
} else {
|
*/
|
||||||
*--pos = 'a' + digit - 10;
|
char *
|
||||||
} /* if */
|
_ultoa(unsigned long value, char *string, int radix)
|
||||||
} while (val != 0L);
|
{
|
||||||
|
char tmp[33];
|
||||||
if (negative) {
|
char *tp = tmp;
|
||||||
*--pos = '-';
|
long i;
|
||||||
} /* if */
|
unsigned long v = value;
|
||||||
|
char *sp;
|
||||||
memcpy(string, pos, &buffer[32] - pos + 1);
|
|
||||||
return string;
|
if (radix > 36 || radix <= 1)
|
||||||
}
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
/*
|
|
||||||
* @implemented
|
while (v || tp == tmp)
|
||||||
*/
|
{
|
||||||
char *
|
i = v % radix;
|
||||||
_ultoa(unsigned long value, char *string, int radix)
|
v = v / radix;
|
||||||
{
|
if (i < 10)
|
||||||
char tmp[33];
|
*tp++ = i+'0';
|
||||||
char *tp = tmp;
|
else
|
||||||
long i;
|
*tp++ = i + 'a' - 10;
|
||||||
unsigned long v = value;
|
}
|
||||||
char *sp;
|
|
||||||
|
sp = string;
|
||||||
if (radix > 36 || radix <= 1)
|
while (tp > tmp)
|
||||||
{
|
*sp++ = *--tp;
|
||||||
return 0;
|
*sp = 0;
|
||||||
}
|
return string;
|
||||||
|
}
|
||||||
while (v || tp == tmp)
|
|
||||||
{
|
|
||||||
i = v % radix;
|
|
||||||
v = v / radix;
|
|
||||||
if (i < 10)
|
|
||||||
*tp++ = i+'0';
|
|
||||||
else
|
|
||||||
*tp++ = i + 'a' - 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
sp = string;
|
|
||||||
while (tp > tmp)
|
|
||||||
*sp++ = *--tp;
|
|
||||||
*sp = 0;
|
|
||||||
return string;
|
|
||||||
}
|
|
|
@ -1,211 +1,200 @@
|
||||||
/*
|
#include <string.h>
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
|
||||||
* PROJECT: ReactOS system libraries
|
/*
|
||||||
* FILE: lib/ntdll/stdlib/itow.c
|
* @implemented
|
||||||
* PURPOSE: converts an integer to Unicode
|
*/
|
||||||
* PROGRAMER:
|
wchar_t *
|
||||||
* UPDATE HISTORY:
|
_i64tow(__int64 value, wchar_t *string, int radix)
|
||||||
* 1995: Created
|
{
|
||||||
* 1998: Added ltoa Boudewijn Dekker
|
wchar_t tmp[65];
|
||||||
*/
|
wchar_t *tp = tmp;
|
||||||
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
|
__int64 i;
|
||||||
#include <ntdll.h>
|
unsigned __int64 v;
|
||||||
|
__int64 sign;
|
||||||
/*
|
wchar_t *sp;
|
||||||
* @implemented
|
|
||||||
*/
|
if (radix > 36 || radix <= 1)
|
||||||
wchar_t *
|
{
|
||||||
_i64tow(__int64 value, wchar_t *string, int radix)
|
return 0;
|
||||||
{
|
}
|
||||||
wchar_t tmp[65];
|
|
||||||
wchar_t *tp = tmp;
|
sign = (radix == 10 && value < 0);
|
||||||
__int64 i;
|
if (sign)
|
||||||
unsigned __int64 v;
|
v = -value;
|
||||||
__int64 sign;
|
else
|
||||||
wchar_t *sp;
|
v = (unsigned __int64)value;
|
||||||
|
while (v || tp == tmp)
|
||||||
if (radix > 36 || radix <= 1)
|
{
|
||||||
{
|
i = v % radix;
|
||||||
return 0;
|
v = v / radix;
|
||||||
}
|
if (i < 10)
|
||||||
|
*tp++ = i+L'0';
|
||||||
sign = (radix == 10 && value < 0);
|
else
|
||||||
if (sign)
|
*tp++ = i + L'a' - 10;
|
||||||
v = -value;
|
}
|
||||||
else
|
|
||||||
v = (unsigned __int64)value;
|
sp = string;
|
||||||
while (v || tp == tmp)
|
if (sign)
|
||||||
{
|
*sp++ = L'-';
|
||||||
i = v % radix;
|
while (tp > tmp)
|
||||||
v = v / radix;
|
*sp++ = *--tp;
|
||||||
if (i < 10)
|
*sp = 0;
|
||||||
*tp++ = i+L'0';
|
return string;
|
||||||
else
|
}
|
||||||
*tp++ = i + L'a' - 10;
|
|
||||||
}
|
|
||||||
|
/*
|
||||||
sp = string;
|
* @implemented
|
||||||
if (sign)
|
*/
|
||||||
*sp++ = L'-';
|
wchar_t *
|
||||||
while (tp > tmp)
|
_ui64tow(unsigned __int64 value, wchar_t *string, int radix)
|
||||||
*sp++ = *--tp;
|
{
|
||||||
*sp = 0;
|
wchar_t tmp[65];
|
||||||
return string;
|
wchar_t *tp = tmp;
|
||||||
}
|
__int64 i;
|
||||||
|
unsigned __int64 v;
|
||||||
|
wchar_t *sp;
|
||||||
/*
|
|
||||||
* @implemented
|
if (radix > 36 || radix <= 1)
|
||||||
*/
|
{
|
||||||
wchar_t *
|
return 0;
|
||||||
_ui64tow(unsigned __int64 value, wchar_t *string, int radix)
|
}
|
||||||
{
|
|
||||||
wchar_t tmp[65];
|
v = (unsigned __int64)value;
|
||||||
wchar_t *tp = tmp;
|
while (v || tp == tmp)
|
||||||
__int64 i;
|
{
|
||||||
unsigned __int64 v;
|
i = v % radix;
|
||||||
wchar_t *sp;
|
v = v / radix;
|
||||||
|
if (i < 10)
|
||||||
if (radix > 36 || radix <= 1)
|
*tp++ = i+L'0';
|
||||||
{
|
else
|
||||||
return 0;
|
*tp++ = i + L'a' - 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
v = (unsigned __int64)value;
|
sp = string;
|
||||||
while (v || tp == tmp)
|
while (tp > tmp)
|
||||||
{
|
*sp++ = *--tp;
|
||||||
i = v % radix;
|
*sp = 0;
|
||||||
v = v / radix;
|
return string;
|
||||||
if (i < 10)
|
}
|
||||||
*tp++ = i+L'0';
|
|
||||||
else
|
|
||||||
*tp++ = i + L'a' - 10;
|
/*
|
||||||
}
|
* @implemented
|
||||||
|
*/
|
||||||
sp = string;
|
wchar_t *
|
||||||
while (tp > tmp)
|
_itow(int value, wchar_t *string, int radix)
|
||||||
*sp++ = *--tp;
|
{
|
||||||
*sp = 0;
|
wchar_t tmp[33];
|
||||||
return string;
|
wchar_t *tp = tmp;
|
||||||
}
|
int i;
|
||||||
|
unsigned v;
|
||||||
|
int sign;
|
||||||
/*
|
wchar_t *sp;
|
||||||
* @implemented
|
|
||||||
*/
|
if (radix > 36 || radix <= 1)
|
||||||
wchar_t *
|
{
|
||||||
_itow(int value, wchar_t *string, int radix)
|
return 0;
|
||||||
{
|
}
|
||||||
wchar_t tmp[33];
|
|
||||||
wchar_t *tp = tmp;
|
sign = (radix == 10 && value < 0);
|
||||||
int i;
|
if (sign)
|
||||||
unsigned v;
|
v = -value;
|
||||||
int sign;
|
else
|
||||||
wchar_t *sp;
|
v = (unsigned)value;
|
||||||
|
while (v || tp == tmp)
|
||||||
if (radix > 36 || radix <= 1)
|
{
|
||||||
{
|
i = v % radix;
|
||||||
return 0;
|
v = v / radix;
|
||||||
}
|
if (i < 10)
|
||||||
|
*tp++ = i+L'0';
|
||||||
sign = (radix == 10 && value < 0);
|
else
|
||||||
if (sign)
|
*tp++ = i + L'a' - 10;
|
||||||
v = -value;
|
}
|
||||||
else
|
|
||||||
v = (unsigned)value;
|
sp = string;
|
||||||
while (v || tp == tmp)
|
if (sign)
|
||||||
{
|
*sp++ = L'-';
|
||||||
i = v % radix;
|
while (tp > tmp)
|
||||||
v = v / radix;
|
*sp++ = *--tp;
|
||||||
if (i < 10)
|
*sp = 0;
|
||||||
*tp++ = i+L'0';
|
return string;
|
||||||
else
|
}
|
||||||
*tp++ = i + L'a' - 10;
|
|
||||||
}
|
|
||||||
|
/*
|
||||||
sp = string;
|
* @implemented
|
||||||
if (sign)
|
*/
|
||||||
*sp++ = L'-';
|
wchar_t *
|
||||||
while (tp > tmp)
|
_ltow(long value, wchar_t *string, int radix)
|
||||||
*sp++ = *--tp;
|
{
|
||||||
*sp = 0;
|
wchar_t tmp[33];
|
||||||
return string;
|
wchar_t *tp = tmp;
|
||||||
}
|
long i;
|
||||||
|
unsigned long v;
|
||||||
|
int sign;
|
||||||
/*
|
wchar_t *sp;
|
||||||
* @implemented
|
|
||||||
*/
|
if (radix > 36 || radix <= 1)
|
||||||
wchar_t *
|
{
|
||||||
_ltow(long value, wchar_t *string, int radix)
|
return 0;
|
||||||
{
|
}
|
||||||
wchar_t tmp[33];
|
|
||||||
wchar_t *tp = tmp;
|
sign = (radix == 10 && value < 0);
|
||||||
long i;
|
if (sign)
|
||||||
unsigned long v;
|
v = -value;
|
||||||
int sign;
|
else
|
||||||
wchar_t *sp;
|
v = (unsigned long)value;
|
||||||
|
while (v || tp == tmp)
|
||||||
if (radix > 36 || radix <= 1)
|
{
|
||||||
{
|
i = v % radix;
|
||||||
return 0;
|
v = v / radix;
|
||||||
}
|
if (i < 10)
|
||||||
|
*tp++ = i+L'0';
|
||||||
sign = (radix == 10 && value < 0);
|
else
|
||||||
if (sign)
|
*tp++ = i + L'a' - 10;
|
||||||
v = -value;
|
}
|
||||||
else
|
|
||||||
v = (unsigned long)value;
|
sp = string;
|
||||||
while (v || tp == tmp)
|
if (sign)
|
||||||
{
|
*sp++ = L'-';
|
||||||
i = v % radix;
|
while (tp > tmp)
|
||||||
v = v / radix;
|
*sp++ = *--tp;
|
||||||
if (i < 10)
|
*sp = 0;
|
||||||
*tp++ = i+L'0';
|
return string;
|
||||||
else
|
}
|
||||||
*tp++ = i + L'a' - 10;
|
|
||||||
}
|
|
||||||
|
/*
|
||||||
sp = string;
|
* @implemented
|
||||||
if (sign)
|
*/
|
||||||
*sp++ = L'-';
|
wchar_t *
|
||||||
while (tp > tmp)
|
_ultow(unsigned long value, wchar_t *string, int radix)
|
||||||
*sp++ = *--tp;
|
{
|
||||||
*sp = 0;
|
wchar_t tmp[33];
|
||||||
return string;
|
wchar_t *tp = tmp;
|
||||||
}
|
long i;
|
||||||
|
unsigned long v = value;
|
||||||
|
wchar_t *sp;
|
||||||
/*
|
|
||||||
* @implemented
|
if (radix > 36 || radix <= 1)
|
||||||
*/
|
{
|
||||||
wchar_t *
|
return 0;
|
||||||
_ultow(unsigned long value, wchar_t *string, int radix)
|
}
|
||||||
{
|
|
||||||
wchar_t tmp[33];
|
while (v || tp == tmp)
|
||||||
wchar_t *tp = tmp;
|
{
|
||||||
long i;
|
i = v % radix;
|
||||||
unsigned long v = value;
|
v = v / radix;
|
||||||
wchar_t *sp;
|
if (i < 10)
|
||||||
|
*tp++ = i+L'0';
|
||||||
if (radix > 36 || radix <= 1)
|
else
|
||||||
{
|
*tp++ = i + L'a' - 10;
|
||||||
return 0;
|
}
|
||||||
}
|
|
||||||
|
sp = string;
|
||||||
while (v || tp == tmp)
|
while (tp > tmp)
|
||||||
{
|
*sp++ = *--tp;
|
||||||
i = v % radix;
|
*sp = 0;
|
||||||
v = v / radix;
|
return string;
|
||||||
if (i < 10)
|
}
|
||||||
*tp++ = i+L'0';
|
|
||||||
else
|
|
||||||
*tp++ = i + L'a' - 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
sp = string;
|
|
||||||
while (tp > tmp)
|
|
||||||
*sp++ = *--tp;
|
|
||||||
*sp = 0;
|
|
||||||
return string;
|
|
||||||
}
|
|
9
reactos/lib/string/labs.c
Normal file
9
reactos/lib/string/labs.c
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#include <string.h>
|
||||||
|
/*
|
||||||
|
* @implemented
|
||||||
|
*/
|
||||||
|
long
|
||||||
|
labs(long j)
|
||||||
|
{
|
||||||
|
return j<0 ? -j : j;
|
||||||
|
}
|
|
@ -1,22 +1,20 @@
|
||||||
#include <ntdll.h>
|
#include <string.h>
|
||||||
|
/*
|
||||||
|
* @implemented
|
||||||
/*
|
*/
|
||||||
* @implemented
|
void *_lfind(const void *key, const void *base, size_t *nelp,
|
||||||
*/
|
size_t width, int (*compar)(const void *, const void *))
|
||||||
void *_lfind(const void *key, const void *base, size_t *nelp,
|
{
|
||||||
size_t width, int (*compar)(const void *, const void *))
|
char* char_base = (char*)base;
|
||||||
{
|
size_t i;
|
||||||
char* char_base = (char*)base;
|
|
||||||
size_t i;
|
for (i = 0; i < *nelp; i++)
|
||||||
|
{
|
||||||
for (i = 0; i < *nelp; i++)
|
if (compar(key, char_base) == 0)
|
||||||
{
|
return char_base;
|
||||||
if (compar(key, char_base) == 0)
|
|
||||||
return char_base;
|
char_base += width;
|
||||||
|
}
|
||||||
char_base += width;
|
|
||||||
}
|
return NULL;
|
||||||
|
}
|
||||||
return NULL;
|
|
||||||
}
|
|
|
@ -1,45 +1,61 @@
|
||||||
/* $Id$
|
#include <windows.h>
|
||||||
*
|
#define NTOS_MODE_USER
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
#define _NTSYSTEM_
|
||||||
* PROJECT: ReactOS kernel
|
#include <ndk/umtypes.h>
|
||||||
* FILE: lib/ntdll/stdlib/mbstowcs.c
|
#include <ndk/rtlfuncs.h>
|
||||||
* PURPOSE: converts a multi byte string to a unicode string
|
#include <string.h>
|
||||||
*/
|
|
||||||
|
/*
|
||||||
#include <ntdll.h>
|
* @implemented
|
||||||
#define NDEBUG
|
*/
|
||||||
#include <debug.h>
|
int mbtowc (wchar_t *wchar, const char *mbchar, size_t count)
|
||||||
#include <stdlib.h>
|
{
|
||||||
#include <string.h>
|
NTSTATUS Status;
|
||||||
/*
|
ULONG Size;
|
||||||
* @implemented
|
|
||||||
*/
|
if (wchar == NULL)
|
||||||
size_t mbstowcs (wchar_t *wcstr, const char *mbstr, size_t count)
|
return 0;
|
||||||
{
|
|
||||||
NTSTATUS Status;
|
Status = RtlMultiByteToUnicodeN (wchar,
|
||||||
ULONG Size;
|
sizeof(WCHAR),
|
||||||
ULONG Length;
|
&Size,
|
||||||
|
(char *)mbchar,
|
||||||
Length = strlen (mbstr);
|
count);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
if (wcstr == NULL)
|
return -1;
|
||||||
{
|
|
||||||
RtlMultiByteToUnicodeSize (&Size,
|
return (int)Size;
|
||||||
(char *)mbstr,
|
}
|
||||||
Length);
|
|
||||||
|
/*
|
||||||
return (size_t)Size;
|
* @implemented
|
||||||
}
|
*/
|
||||||
|
size_t mbstowcs (wchar_t *wcstr, const char *mbstr, size_t count)
|
||||||
Status = RtlMultiByteToUnicodeN (wcstr,
|
{
|
||||||
count,
|
NTSTATUS Status;
|
||||||
&Size,
|
ULONG Size;
|
||||||
(char *)mbstr,
|
ULONG Length;
|
||||||
Length);
|
|
||||||
if (!NT_SUCCESS(Status))
|
Length = strlen (mbstr);
|
||||||
return -1;
|
|
||||||
|
if (wcstr == NULL)
|
||||||
return (size_t)Size;
|
{
|
||||||
}
|
RtlMultiByteToUnicodeSize (&Size,
|
||||||
|
(char *)mbstr,
|
||||||
/* EOF */
|
Length);
|
||||||
|
|
||||||
|
return (size_t)Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = RtlMultiByteToUnicodeN (wcstr,
|
||||||
|
count,
|
||||||
|
&Size,
|
||||||
|
(char *)mbstr,
|
||||||
|
Length);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return (size_t)Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* EOF */
|
29
reactos/lib/string/rand.c
Normal file
29
reactos/lib/string/rand.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
static unsigned long long next = 0;
|
||||||
|
#else
|
||||||
|
static unsigned __int64 next = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @implemented
|
||||||
|
*/
|
||||||
|
int rand(void)
|
||||||
|
{
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
next = next * 0x5deece66dLL + 11;
|
||||||
|
#else
|
||||||
|
next = next * 0x5deece66di64 + 11;
|
||||||
|
#endif
|
||||||
|
return (int)((next >> 16) & RAND_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @implemented
|
||||||
|
*/
|
||||||
|
void srand(unsigned seed)
|
||||||
|
{
|
||||||
|
next = seed;
|
||||||
|
}
|
|
@ -1,51 +1,50 @@
|
||||||
#include <ntdll.h>
|
#include <string.h>
|
||||||
|
/*
|
||||||
/*
|
* @implemented
|
||||||
* @implemented
|
*/
|
||||||
*/
|
void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext)
|
||||||
void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext)
|
{
|
||||||
{
|
char* tmp_drive;
|
||||||
char* tmp_drive;
|
char* tmp_dir;
|
||||||
char* tmp_dir;
|
char* tmp_ext;
|
||||||
char* tmp_ext;
|
|
||||||
|
tmp_drive = (char*)strchr(path,':');
|
||||||
tmp_drive = (char*)strchr(path,':');
|
if (drive) {
|
||||||
if (drive) {
|
if (tmp_drive) {
|
||||||
if (tmp_drive) {
|
strncpy(drive,tmp_drive-1,2);
|
||||||
strncpy(drive,tmp_drive-1,2);
|
*(drive+2) = 0;
|
||||||
*(drive+2) = 0;
|
} else {
|
||||||
} else {
|
*drive = 0;
|
||||||
*drive = 0;
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!tmp_drive) {
|
||||||
if (!tmp_drive) {
|
tmp_drive = (char*)path - 1;
|
||||||
tmp_drive = (char*)path - 1;
|
}
|
||||||
}
|
|
||||||
|
tmp_dir = (char*)strrchr(path,'\\');
|
||||||
tmp_dir = (char*)strrchr(path,'\\');
|
if (dir) {
|
||||||
if (dir) {
|
if (tmp_dir) {
|
||||||
if (tmp_dir) {
|
strncpy(dir,tmp_drive+1,tmp_dir-tmp_drive);
|
||||||
strncpy(dir,tmp_drive+1,tmp_dir-tmp_drive);
|
*(dir+(tmp_dir-tmp_drive)) = 0;
|
||||||
*(dir+(tmp_dir-tmp_drive)) = 0;
|
} else {
|
||||||
} else {
|
*dir =0;
|
||||||
*dir =0;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
tmp_ext = (char*)strrchr(path,'.');
|
||||||
tmp_ext = (char*)strrchr(path,'.');
|
if (!tmp_ext) {
|
||||||
if (!tmp_ext) {
|
tmp_ext = (char*)path+strlen(path);
|
||||||
tmp_ext = (char*)path+strlen(path);
|
}
|
||||||
}
|
if (ext) {
|
||||||
if (ext) {
|
strcpy(ext,tmp_ext);
|
||||||
strcpy(ext,tmp_ext);
|
}
|
||||||
}
|
|
||||||
|
if (tmp_dir) {
|
||||||
if (tmp_dir) {
|
strncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1);
|
||||||
strncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1);
|
*(fname+(tmp_ext-tmp_dir-1)) = 0;
|
||||||
*(fname+(tmp_ext-tmp_dir-1)) = 0;
|
} else {
|
||||||
} else {
|
strncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1);
|
||||||
strncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1);
|
*(fname+(tmp_ext-path))=0;
|
||||||
*(fname+(tmp_ext-path))=0;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -76,4 +76,24 @@
|
||||||
<file>wstring.c</file>
|
<file>wstring.c</file>
|
||||||
<file>wcsrev.c</file>
|
<file>wcsrev.c</file>
|
||||||
<file>wcsnset.c</file>
|
<file>wcsnset.c</file>
|
||||||
|
<file>abs.c</file>
|
||||||
|
<file>atoi64.c</file>
|
||||||
|
<file>atoi.c</file>
|
||||||
|
<file>atol.c</file>
|
||||||
|
<file>bsearch.c</file>
|
||||||
|
<file>itoa.c</file>
|
||||||
|
<file>itow.c</file>
|
||||||
|
<file>labs.c</file>
|
||||||
|
<file>lfind.c</file>
|
||||||
|
<file>mbstowcs.c</file>
|
||||||
|
<file>splitp.c</file>
|
||||||
|
<file>strtol.c</file>
|
||||||
|
<file>strtoul.c</file>
|
||||||
|
<file>wcstol.c</file>
|
||||||
|
<file>wcstombs.c</file>
|
||||||
|
<file>wcstoul.c</file>
|
||||||
|
<file>wtoi64.c</file>
|
||||||
|
<file>wtoi.c</file>
|
||||||
|
<file>wtol.c</file>
|
||||||
|
<file>rand.c</file>
|
||||||
</module>
|
</module>
|
||||||
|
|
|
@ -1,89 +1,90 @@
|
||||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
#include <string.h>
|
||||||
#include <ntdll.h>
|
#include <limits.h>
|
||||||
|
#include <ctype.h>
|
||||||
/*
|
|
||||||
* @implemented
|
/*
|
||||||
*/
|
* @implemented
|
||||||
long
|
*/
|
||||||
strtol(const char *nptr, char **endptr, int base)
|
long
|
||||||
{
|
strtol(const char *nptr, char **endptr, int base)
|
||||||
const char *s = nptr;
|
{
|
||||||
unsigned long acc;
|
const char *s = nptr;
|
||||||
int c;
|
unsigned long acc;
|
||||||
unsigned long cutoff;
|
int c;
|
||||||
int neg = 0, any, cutlim;
|
unsigned long cutoff;
|
||||||
|
int neg = 0, any, cutlim;
|
||||||
/*
|
|
||||||
* Skip white space and pick up leading +/- sign if any.
|
/*
|
||||||
* If base is 0, allow 0x for hex and 0 for octal, else
|
* Skip white space and pick up leading +/- sign if any.
|
||||||
* assume decimal; if base is already 16, allow 0x.
|
* 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++;
|
do {
|
||||||
} while (isspace(c));
|
c = *s++;
|
||||||
if (c == '-')
|
} while (isspace(c));
|
||||||
{
|
if (c == '-')
|
||||||
neg = 1;
|
{
|
||||||
c = *s++;
|
neg = 1;
|
||||||
}
|
c = *s++;
|
||||||
else if (c == '+')
|
}
|
||||||
c = *s++;
|
else if (c == '+')
|
||||||
if ((base == 0 || base == 16) &&
|
c = *s++;
|
||||||
c == '0' && (*s == 'x' || *s == 'X'))
|
if ((base == 0 || base == 16) &&
|
||||||
{
|
c == '0' && (*s == 'x' || *s == 'X'))
|
||||||
c = s[1];
|
{
|
||||||
s += 2;
|
c = s[1];
|
||||||
base = 16;
|
s += 2;
|
||||||
}
|
base = 16;
|
||||||
if (base == 0)
|
}
|
||||||
base = c == '0' ? 8 : 10;
|
if (base == 0)
|
||||||
|
base = c == '0' ? 8 : 10;
|
||||||
/*
|
|
||||||
* Compute the cutoff value between legal numbers and illegal
|
/*
|
||||||
* numbers. That is the largest legal value, divided by the
|
* Compute the cutoff value between legal numbers and illegal
|
||||||
* base. An input number that is greater than this value, if
|
* numbers. That is the largest legal value, divided by the
|
||||||
* followed by a legal input character, is too big. One that
|
* base. An input number that is greater than this value, if
|
||||||
* is equal to this value may be valid or not; the limit
|
* followed by a legal input character, is too big. One that
|
||||||
* between valid and invalid numbers is then based on the last
|
* is equal to this value may be valid or not; the limit
|
||||||
* digit. For instance, if the range for longs is
|
* between valid and invalid numbers is then based on the last
|
||||||
* [-2147483648..2147483647] and the input base is 10,
|
* digit. For instance, if the range for longs is
|
||||||
* cutoff will be set to 214748364 and cutlim to either
|
* [-2147483648..2147483647] and the input base is 10,
|
||||||
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
|
* cutoff will be set to 214748364 and cutlim to either
|
||||||
* a value > 214748364, or equal but the next digit is > 7 (or 8),
|
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
|
||||||
* the number is too big, and we will return a range error.
|
* a value > 214748364, or equal but the next digit is > 7 (or 8),
|
||||||
*
|
* the number is too big, and we will return a range error.
|
||||||
* Set any if any `digits' consumed; make it negative to indicate
|
*
|
||||||
* overflow.
|
* Set any if any `digits' consumed; make it negative to indicate
|
||||||
*/
|
* overflow.
|
||||||
cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
|
*/
|
||||||
cutlim = cutoff % (unsigned long)base;
|
cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
|
||||||
cutoff /= (unsigned long)base;
|
cutlim = cutoff % (unsigned long)base;
|
||||||
for (acc = 0, any = 0;; c = *s++)
|
cutoff /= (unsigned long)base;
|
||||||
{
|
for (acc = 0, any = 0;; c = *s++)
|
||||||
if (isdigit(c))
|
{
|
||||||
c -= '0';
|
if (isdigit(c))
|
||||||
else if (isalpha(c))
|
c -= '0';
|
||||||
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
else if (isalpha(c))
|
||||||
else
|
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
||||||
break;
|
else
|
||||||
if (c >= base)
|
break;
|
||||||
break;
|
if (c >= base)
|
||||||
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
|
break;
|
||||||
any = -1;
|
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
|
||||||
else
|
any = -1;
|
||||||
{
|
else
|
||||||
any = 1;
|
{
|
||||||
acc *= base;
|
any = 1;
|
||||||
acc += c;
|
acc *= base;
|
||||||
}
|
acc += c;
|
||||||
}
|
}
|
||||||
if (any < 0)
|
}
|
||||||
{
|
if (any < 0)
|
||||||
acc = neg ? LONG_MIN : LONG_MAX;
|
{
|
||||||
}
|
acc = neg ? LONG_MIN : LONG_MAX;
|
||||||
else if (neg)
|
}
|
||||||
acc = -acc;
|
else if (neg)
|
||||||
if (endptr != 0)
|
acc = -acc;
|
||||||
*endptr = any ? (char *)s - 1 : (char *)nptr;
|
if (endptr != 0)
|
||||||
return acc;
|
*endptr = any ? (char *)s - 1 : (char *)nptr;
|
||||||
}
|
return acc;
|
||||||
|
}
|
|
@ -1,73 +1,73 @@
|
||||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
#include <string.h>
|
||||||
#include <ntdll.h>
|
#include <limits.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert a string to an unsigned long integer.
|
* Convert a string to an unsigned long integer.
|
||||||
*
|
*
|
||||||
* Ignores `locale' stuff. Assumes that the upper and lower case
|
* Ignores `locale' stuff. Assumes that the upper and lower case
|
||||||
* alphabets and digits are each contiguous.
|
* alphabets and digits are each contiguous.
|
||||||
*
|
*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
unsigned long
|
unsigned long
|
||||||
strtoul(const char *nptr, char **endptr, int base)
|
strtoul(const char *nptr, char **endptr, int base)
|
||||||
{
|
{
|
||||||
const char *s = nptr;
|
const char *s = nptr;
|
||||||
unsigned long acc;
|
unsigned long acc;
|
||||||
int c;
|
int c;
|
||||||
unsigned long cutoff;
|
unsigned long cutoff;
|
||||||
int neg = 0, any, cutlim;
|
int neg = 0, any, cutlim;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* See strtol for comments as to the logic used.
|
* See strtol for comments as to the logic used.
|
||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
c = *s++;
|
c = *s++;
|
||||||
} while (isspace(c));
|
} while (isspace(c));
|
||||||
if (c == '-')
|
if (c == '-')
|
||||||
{
|
{
|
||||||
neg = 1;
|
neg = 1;
|
||||||
c = *s++;
|
c = *s++;
|
||||||
}
|
}
|
||||||
else if (c == '+')
|
else if (c == '+')
|
||||||
c = *s++;
|
c = *s++;
|
||||||
if ((base == 0 || base == 16) &&
|
if ((base == 0 || base == 16) &&
|
||||||
c == '0' && (*s == 'x' || *s == 'X'))
|
c == '0' && (*s == 'x' || *s == 'X'))
|
||||||
{
|
{
|
||||||
c = s[1];
|
c = s[1];
|
||||||
s += 2;
|
s += 2;
|
||||||
base = 16;
|
base = 16;
|
||||||
}
|
}
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
base = c == '0' ? 8 : 10;
|
base = c == '0' ? 8 : 10;
|
||||||
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
|
cutoff = (unsigned long)ULONG_MAX / (unsigned long)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 (isdigit(c))
|
if (isdigit(c))
|
||||||
c -= '0';
|
c -= '0';
|
||||||
else if (isalpha(c))
|
else if (isalpha(c))
|
||||||
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
if (c >= base)
|
if (c >= base)
|
||||||
break;
|
break;
|
||||||
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
|
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
|
||||||
any = -1;
|
any = -1;
|
||||||
else {
|
else {
|
||||||
any = 1;
|
any = 1;
|
||||||
acc *= base;
|
acc *= base;
|
||||||
acc += c;
|
acc += c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (any < 0)
|
if (any < 0)
|
||||||
{
|
{
|
||||||
acc = ULONG_MAX;
|
acc = ULONG_MAX;
|
||||||
}
|
}
|
||||||
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 *)s - 1 : (char *)nptr;
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
|
@ -1,90 +1,90 @@
|
||||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
#include <string.h>
|
||||||
#include <ntdll.h>
|
#include <ctype.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
long
|
long
|
||||||
wcstol(const wchar_t *nptr, wchar_t **endptr, int base)
|
wcstol(const wchar_t *nptr, wchar_t **endptr, int base)
|
||||||
{
|
{
|
||||||
const wchar_t *s = nptr;
|
const wchar_t *s = nptr;
|
||||||
unsigned long acc;
|
unsigned long acc;
|
||||||
int c;
|
int c;
|
||||||
unsigned long cutoff;
|
unsigned long cutoff;
|
||||||
int neg = 0, any, cutlim;
|
int neg = 0, any, cutlim;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Skip white space and pick up leading +/- sign if any.
|
* Skip white space and pick up leading +/- sign if any.
|
||||||
* If base is 0, allow 0x for hex and 0 for octal, else
|
* If base is 0, allow 0x for hex and 0 for octal, else
|
||||||
* assume decimal; if base is already 16, allow 0x.
|
* assume decimal; if base is already 16, allow 0x.
|
||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
c = *s++;
|
c = *s++;
|
||||||
} while (iswctype(c, _SPACE));
|
} while (iswctype(c, _SPACE));
|
||||||
if (c == '-')
|
if (c == '-')
|
||||||
{
|
{
|
||||||
neg = 1;
|
neg = 1;
|
||||||
c = *s++;
|
c = *s++;
|
||||||
}
|
}
|
||||||
else if (c == L'+')
|
else if (c == L'+')
|
||||||
c = *s++;
|
c = *s++;
|
||||||
if ((base == 0 || base == 16) &&
|
if ((base == 0 || base == 16) &&
|
||||||
c == L'0' && (*s == L'x' || *s == L'X'))
|
c == L'0' && (*s == L'x' || *s == L'X'))
|
||||||
{
|
{
|
||||||
c = s[1];
|
c = s[1];
|
||||||
s += 2;
|
s += 2;
|
||||||
base = 16;
|
base = 16;
|
||||||
}
|
}
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
base = c == L'0' ? 8 : 10;
|
base = c == L'0' ? 8 : 10;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compute the cutoff value between legal numbers and illegal
|
* Compute the cutoff value between legal numbers and illegal
|
||||||
* numbers. That is the largest legal value, divided by the
|
* numbers. That is the largest legal value, divided by the
|
||||||
* base. An input number that is greater than this value, if
|
* base. An input number that is greater than this value, if
|
||||||
* followed by a legal input character, is too big. One that
|
* followed by a legal input character, is too big. One that
|
||||||
* is equal to this value may be valid or not; the limit
|
* is equal to this value may be valid or not; the limit
|
||||||
* between valid and invalid numbers is then based on the last
|
* between valid and invalid numbers is then based on the last
|
||||||
* digit. For instance, if the range for longs is
|
* digit. For instance, if the range for longs is
|
||||||
* [-2147483648..2147483647] and the input base is 10,
|
* [-2147483648..2147483647] and the input base is 10,
|
||||||
* cutoff will be set to 214748364 and cutlim to either
|
* cutoff will be set to 214748364 and cutlim to either
|
||||||
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
|
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
|
||||||
* a value > 214748364, or equal but the next digit is > 7 (or 8),
|
* a value > 214748364, or equal but the next digit is > 7 (or 8),
|
||||||
* the number is too big, and we will return a range error.
|
* the number is too big, and we will return a range error.
|
||||||
*
|
*
|
||||||
* Set any if any `digits' consumed; make it negative to indicate
|
* Set any if any `digits' consumed; make it negative to indicate
|
||||||
* overflow.
|
* overflow.
|
||||||
*/
|
*/
|
||||||
cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
|
cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
|
||||||
cutlim = cutoff % (unsigned long)base;
|
cutlim = cutoff % (unsigned long)base;
|
||||||
cutoff /= (unsigned long)base;
|
cutoff /= (unsigned long)base;
|
||||||
for (acc = 0, any = 0;; c = *s++)
|
for (acc = 0, any = 0;; c = *s++)
|
||||||
{
|
{
|
||||||
if (iswctype(c, _DIGIT))
|
if (iswctype(c, _DIGIT))
|
||||||
c -= L'0';
|
c -= L'0';
|
||||||
else if (iswctype(c, _ALPHA))
|
else if (iswctype(c, _ALPHA))
|
||||||
c -= iswctype(c, _UPPER) ? 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)
|
||||||
break;
|
break;
|
||||||
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
|
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
|
||||||
any = -1;
|
any = -1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
any = 1;
|
any = 1;
|
||||||
acc *= base;
|
acc *= base;
|
||||||
acc += c;
|
acc += c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (any < 0)
|
if (any < 0)
|
||||||
{
|
{
|
||||||
acc = neg ? LONG_MIN : LONG_MAX;
|
acc = neg ? LONG_MIN : LONG_MAX;
|
||||||
}
|
}
|
||||||
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 *)s - 1 : (wchar_t *)nptr;
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
|
@ -1,46 +1,60 @@
|
||||||
/* $Id$
|
#include <windows.h>
|
||||||
*
|
#define NTOS_MODE_USER
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
#define _NTSYSTEM_
|
||||||
* PROJECT: ReactOS kernel
|
#include <ndk/umtypes.h>
|
||||||
* FILE: lib/ntdll/stdlib/wcstombs.c
|
#include <ndk/rtlfuncs.h>
|
||||||
* PURPOSE: converts a unicode string to a multi byte string
|
|
||||||
*/
|
/*
|
||||||
|
* @implemented
|
||||||
#include <ntdll.h>
|
*/
|
||||||
#define NDEBUG
|
int wctomb (char *mbchar, wchar_t wchar)
|
||||||
#include <debug.h>
|
{
|
||||||
#include <stdlib.h>
|
NTSTATUS Status;
|
||||||
#include <string.h>
|
ULONG Size;
|
||||||
|
|
||||||
/*
|
if (mbchar == NULL)
|
||||||
* @implemented
|
return 0;
|
||||||
*/
|
|
||||||
size_t wcstombs (char *mbstr, const wchar_t *wcstr, size_t count)
|
Status = RtlUnicodeToMultiByteN (mbchar,
|
||||||
{
|
1,
|
||||||
NTSTATUS Status;
|
&Size,
|
||||||
ULONG Size;
|
&wchar,
|
||||||
ULONG Length;
|
sizeof(WCHAR));
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
Length = wcslen (wcstr);
|
return -1;
|
||||||
|
|
||||||
if (mbstr == NULL)
|
return (int)Size;
|
||||||
{
|
}
|
||||||
RtlUnicodeToMultiByteSize (&Size,
|
|
||||||
(wchar_t *)wcstr,
|
/*
|
||||||
Length * sizeof(WCHAR));
|
* @implemented
|
||||||
|
*/
|
||||||
return (size_t)Size;
|
size_t wcstombs (char *mbstr, const wchar_t *wcstr, size_t count)
|
||||||
}
|
{
|
||||||
|
NTSTATUS Status;
|
||||||
Status = RtlUnicodeToMultiByteN (mbstr,
|
ULONG Size;
|
||||||
count,
|
ULONG Length;
|
||||||
&Size,
|
|
||||||
(wchar_t *)wcstr,
|
Length = wcslen (wcstr);
|
||||||
Length * sizeof(WCHAR));
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (mbstr == NULL)
|
||||||
return -1;
|
{
|
||||||
|
RtlUnicodeToMultiByteSize (&Size,
|
||||||
return (size_t)Size;
|
(wchar_t *)wcstr,
|
||||||
}
|
Length * sizeof(WCHAR));
|
||||||
|
|
||||||
/* EOF */
|
return (size_t)Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = RtlUnicodeToMultiByteN (mbstr,
|
||||||
|
count,
|
||||||
|
&Size,
|
||||||
|
(wchar_t *)wcstr,
|
||||||
|
Length * sizeof(WCHAR));
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return (size_t)Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* EOF */
|
|
@ -1,72 +1,74 @@
|
||||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
#include <string.h>
|
||||||
#include <ntdll.h>
|
#include <ctype.h>
|
||||||
|
#include <limits.h>
|
||||||
/*
|
|
||||||
* Convert a unicode string to an unsigned long integer.
|
|
||||||
*
|
/*
|
||||||
* Ignores `locale' stuff. Assumes that the upper and lower case
|
* Convert a unicode string to an unsigned long integer.
|
||||||
* alphabets and digits are each contiguous.
|
*
|
||||||
*
|
* Ignores `locale' stuff. Assumes that the upper and lower case
|
||||||
* @implemented
|
* alphabets and digits are each contiguous.
|
||||||
*/
|
*
|
||||||
unsigned long
|
* @implemented
|
||||||
wcstoul(const wchar_t *nptr, wchar_t **endptr, int base)
|
*/
|
||||||
{
|
unsigned long
|
||||||
const wchar_t *s = nptr;
|
wcstoul(const wchar_t *nptr, wchar_t **endptr, int base)
|
||||||
unsigned long acc;
|
{
|
||||||
int c;
|
const wchar_t *s = nptr;
|
||||||
unsigned long cutoff;
|
unsigned long acc;
|
||||||
int neg = 0, any, cutlim;
|
int c;
|
||||||
|
unsigned long cutoff;
|
||||||
/*
|
int neg = 0, any, cutlim;
|
||||||
* See strtol for comments as to the logic used.
|
|
||||||
*/
|
/*
|
||||||
do {
|
* See strtol for comments as to the logic used.
|
||||||
c = *s++;
|
*/
|
||||||
} while (iswctype(c, _SPACE));
|
do {
|
||||||
if (c == '-')
|
c = *s++;
|
||||||
{
|
} while (iswctype(c, _SPACE));
|
||||||
neg = 1;
|
if (c == '-')
|
||||||
c = *s++;
|
{
|
||||||
}
|
neg = 1;
|
||||||
else if (c == L'+')
|
c = *s++;
|
||||||
c = *s++;
|
}
|
||||||
if ((base == 0 || base == 16) &&
|
else if (c == L'+')
|
||||||
c == L'0' && (*s == L'x' || *s == L'X'))
|
c = *s++;
|
||||||
{
|
if ((base == 0 || base == 16) &&
|
||||||
c = s[1];
|
c == L'0' && (*s == L'x' || *s == L'X'))
|
||||||
s += 2;
|
{
|
||||||
base = 16;
|
c = s[1];
|
||||||
}
|
s += 2;
|
||||||
if (base == 0)
|
base = 16;
|
||||||
base = c == L'0' ? 8 : 10;
|
}
|
||||||
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
|
if (base == 0)
|
||||||
cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
|
base = c == L'0' ? 8 : 10;
|
||||||
for (acc = 0, any = 0;; c = *s++)
|
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
|
||||||
{
|
cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
|
||||||
if (iswctype(c, _DIGIT))
|
for (acc = 0, any = 0;; c = *s++)
|
||||||
c -= L'0';
|
{
|
||||||
else if (iswctype(c, _ALPHA))
|
if (iswctype(c, _DIGIT))
|
||||||
c -= iswctype(c, _UPPER) ? L'A' - 10 : L'a' - 10;
|
c -= L'0';
|
||||||
else
|
else if (iswctype(c, _ALPHA))
|
||||||
break;
|
c -= iswctype(c, _UPPER) ? L'A' - 10 : L'a' - 10;
|
||||||
if (c >= base)
|
else
|
||||||
break;
|
break;
|
||||||
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
|
if (c >= base)
|
||||||
any = -1;
|
break;
|
||||||
else {
|
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
|
||||||
any = 1;
|
any = -1;
|
||||||
acc *= base;
|
else {
|
||||||
acc += c;
|
any = 1;
|
||||||
}
|
acc *= base;
|
||||||
}
|
acc += c;
|
||||||
if (any < 0)
|
}
|
||||||
{
|
}
|
||||||
acc = ULONG_MAX;
|
if (any < 0)
|
||||||
}
|
{
|
||||||
else if (neg)
|
acc = ULONG_MAX;
|
||||||
acc = -acc;
|
}
|
||||||
if (endptr != 0)
|
else if (neg)
|
||||||
*endptr = any ? (wchar_t *)s - 1 : (wchar_t *)nptr;
|
acc = -acc;
|
||||||
return acc;
|
if (endptr != 0)
|
||||||
}
|
*endptr = any ? (wchar_t *)s - 1 : (wchar_t *)nptr;
|
||||||
|
return acc;
|
||||||
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
#include <string.h>
|
||||||
#include <ntdll.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
_wtoi(const wchar_t *str)
|
_wtoi(const wchar_t *str)
|
||||||
{
|
{
|
||||||
return (int)wcstol(str, 0, 10);
|
return (int)wcstol(str, 0, 10);
|
||||||
}
|
}
|
|
@ -1,43 +1,37 @@
|
||||||
/* $Id$
|
#include <string.h>
|
||||||
*
|
#include <ctype.h>
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
|
||||||
* PROJECT: ReactOS kernel
|
|
||||||
* FILE: lib/ntdll/stdlib/wtoi64.c
|
/*
|
||||||
* PURPOSE: converts a unicode string to 64 bit integer
|
* @implemented
|
||||||
*/
|
*/
|
||||||
|
__int64
|
||||||
#include <ntdll.h>
|
_wtoi64 (const wchar_t *nptr)
|
||||||
|
{
|
||||||
/*
|
int c;
|
||||||
* @implemented
|
__int64 value;
|
||||||
*/
|
int sign;
|
||||||
__int64
|
|
||||||
_wtoi64 (const wchar_t *nptr)
|
while (iswctype((int)*nptr, _SPACE))
|
||||||
{
|
++nptr;
|
||||||
int c;
|
|
||||||
__int64 value;
|
c = (int)*nptr++;
|
||||||
int sign;
|
sign = c;
|
||||||
|
if (c == L'-' || c == L'+')
|
||||||
while (iswctype((int)*nptr, _SPACE))
|
c = (int)*nptr++;
|
||||||
++nptr;
|
|
||||||
|
value = 0;
|
||||||
c = (int)*nptr++;
|
|
||||||
sign = c;
|
while (iswctype(c, _DIGIT))
|
||||||
if (c == L'-' || c == L'+')
|
{
|
||||||
c = (int)*nptr++;
|
value = 10 * value + (c - L'0');
|
||||||
|
c = (int)*nptr++;
|
||||||
value = 0;
|
}
|
||||||
|
|
||||||
while (iswctype(c, _DIGIT))
|
if (sign == L'-')
|
||||||
{
|
return -value;
|
||||||
value = 10 * value + (c - L'0');
|
else
|
||||||
c = (int)*nptr++;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sign == L'-')
|
/* EOF */
|
||||||
return -value;
|
|
||||||
else
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* EOF */
|
|
|
@ -1,11 +1,11 @@
|
||||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
#include <string.h>
|
||||||
#include <ntdll.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
long
|
long
|
||||||
_wtol(const wchar_t *str)
|
_wtol(const wchar_t *str)
|
||||||
{
|
{
|
||||||
return wcstol(str, 0, 10);
|
return wcstol(str, 0, 10);
|
||||||
}
|
}
|
|
@ -321,7 +321,6 @@
|
||||||
<file>purecall.c</file>
|
<file>purecall.c</file>
|
||||||
<file>regio.c</file>
|
<file>regio.c</file>
|
||||||
<file>sprintf.c</file>
|
<file>sprintf.c</file>
|
||||||
<file>stdlib.c</file>
|
|
||||||
<file>strtok.c</file>
|
<file>strtok.c</file>
|
||||||
<file>swprintf.c</file>
|
<file>swprintf.c</file>
|
||||||
</directory>
|
</directory>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue