From 48fe1fb84bb207c5717fc3891ebc52348b3168b0 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Thu, 8 Sep 2005 05:03:34 +0000 Subject: [PATCH] Share more duplicated functions svn path=/trunk/; revision=17734 --- reactos/include/ndk/rtlfuncs.h | 2 + reactos/lib/ntdll/ntdll.xml | 21 - reactos/lib/ntdll/stdlib/abs.c | 11 - reactos/lib/ntdll/stdlib/labs.c | 11 - reactos/lib/string/abs.c | 10 + reactos/lib/{ntdll/stdlib => string}/atoi.c | 22 +- reactos/lib/{ntdll/stdlib => string}/atoi64.c | 79 ++-- reactos/lib/{ntdll/stdlib => string}/atol.c | 22 +- .../lib/{ntdll/stdlib => string}/bsearch.c | 55 ++- reactos/lib/{ntdll/stdlib => string}/itoa.c | 350 +++++++-------- reactos/lib/{ntdll/stdlib => string}/itow.c | 411 +++++++++--------- reactos/lib/string/labs.c | 9 + reactos/lib/{ntdll/stdlib => string}/lfind.c | 42 +- .../lib/{ntdll/stdlib => string}/mbstowcs.c | 106 +++-- reactos/lib/string/rand.c | 29 ++ reactos/lib/{ntdll/stdlib => string}/splitp.c | 101 +++-- reactos/lib/string/string.xml | 20 + reactos/lib/{ntdll/stdlib => string}/strtol.c | 179 ++++---- .../lib/{ntdll/stdlib => string}/strtoul.c | 146 +++---- reactos/lib/{ntdll/stdlib => string}/wcstol.c | 180 ++++---- .../lib/{ntdll/stdlib => string}/wcstombs.c | 106 +++-- .../lib/{ntdll/stdlib => string}/wcstoul.c | 146 ++++--- reactos/lib/{ntdll/stdlib => string}/wtoi.c | 22 +- reactos/lib/{ntdll/stdlib => string}/wtoi64.c | 80 ++-- reactos/lib/{ntdll/stdlib => string}/wtol.c | 22 +- reactos/ntoskrnl/ntoskrnl.xml | 1 - 26 files changed, 1099 insertions(+), 1084 deletions(-) delete mode 100644 reactos/lib/ntdll/stdlib/abs.c delete mode 100644 reactos/lib/ntdll/stdlib/labs.c create mode 100644 reactos/lib/string/abs.c rename reactos/lib/{ntdll/stdlib => string}/atoi.c (51%) rename reactos/lib/{ntdll/stdlib => string}/atoi64.c (65%) rename reactos/lib/{ntdll/stdlib => string}/atol.c (50%) rename reactos/lib/{ntdll/stdlib => string}/bsearch.c (85%) rename reactos/lib/{ntdll/stdlib => string}/itoa.c (80%) rename reactos/lib/{ntdll/stdlib => string}/itow.c (87%) create mode 100644 reactos/lib/string/labs.c rename reactos/lib/{ntdll/stdlib => string}/lfind.c (89%) rename reactos/lib/{ntdll/stdlib => string}/mbstowcs.c (51%) create mode 100644 reactos/lib/string/rand.c rename reactos/lib/{ntdll/stdlib => string}/splitp.c (93%) rename reactos/lib/{ntdll/stdlib => string}/strtol.c (93%) rename reactos/lib/{ntdll/stdlib => string}/strtoul.c (91%) rename reactos/lib/{ntdll/stdlib => string}/wcstol.c (93%) rename reactos/lib/{ntdll/stdlib => string}/wcstombs.c (53%) rename reactos/lib/{ntdll/stdlib => string}/wcstoul.c (91%) rename reactos/lib/{ntdll/stdlib => string}/wtoi.c (52%) rename reactos/lib/{ntdll/stdlib => string}/wtoi64.c (66%) rename reactos/lib/{ntdll/stdlib => string}/wtol.c (51%) diff --git a/reactos/include/ndk/rtlfuncs.h b/reactos/include/ndk/rtlfuncs.h index d5bfe11c1a5..8eade3854d7 100644 --- a/reactos/include/ndk/rtlfuncs.h +++ b/reactos/include/ndk/rtlfuncs.h @@ -11,6 +11,8 @@ /* DEPENDENCIES **************************************************************/ #include +#include "extypes.h" +#include "rtltypes.h" /* PROTOTYPES ****************************************************************/ diff --git a/reactos/lib/ntdll/ntdll.xml b/reactos/lib/ntdll/ntdll.xml index 4dba6ef8b4d..78445567e46 100644 --- a/reactos/lib/ntdll/ntdll.xml +++ b/reactos/lib/ntdll/ntdll.xml @@ -42,27 +42,6 @@ sscanf.c swprintf.c - - abs.c - atoi64.c - atoi.c - atol.c - bsearch.c - itoa.c - itow.c - labs.c - lfind.c - mbstowcs.c - splitp.c - strtol.c - strtoul.c - wcstol.c - wcstombs.c - wcstoul.c - wtoi64.c - wtoi.c - wtol.c - ntdll.rc diff --git a/reactos/lib/ntdll/stdlib/abs.c b/reactos/lib/ntdll/stdlib/abs.c deleted file mode 100644 index 98953c4c2f9..00000000000 --- a/reactos/lib/ntdll/stdlib/abs.c +++ /dev/null @@ -1,11 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -int -abs(int j) -{ - return j<0 ? -j : j; -} diff --git a/reactos/lib/ntdll/stdlib/labs.c b/reactos/lib/ntdll/stdlib/labs.c deleted file mode 100644 index 52ef2473624..00000000000 --- a/reactos/lib/ntdll/stdlib/labs.c +++ /dev/null @@ -1,11 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -long -labs(long j) -{ - return j<0 ? -j : j; -} diff --git a/reactos/lib/string/abs.c b/reactos/lib/string/abs.c new file mode 100644 index 00000000000..4f57aa8d5ab --- /dev/null +++ b/reactos/lib/string/abs.c @@ -0,0 +1,10 @@ +#include + +/* + * @implemented + */ +int +abs(int j) +{ + return j<0 ? -j : j; +} diff --git a/reactos/lib/ntdll/stdlib/atoi.c b/reactos/lib/string/atoi.c similarity index 51% rename from reactos/lib/ntdll/stdlib/atoi.c rename to reactos/lib/string/atoi.c index 3e2331b2e0b..790653f39a9 100644 --- a/reactos/lib/ntdll/stdlib/atoi.c +++ b/reactos/lib/string/atoi.c @@ -1,11 +1,11 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -int -atoi(const char *str) -{ - return (int)strtol(str, 0, 10); -} +#include +#include + +/* + * @implemented + */ +int +atoi(const char *str) +{ + return (int)strtol(str, 0, 10); +} diff --git a/reactos/lib/ntdll/stdlib/atoi64.c b/reactos/lib/string/atoi64.c similarity index 65% rename from reactos/lib/ntdll/stdlib/atoi64.c rename to reactos/lib/string/atoi64.c index cd9cba796fa..a9ddb446c84 100644 --- a/reactos/lib/ntdll/stdlib/atoi64.c +++ b/reactos/lib/string/atoi64.c @@ -1,43 +1,36 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: lib/ntdll/stdlib/atoi64.c - * PURPOSE: converts an ascii string to 64 bit integer - */ - -#include - -/* - * @implemented - */ -__int64 -_atoi64 (const char *nptr) -{ - int c; - __int64 value; - int sign; - - while (isspace((int)*nptr)) - ++nptr; - - c = (int)*nptr++; - sign = c; - if (c == '-' || c == '+') - c = (int)*nptr++; - - value = 0; - - while (isdigit(c)) - { - value = 10 * value + (c - '0'); - c = (int)*nptr++; - } - - if (sign == '-') - return -value; - else - return value; -} - -/* EOF */ +#include +#include + +/* + * @implemented + */ +__int64 +_atoi64 (const char *nptr) +{ + int c; + __int64 value; + int sign; + + while (isspace((int)*nptr)) + ++nptr; + + c = (int)*nptr++; + sign = c; + if (c == '-' || c == '+') + c = (int)*nptr++; + + value = 0; + + while (isdigit(c)) + { + value = 10 * value + (c - '0'); + c = (int)*nptr++; + } + + if (sign == '-') + return -value; + else + return value; +} + +/* EOF */ diff --git a/reactos/lib/ntdll/stdlib/atol.c b/reactos/lib/string/atol.c similarity index 50% rename from reactos/lib/ntdll/stdlib/atol.c rename to reactos/lib/string/atol.c index fca9a312360..18f8711b029 100644 --- a/reactos/lib/ntdll/stdlib/atol.c +++ b/reactos/lib/string/atol.c @@ -1,11 +1,11 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -long -atol(const char *str) -{ - return strtol(str, 0, 10); -} +#include +#include + +/* + * @implemented + */ +long +atol(const char *str) +{ + return strtol(str, 0, 10); +} diff --git a/reactos/lib/ntdll/stdlib/bsearch.c b/reactos/lib/string/bsearch.c similarity index 85% rename from reactos/lib/ntdll/stdlib/bsearch.c rename to reactos/lib/string/bsearch.c index 08f7d94feee..d76db177c16 100644 --- a/reactos/lib/ntdll/stdlib/bsearch.c +++ b/reactos/lib/string/bsearch.c @@ -1,28 +1,27 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -void * -bsearch(const void *key, const void *base0, size_t nelem, - size_t size, int (*cmp)(const void *ck, const void *ce)) -{ - char *base = (char *)base0; - int lim, cmpval; - void *p; - - for (lim = nelem; lim != 0; lim >>= 1) - { - p = base + (lim >> 1) * size; - cmpval = (*cmp)(key, p); - if (cmpval == 0) - return p; - if (cmpval > 0) - { /* key > p: move right */ - base = (char *)p + size; - lim--; - } /* else move left */ - } - return 0; -} +#include + +/* + * @implemented + */ +void * +bsearch(const void *key, const void *base0, size_t nelem, + size_t size, int (*cmp)(const void *ck, const void *ce)) +{ + char *base = (char *)base0; + int lim, cmpval; + void *p; + + for (lim = nelem; lim != 0; lim >>= 1) + { + p = base + (lim >> 1) * size; + cmpval = (*cmp)(key, p); + if (cmpval == 0) + return p; + if (cmpval > 0) + { /* key > p: move right */ + base = (char *)p + size; + lim--; + } /* else move left */ + } + return 0; +} diff --git a/reactos/lib/ntdll/stdlib/itoa.c b/reactos/lib/string/itoa.c similarity index 80% rename from reactos/lib/ntdll/stdlib/itoa.c rename to reactos/lib/string/itoa.c index 0643b3d177e..3bcb9cb2321 100644 --- a/reactos/lib/ntdll/stdlib/itoa.c +++ b/reactos/lib/string/itoa.c @@ -1,183 +1,167 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/ntdll/stdlib/itoa.c - * PURPOSE: converts an integer to ascii - * PROGRAMER: - * UPDATE HISTORY: - * 1995: Created - * 1998: Added ltoa Boudewijn Dekker - * 2003: Corrected ltoa implementation - Steven Edwards - */ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details - * Copyright 2000 Alexandre Julliard - * Copyright 2000 Jon Griffiths - * Copyright 2003 Thomas Mertes - */ - -#include - -/* - * @implemented - */ -char * -_i64toa(__int64 value, char *string, int radix) -{ - char tmp[65]; - char *tp = tmp; - __int64 i; - unsigned __int64 v; - __int64 sign; - char *sp; - - if (radix > 36 || radix <= 1) - { - return 0; - } - - sign = (radix == 10 && value < 0); - if (sign) - v = -value; - else - v = (unsigned __int64)value; - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+'0'; - else - *tp++ = i + 'a' - 10; - } - - sp = string; - if (sign) - *sp++ = '-'; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - return string; -} - - -/* - * @implemented - */ -char * -_ui64toa(unsigned __int64 value, char *string, int radix) -{ - char tmp[65]; - char *tp = tmp; - __int64 i; - unsigned __int64 v; - char *sp; - - if (radix > 36 || radix <= 1) - { - return 0; - } - - v = (unsigned __int64)value; - 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; -} - - -/* - * @implemented - */ -char * -_itoa(int value, char *string, int radix) -{ - return _ltoa(value, string, radix); -} - - -/* - * @implemented - */ -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 - */ -char * -_ultoa(unsigned long value, char *string, int radix) -{ - char tmp[33]; - char *tp = tmp; - long i; - unsigned long v = value; - char *sp; - - if (radix > 36 || radix <= 1) - { - return 0; - } - - 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; -} +#include +#include + +/* + * @implemented + */ +char * +_i64toa(__int64 value, char *string, int radix) +{ + char tmp[65]; + char *tp = tmp; + __int64 i; + unsigned __int64 v; + __int64 sign; + char *sp; + + if (radix > 36 || radix <= 1) + { + return 0; + } + + sign = (radix == 10 && value < 0); + if (sign) + v = -value; + else + v = (unsigned __int64)value; + while (v || tp == tmp) + { + i = v % radix; + v = v / radix; + if (i < 10) + *tp++ = i+'0'; + else + *tp++ = i + 'a' - 10; + } + + sp = string; + if (sign) + *sp++ = '-'; + while (tp > tmp) + *sp++ = *--tp; + *sp = 0; + return string; +} + + +/* + * @implemented + */ +char * +_ui64toa(unsigned __int64 value, char *string, int radix) +{ + char tmp[65]; + char *tp = tmp; + __int64 i; + unsigned __int64 v; + char *sp; + + if (radix > 36 || radix <= 1) + { + return 0; + } + + v = (unsigned __int64)value; + 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; +} + + +/* + * @implemented + */ +char * +_itoa(int value, char *string, int radix) +{ + return _ltoa(value, string, radix); +} + + +/* + * @implemented + */ +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 + */ +char * +_ultoa(unsigned long value, char *string, int radix) +{ + char tmp[33]; + char *tp = tmp; + long i; + unsigned long v = value; + char *sp; + + if (radix > 36 || radix <= 1) + { + return 0; + } + + 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; +} diff --git a/reactos/lib/ntdll/stdlib/itow.c b/reactos/lib/string/itow.c similarity index 87% rename from reactos/lib/ntdll/stdlib/itow.c rename to reactos/lib/string/itow.c index eb7aa6132f4..e82da0747cf 100644 --- a/reactos/lib/ntdll/stdlib/itow.c +++ b/reactos/lib/string/itow.c @@ -1,211 +1,200 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/ntdll/stdlib/itow.c - * PURPOSE: converts an integer to Unicode - * PROGRAMER: - * UPDATE HISTORY: - * 1995: Created - * 1998: Added ltoa Boudewijn Dekker - */ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -wchar_t * -_i64tow(__int64 value, wchar_t *string, int radix) -{ - wchar_t tmp[65]; - wchar_t *tp = tmp; - __int64 i; - unsigned __int64 v; - __int64 sign; - wchar_t *sp; - - if (radix > 36 || radix <= 1) - { - return 0; - } - - sign = (radix == 10 && value < 0); - if (sign) - v = -value; - else - v = (unsigned __int64)value; - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+L'0'; - else - *tp++ = i + L'a' - 10; - } - - sp = string; - if (sign) - *sp++ = L'-'; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - return string; -} - - -/* - * @implemented - */ -wchar_t * -_ui64tow(unsigned __int64 value, wchar_t *string, int radix) -{ - wchar_t tmp[65]; - wchar_t *tp = tmp; - __int64 i; - unsigned __int64 v; - wchar_t *sp; - - if (radix > 36 || radix <= 1) - { - return 0; - } - - v = (unsigned __int64)value; - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+L'0'; - else - *tp++ = i + L'a' - 10; - } - - sp = string; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - return string; -} - - -/* - * @implemented - */ -wchar_t * -_itow(int value, wchar_t *string, int radix) -{ - wchar_t tmp[33]; - wchar_t *tp = tmp; - int i; - unsigned v; - int sign; - wchar_t *sp; - - if (radix > 36 || radix <= 1) - { - return 0; - } - - sign = (radix == 10 && value < 0); - if (sign) - v = -value; - else - v = (unsigned)value; - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+L'0'; - else - *tp++ = i + L'a' - 10; - } - - sp = string; - if (sign) - *sp++ = L'-'; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - return string; -} - - -/* - * @implemented - */ -wchar_t * -_ltow(long value, wchar_t *string, int radix) -{ - wchar_t tmp[33]; - wchar_t *tp = tmp; - long i; - unsigned long v; - int sign; - wchar_t *sp; - - if (radix > 36 || radix <= 1) - { - 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+L'0'; - else - *tp++ = i + L'a' - 10; - } - - sp = string; - if (sign) - *sp++ = L'-'; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - return string; -} - - -/* - * @implemented - */ -wchar_t * -_ultow(unsigned long value, wchar_t *string, int radix) -{ - wchar_t tmp[33]; - wchar_t *tp = tmp; - long i; - unsigned long v = value; - wchar_t *sp; - - if (radix > 36 || radix <= 1) - { - return 0; - } - - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+L'0'; - else - *tp++ = i + L'a' - 10; - } - - sp = string; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - return string; -} +#include + +/* + * @implemented + */ +wchar_t * +_i64tow(__int64 value, wchar_t *string, int radix) +{ + wchar_t tmp[65]; + wchar_t *tp = tmp; + __int64 i; + unsigned __int64 v; + __int64 sign; + wchar_t *sp; + + if (radix > 36 || radix <= 1) + { + return 0; + } + + sign = (radix == 10 && value < 0); + if (sign) + v = -value; + else + v = (unsigned __int64)value; + while (v || tp == tmp) + { + i = v % radix; + v = v / radix; + if (i < 10) + *tp++ = i+L'0'; + else + *tp++ = i + L'a' - 10; + } + + sp = string; + if (sign) + *sp++ = L'-'; + while (tp > tmp) + *sp++ = *--tp; + *sp = 0; + return string; +} + + +/* + * @implemented + */ +wchar_t * +_ui64tow(unsigned __int64 value, wchar_t *string, int radix) +{ + wchar_t tmp[65]; + wchar_t *tp = tmp; + __int64 i; + unsigned __int64 v; + wchar_t *sp; + + if (radix > 36 || radix <= 1) + { + return 0; + } + + v = (unsigned __int64)value; + while (v || tp == tmp) + { + i = v % radix; + v = v / radix; + if (i < 10) + *tp++ = i+L'0'; + else + *tp++ = i + L'a' - 10; + } + + sp = string; + while (tp > tmp) + *sp++ = *--tp; + *sp = 0; + return string; +} + + +/* + * @implemented + */ +wchar_t * +_itow(int value, wchar_t *string, int radix) +{ + wchar_t tmp[33]; + wchar_t *tp = tmp; + int i; + unsigned v; + int sign; + wchar_t *sp; + + if (radix > 36 || radix <= 1) + { + return 0; + } + + sign = (radix == 10 && value < 0); + if (sign) + v = -value; + else + v = (unsigned)value; + while (v || tp == tmp) + { + i = v % radix; + v = v / radix; + if (i < 10) + *tp++ = i+L'0'; + else + *tp++ = i + L'a' - 10; + } + + sp = string; + if (sign) + *sp++ = L'-'; + while (tp > tmp) + *sp++ = *--tp; + *sp = 0; + return string; +} + + +/* + * @implemented + */ +wchar_t * +_ltow(long value, wchar_t *string, int radix) +{ + wchar_t tmp[33]; + wchar_t *tp = tmp; + long i; + unsigned long v; + int sign; + wchar_t *sp; + + if (radix > 36 || radix <= 1) + { + 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+L'0'; + else + *tp++ = i + L'a' - 10; + } + + sp = string; + if (sign) + *sp++ = L'-'; + while (tp > tmp) + *sp++ = *--tp; + *sp = 0; + return string; +} + + +/* + * @implemented + */ +wchar_t * +_ultow(unsigned long value, wchar_t *string, int radix) +{ + wchar_t tmp[33]; + wchar_t *tp = tmp; + long i; + unsigned long v = value; + wchar_t *sp; + + if (radix > 36 || radix <= 1) + { + return 0; + } + + while (v || tp == tmp) + { + i = v % radix; + v = v / radix; + if (i < 10) + *tp++ = i+L'0'; + else + *tp++ = i + L'a' - 10; + } + + sp = string; + while (tp > tmp) + *sp++ = *--tp; + *sp = 0; + return string; +} diff --git a/reactos/lib/string/labs.c b/reactos/lib/string/labs.c new file mode 100644 index 00000000000..7ef91694786 --- /dev/null +++ b/reactos/lib/string/labs.c @@ -0,0 +1,9 @@ +#include +/* + * @implemented + */ +long +labs(long j) +{ + return j<0 ? -j : j; +} diff --git a/reactos/lib/ntdll/stdlib/lfind.c b/reactos/lib/string/lfind.c similarity index 89% rename from reactos/lib/ntdll/stdlib/lfind.c rename to reactos/lib/string/lfind.c index 93b454ababa..18353a2680d 100644 --- a/reactos/lib/ntdll/stdlib/lfind.c +++ b/reactos/lib/string/lfind.c @@ -1,22 +1,20 @@ -#include - - -/* - * @implemented - */ -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; - - for (i = 0; i < *nelp; i++) - { - if (compar(key, char_base) == 0) - return char_base; - - char_base += width; - } - - return NULL; -} +#include +/* + * @implemented + */ +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; + + for (i = 0; i < *nelp; i++) + { + if (compar(key, char_base) == 0) + return char_base; + + char_base += width; + } + + return NULL; +} diff --git a/reactos/lib/ntdll/stdlib/mbstowcs.c b/reactos/lib/string/mbstowcs.c similarity index 51% rename from reactos/lib/ntdll/stdlib/mbstowcs.c rename to reactos/lib/string/mbstowcs.c index 19d69ef6b6e..a403f7f7255 100644 --- a/reactos/lib/ntdll/stdlib/mbstowcs.c +++ b/reactos/lib/string/mbstowcs.c @@ -1,45 +1,61 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: lib/ntdll/stdlib/mbstowcs.c - * PURPOSE: converts a multi byte string to a unicode string - */ - -#include -#define NDEBUG -#include -#include -#include -/* - * @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, - (char *)mbstr, - Length); - - return (size_t)Size; - } - - Status = RtlMultiByteToUnicodeN (wcstr, - count, - &Size, - (char *)mbstr, - Length); - if (!NT_SUCCESS(Status)) - return -1; - - return (size_t)Size; -} - -/* EOF */ +#include +#define NTOS_MODE_USER +#define _NTSYSTEM_ +#include +#include +#include + +/* + * @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, + (char *)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, + (char *)mbstr, + Length); + + return (size_t)Size; + } + + Status = RtlMultiByteToUnicodeN (wcstr, + count, + &Size, + (char *)mbstr, + Length); + if (!NT_SUCCESS(Status)) + return -1; + + return (size_t)Size; +} + +/* EOF */ diff --git a/reactos/lib/string/rand.c b/reactos/lib/string/rand.c new file mode 100644 index 00000000000..a03107620e6 --- /dev/null +++ b/reactos/lib/string/rand.c @@ -0,0 +1,29 @@ +#include + +#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; +} diff --git a/reactos/lib/ntdll/stdlib/splitp.c b/reactos/lib/string/splitp.c similarity index 93% rename from reactos/lib/ntdll/stdlib/splitp.c rename to reactos/lib/string/splitp.c index be123f365cc..041b4324ff3 100644 --- a/reactos/lib/ntdll/stdlib/splitp.c +++ b/reactos/lib/string/splitp.c @@ -1,51 +1,50 @@ -#include - -/* - * @implemented - */ -void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext) -{ - char* tmp_drive; - char* tmp_dir; - char* tmp_ext; - - tmp_drive = (char*)strchr(path,':'); - if (drive) { - if (tmp_drive) { - strncpy(drive,tmp_drive-1,2); - *(drive+2) = 0; - } else { - *drive = 0; - } - } - if (!tmp_drive) { - tmp_drive = (char*)path - 1; - } - - tmp_dir = (char*)strrchr(path,'\\'); - if (dir) { - if (tmp_dir) { - strncpy(dir,tmp_drive+1,tmp_dir-tmp_drive); - *(dir+(tmp_dir-tmp_drive)) = 0; - } else { - *dir =0; - } - } - - tmp_ext = (char*)strrchr(path,'.'); - if (!tmp_ext) { - tmp_ext = (char*)path+strlen(path); - } - if (ext) { - strcpy(ext,tmp_ext); - } - - if (tmp_dir) { - strncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1); - *(fname+(tmp_ext-tmp_dir-1)) = 0; - } else { - strncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1); - *(fname+(tmp_ext-path))=0; - } -} - +#include +/* + * @implemented + */ +void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext) +{ + char* tmp_drive; + char* tmp_dir; + char* tmp_ext; + + tmp_drive = (char*)strchr(path,':'); + if (drive) { + if (tmp_drive) { + strncpy(drive,tmp_drive-1,2); + *(drive+2) = 0; + } else { + *drive = 0; + } + } + if (!tmp_drive) { + tmp_drive = (char*)path - 1; + } + + tmp_dir = (char*)strrchr(path,'\\'); + if (dir) { + if (tmp_dir) { + strncpy(dir,tmp_drive+1,tmp_dir-tmp_drive); + *(dir+(tmp_dir-tmp_drive)) = 0; + } else { + *dir =0; + } + } + + tmp_ext = (char*)strrchr(path,'.'); + if (!tmp_ext) { + tmp_ext = (char*)path+strlen(path); + } + if (ext) { + strcpy(ext,tmp_ext); + } + + if (tmp_dir) { + strncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1); + *(fname+(tmp_ext-tmp_dir-1)) = 0; + } else { + strncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1); + *(fname+(tmp_ext-path))=0; + } +} + diff --git a/reactos/lib/string/string.xml b/reactos/lib/string/string.xml index d5cb133a8b2..efb29ecfaf1 100644 --- a/reactos/lib/string/string.xml +++ b/reactos/lib/string/string.xml @@ -76,4 +76,24 @@ wstring.c wcsrev.c wcsnset.c + abs.c + atoi64.c + atoi.c + atol.c + bsearch.c + itoa.c + itow.c + labs.c + lfind.c + mbstowcs.c + splitp.c + strtol.c + strtoul.c + wcstol.c + wcstombs.c + wcstoul.c + wtoi64.c + wtoi.c + wtol.c + rand.c diff --git a/reactos/lib/ntdll/stdlib/strtol.c b/reactos/lib/string/strtol.c similarity index 93% rename from reactos/lib/ntdll/stdlib/strtol.c rename to reactos/lib/string/strtol.c index b6d4f551ed0..dd66a1ee8a0 100644 --- a/reactos/lib/ntdll/stdlib/strtol.c +++ b/reactos/lib/string/strtol.c @@ -1,89 +1,90 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -long -strtol(const char *nptr, char **endptr, int base) -{ - const char *s = nptr; - unsigned long acc; - int c; - 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 - * assume decimal; if base is already 16, allow 0x. - */ - do { - c = *s++; - } while (isspace(c)); - if (c == '-') - { - neg = 1; - c = *s++; - } - else if (c == '+') - c = *s++; - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) - { - c = s[1]; - s += 2; - base = 16; - } - 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 - * base. An input number that is greater than this value, if - * followed by a legal input character, is too big. One that - * is equal to this value may be valid or not; the limit - * between valid and invalid numbers is then based on the last - * 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 - * 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. - */ - cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; - cutlim = cutoff % (unsigned long)base; - cutoff /= (unsigned long)base; - for (acc = 0, any = 0;; c = *s++) - { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : '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 ? (char *)s - 1 : (char *)nptr; - return acc; -} +#include +#include +#include + +/* + * @implemented + */ +long +strtol(const char *nptr, char **endptr, int base) +{ + const char *s = nptr; + unsigned long acc; + int c; + 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 + * assume decimal; if base is already 16, allow 0x. + */ + do { + c = *s++; + } while (isspace(c)); + if (c == '-') + { + neg = 1; + c = *s++; + } + else if (c == '+') + c = *s++; + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) + { + c = s[1]; + s += 2; + base = 16; + } + 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 + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * 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 + * 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. + */ + cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; + cutlim = cutoff % (unsigned long)base; + cutoff /= (unsigned long)base; + for (acc = 0, any = 0;; c = *s++) + { + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : '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 ? (char *)s - 1 : (char *)nptr; + return acc; +} diff --git a/reactos/lib/ntdll/stdlib/strtoul.c b/reactos/lib/string/strtoul.c similarity index 91% rename from reactos/lib/ntdll/stdlib/strtoul.c rename to reactos/lib/string/strtoul.c index cf28c143b60..9b7c7122024 100644 --- a/reactos/lib/ntdll/stdlib/strtoul.c +++ b/reactos/lib/string/strtoul.c @@ -1,73 +1,73 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - - -/* - * Convert a string to an unsigned long integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - * - * @implemented - */ -unsigned long -strtoul(const char *nptr, char **endptr, int base) -{ - const char *s = nptr; - unsigned long acc; - int c; - unsigned long cutoff; - int neg = 0, any, cutlim; - - /* - * See strtol for comments as to the logic used. - */ - do { - c = *s++; - } while (isspace(c)); - if (c == '-') - { - neg = 1; - c = *s++; - } - else if (c == '+') - c = *s++; - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) - { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; - cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; - for (acc = 0, any = 0;; c = *s++) - { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : '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 = ULONG_MAX; - } - else if (neg) - acc = -acc; - if (endptr != 0) - *endptr = any ? (char *)s - 1 : (char *)nptr; - return acc; -} +#include +#include +#include + +/* + * Convert a string to an unsigned long integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + * + * @implemented + */ +unsigned long +strtoul(const char *nptr, char **endptr, int base) +{ + const char *s = nptr; + unsigned long acc; + int c; + unsigned long cutoff; + int neg = 0, any, cutlim; + + /* + * See strtol for comments as to the logic used. + */ + do { + c = *s++; + } while (isspace(c)); + if (c == '-') + { + neg = 1; + c = *s++; + } + else if (c == '+') + c = *s++; + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) + { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; + cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; + for (acc = 0, any = 0;; c = *s++) + { + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : '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 = ULONG_MAX; + } + else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = any ? (char *)s - 1 : (char *)nptr; + return acc; +} diff --git a/reactos/lib/ntdll/stdlib/wcstol.c b/reactos/lib/string/wcstol.c similarity index 93% rename from reactos/lib/ntdll/stdlib/wcstol.c rename to reactos/lib/string/wcstol.c index ae0cab5b81b..97fde78db19 100644 --- a/reactos/lib/ntdll/stdlib/wcstol.c +++ b/reactos/lib/string/wcstol.c @@ -1,90 +1,90 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - - -/* - * @implemented - */ -long -wcstol(const wchar_t *nptr, wchar_t **endptr, int base) -{ - const wchar_t *s = nptr; - unsigned long acc; - int c; - 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 - * 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; - - /* - * Compute the cutoff value between legal numbers and illegal - * numbers. That is the largest legal value, divided by the - * base. An input number that is greater than this value, if - * followed by a legal input character, is too big. One that - * is equal to this value may be valid or not; the limit - * between valid and invalid numbers is then based on the last - * 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 - * 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. - */ - cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; - 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 *)s - 1 : (wchar_t *)nptr; - return acc; -} +#include +#include +#include + +/* + * @implemented + */ +long +wcstol(const wchar_t *nptr, wchar_t **endptr, int base) +{ + const wchar_t *s = nptr; + unsigned long acc; + int c; + 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 + * 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; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * 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 + * 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. + */ + cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; + 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 *)s - 1 : (wchar_t *)nptr; + return acc; +} diff --git a/reactos/lib/ntdll/stdlib/wcstombs.c b/reactos/lib/string/wcstombs.c similarity index 53% rename from reactos/lib/ntdll/stdlib/wcstombs.c rename to reactos/lib/string/wcstombs.c index 8029c0b9305..2922a9cf861 100644 --- a/reactos/lib/ntdll/stdlib/wcstombs.c +++ b/reactos/lib/string/wcstombs.c @@ -1,46 +1,60 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: lib/ntdll/stdlib/wcstombs.c - * PURPOSE: converts a unicode string to a multi byte string - */ - -#include -#define NDEBUG -#include -#include -#include - -/* - * @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 *)wcstr, - Length * sizeof(WCHAR)); - - 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 */ +#include +#define NTOS_MODE_USER +#define _NTSYSTEM_ +#include +#include + +/* + * @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 *)wcstr, + Length * sizeof(WCHAR)); + + 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 */ diff --git a/reactos/lib/ntdll/stdlib/wcstoul.c b/reactos/lib/string/wcstoul.c similarity index 91% rename from reactos/lib/ntdll/stdlib/wcstoul.c rename to reactos/lib/string/wcstoul.c index e7c8ce7a417..a18f8d92ee7 100644 --- a/reactos/lib/ntdll/stdlib/wcstoul.c +++ b/reactos/lib/string/wcstoul.c @@ -1,72 +1,74 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * Convert a unicode string to an unsigned long integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - * - * @implemented - */ -unsigned long -wcstoul(const wchar_t *nptr, wchar_t **endptr, int base) -{ - const wchar_t *s = nptr; - unsigned long acc; - int c; - unsigned long cutoff; - int neg = 0, any, cutlim; - - /* - * See strtol for comments as to the logic used. - */ - 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; - cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; - cutlim = (unsigned long)ULONG_MAX % (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 = ULONG_MAX; - } - else if (neg) - acc = -acc; - if (endptr != 0) - *endptr = any ? (wchar_t *)s - 1 : (wchar_t *)nptr; - return acc; -} +#include +#include +#include + + +/* + * Convert a unicode string to an unsigned long integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + * + * @implemented + */ +unsigned long +wcstoul(const wchar_t *nptr, wchar_t **endptr, int base) +{ + const wchar_t *s = nptr; + unsigned long acc; + int c; + unsigned long cutoff; + int neg = 0, any, cutlim; + + /* + * See strtol for comments as to the logic used. + */ + 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; + cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; + cutlim = (unsigned long)ULONG_MAX % (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 = ULONG_MAX; + } + else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = any ? (wchar_t *)s - 1 : (wchar_t *)nptr; + return acc; +} diff --git a/reactos/lib/ntdll/stdlib/wtoi.c b/reactos/lib/string/wtoi.c similarity index 52% rename from reactos/lib/ntdll/stdlib/wtoi.c rename to reactos/lib/string/wtoi.c index 7368ef8623a..6cfec56abf2 100644 --- a/reactos/lib/ntdll/stdlib/wtoi.c +++ b/reactos/lib/string/wtoi.c @@ -1,11 +1,11 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -int -_wtoi(const wchar_t *str) -{ - return (int)wcstol(str, 0, 10); -} +#include +#include + +/* + * @implemented + */ +int +_wtoi(const wchar_t *str) +{ + return (int)wcstol(str, 0, 10); +} diff --git a/reactos/lib/ntdll/stdlib/wtoi64.c b/reactos/lib/string/wtoi64.c similarity index 66% rename from reactos/lib/ntdll/stdlib/wtoi64.c rename to reactos/lib/string/wtoi64.c index a27f9011032..3edd98b6a12 100644 --- a/reactos/lib/ntdll/stdlib/wtoi64.c +++ b/reactos/lib/string/wtoi64.c @@ -1,43 +1,37 @@ -/* $Id$ - * - * 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 - */ - -#include - -/* - * @implemented - */ -__int64 -_wtoi64 (const wchar_t *nptr) -{ - int c; - __int64 value; - int sign; - - while (iswctype((int)*nptr, _SPACE)) - ++nptr; - - c = (int)*nptr++; - sign = c; - if (c == L'-' || c == L'+') - c = (int)*nptr++; - - value = 0; - - while (iswctype(c, _DIGIT)) - { - value = 10 * value + (c - L'0'); - c = (int)*nptr++; - } - - if (sign == L'-') - return -value; - else - return value; -} - -/* EOF */ +#include +#include + + +/* + * @implemented + */ +__int64 +_wtoi64 (const wchar_t *nptr) +{ + int c; + __int64 value; + int sign; + + while (iswctype((int)*nptr, _SPACE)) + ++nptr; + + c = (int)*nptr++; + sign = c; + if (c == L'-' || c == L'+') + c = (int)*nptr++; + + value = 0; + + while (iswctype(c, _DIGIT)) + { + value = 10 * value + (c - L'0'); + c = (int)*nptr++; + } + + if (sign == L'-') + return -value; + else + return value; +} + +/* EOF */ diff --git a/reactos/lib/ntdll/stdlib/wtol.c b/reactos/lib/string/wtol.c similarity index 51% rename from reactos/lib/ntdll/stdlib/wtol.c rename to reactos/lib/string/wtol.c index 603dd831a02..9798cd6b4d0 100644 --- a/reactos/lib/ntdll/stdlib/wtol.c +++ b/reactos/lib/string/wtol.c @@ -1,11 +1,11 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -long -_wtol(const wchar_t *str) -{ - return wcstol(str, 0, 10); -} +#include +#include + +/* + * @implemented + */ +long +_wtol(const wchar_t *str) +{ + return wcstol(str, 0, 10); +} diff --git a/reactos/ntoskrnl/ntoskrnl.xml b/reactos/ntoskrnl/ntoskrnl.xml index 92bb1687fc1..9bbf8b0518d 100644 --- a/reactos/ntoskrnl/ntoskrnl.xml +++ b/reactos/ntoskrnl/ntoskrnl.xml @@ -321,7 +321,6 @@ purecall.c regio.c sprintf.c - stdlib.c strtok.c swprintf.c