Commit b49dd456 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

include: Provide iswspace, wcstol and wcstoul in unixlib.h.

parent f30332fe
...@@ -525,99 +525,6 @@ static inline WCHAR win32u_towupper( WCHAR ch ) ...@@ -525,99 +525,6 @@ static inline WCHAR win32u_towupper( WCHAR ch )
return RtlUpcaseUnicodeChar( ch ); return RtlUpcaseUnicodeChar( ch );
} }
static inline LONG win32u_wcstol( LPCWSTR s, LPWSTR *end, INT base )
{
BOOL negative = FALSE, empty = TRUE;
LONG ret = 0;
if (base < 0 || base == 1 || base > 36) return 0;
if (end) *end = (WCHAR *)s;
while (*s == ' ' || *s == '\t') s++;
if (*s == '-')
{
negative = TRUE;
s++;
}
else if (*s == '+') s++;
if ((base == 0 || base == 16) && s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
{
base = 16;
s += 2;
}
if (base == 0) base = s[0] != '0' ? 10 : 8;
while (*s)
{
int v;
if ('0' <= *s && *s <= '9') v = *s - '0';
else if ('A' <= *s && *s <= 'Z') v = *s - 'A' + 10;
else if ('a' <= *s && *s <= 'z') v = *s - 'a' + 10;
else break;
if (v >= base) break;
if (negative) v = -v;
s++;
empty = FALSE;
if (!negative && (ret > MAXLONG / base || ret * base > MAXLONG - v))
ret = MAXLONG;
else if (negative && (ret < (LONG)MINLONG / base || ret * base < (LONG)(MINLONG - v)))
ret = MINLONG;
else
ret = ret * base + v;
}
if (end && !empty) *end = (WCHAR *)s;
return ret;
}
static inline ULONG win32u_wcstoul( const WCHAR *s, WCHAR **end, int base )
{
BOOL negative = FALSE, empty = TRUE;
ULONG ret = 0;
if (base < 0 || base == 1 || base > 36) return 0;
if (end) *end = (WCHAR *)s;
while (*s == ' ' || *s == '\t') s++;
if (*s == '-')
{
negative = TRUE;
s++;
}
else if (*s == '+') s++;
if ((base == 0 || base == 16) && s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
{
base = 16;
s += 2;
}
if (base == 0) base = s[0] != '0' ? 10 : 8;
while (*s)
{
int v;
if ('0' <= *s && *s <= '9') v = *s - '0';
else if ('A' <= *s && *s <= 'Z') v = *s - 'A' + 10;
else if ('a' <= *s && *s <= 'z') v = *s - 'a' + 10;
else break;
if (v >= base) break;
s++;
empty = FALSE;
if (ret > MAXDWORD / base || ret * base > MAXDWORD - v)
ret = MAXDWORD;
else
ret = ret * base + v;
}
if (end && !empty) *end = (WCHAR *)s;
return negative ? -ret : ret;
}
extern CPTABLEINFO ansi_cp DECLSPEC_HIDDEN; extern CPTABLEINFO ansi_cp DECLSPEC_HIDDEN;
DWORD win32u_mbtowc( CPTABLEINFO *info, WCHAR *dst, DWORD dstlen, const char *src, DWORD win32u_mbtowc( CPTABLEINFO *info, WCHAR *dst, DWORD dstlen, const char *src,
...@@ -643,8 +550,6 @@ static inline WCHAR *towstr( const char *str ) ...@@ -643,8 +550,6 @@ static inline WCHAR *towstr( const char *str )
#define towupper(c) win32u_towupper(c) #define towupper(c) win32u_towupper(c)
#define wcsdup(s) win32u_wcsdup(s) #define wcsdup(s) win32u_wcsdup(s)
#define wcstol(s,e,b) win32u_wcstol(s,e,b)
#define wcstoul(s,e,b) win32u_wcstoul(s,e,b)
static inline void ascii_to_unicode( WCHAR *dst, const char *src, size_t len ) static inline void ascii_to_unicode( WCHAR *dst, const char *src, size_t len )
{ {
......
...@@ -928,54 +928,4 @@ static inline UINT asciiz_to_unicode( WCHAR *dst, const char *src ) ...@@ -928,54 +928,4 @@ static inline UINT asciiz_to_unicode( WCHAR *dst, const char *src )
return (p - dst) * sizeof(WCHAR); return (p - dst) * sizeof(WCHAR);
} }
static inline LONG x11drv_wcstol( LPCWSTR s, LPWSTR *end, INT base )
{
BOOL negative = FALSE, empty = TRUE;
LONG ret = 0;
if (base < 0 || base == 1 || base > 36) return 0;
if (end) *end = (WCHAR *)s;
while (*s == ' ' || *s == '\t') s++;
if (*s == '-')
{
negative = TRUE;
s++;
}
else if (*s == '+') s++;
if ((base == 0 || base == 16) && s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
{
base = 16;
s += 2;
}
if (base == 0) base = s[0] != '0' ? 10 : 8;
while (*s)
{
int v;
if ('0' <= *s && *s <= '9') v = *s - '0';
else if ('A' <= *s && *s <= 'Z') v = *s - 'A' + 10;
else if ('a' <= *s && *s <= 'z') v = *s - 'a' + 10;
else break;
if (v >= base) break;
if (negative) v = -v;
s++;
empty = FALSE;
if (!negative && (ret > MAXLONG / base || ret * base > MAXLONG - v))
ret = MAXLONG;
else if (negative && (ret < (LONG)MINLONG / base || ret * base < (LONG)(MINLONG - v)))
ret = MINLONG;
else
ret = ret * base + v;
}
if (end && !empty) *end = (WCHAR *)s;
return ret;
}
#define wcstol x11drv_wcstol
#endif /* __WINE_X11DRV_H */ #endif /* __WINE_X11DRV_H */
...@@ -84,6 +84,11 @@ NTSTATUS WINAPI KeUserModeCallback( ULONG id, const void *args, ULONG len, void ...@@ -84,6 +84,11 @@ NTSTATUS WINAPI KeUserModeCallback( ULONG id, const void *args, ULONG len, void
/* wide char string functions */ /* wide char string functions */
static inline int ntdll_iswspace( WCHAR wc )
{
return ('\t' <= wc && wc <= '\r') || wc == ' ' || wc == 0xa0;
}
static inline size_t ntdll_wcslen( const WCHAR *str ) static inline size_t ntdll_wcslen( const WCHAR *str )
{ {
const WCHAR *s = str; const WCHAR *s = str;
...@@ -150,6 +155,100 @@ static inline SIZE_T ntdll_wcscspn( const WCHAR *str, const WCHAR *reject ) ...@@ -150,6 +155,100 @@ static inline SIZE_T ntdll_wcscspn( const WCHAR *str, const WCHAR *reject )
return ptr - str; return ptr - str;
} }
static inline LONG ntdll_wcstol( const WCHAR *s, WCHAR **end, int base )
{
BOOL negative = FALSE, empty = TRUE;
LONG ret = 0;
if (base < 0 || base == 1 || base > 36) return 0;
if (end) *end = (WCHAR *)s;
while (ntdll_iswspace(*s)) s++;
if (*s == '-')
{
negative = TRUE;
s++;
}
else if (*s == '+') s++;
if ((base == 0 || base == 16) && s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
{
base = 16;
s += 2;
}
if (base == 0) base = s[0] != '0' ? 10 : 8;
while (*s)
{
int v;
if ('0' <= *s && *s <= '9') v = *s - '0';
else if ('A' <= *s && *s <= 'Z') v = *s - 'A' + 10;
else if ('a' <= *s && *s <= 'z') v = *s - 'a' + 10;
else break;
if (v >= base) break;
if (negative) v = -v;
s++;
empty = FALSE;
if (!negative && (ret > MAXLONG / base || ret * base > MAXLONG - v))
ret = MAXLONG;
else if (negative && (ret < (LONG)MINLONG / base || ret * base < (LONG)(MINLONG - v)))
ret = MINLONG;
else
ret = ret * base + v;
}
if (end && !empty) *end = (WCHAR *)s;
return ret;
}
static inline ULONG ntdll_wcstoul( const WCHAR *s, WCHAR **end, int base )
{
BOOL negative = FALSE, empty = TRUE;
ULONG ret = 0;
if (base < 0 || base == 1 || base > 36) return 0;
if (end) *end = (WCHAR *)s;
while (ntdll_iswspace(*s)) s++;
if (*s == '-')
{
negative = TRUE;
s++;
}
else if (*s == '+') s++;
if ((base == 0 || base == 16) && s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
{
base = 16;
s += 2;
}
if (base == 0) base = s[0] != '0' ? 10 : 8;
while (*s)
{
int v;
if ('0' <= *s && *s <= '9') v = *s - '0';
else if ('A' <= *s && *s <= 'Z') v = *s - 'A' + 10;
else if ('a' <= *s && *s <= 'z') v = *s - 'a' + 10;
else break;
if (v >= base) break;
s++;
empty = FALSE;
if (ret > MAXDWORD / base || ret * base > MAXDWORD - v)
ret = MAXDWORD;
else
ret = ret * base + v;
}
if (end && !empty) *end = (WCHAR *)s;
return negative ? -ret : ret;
}
#define iswspace(ch) ntdll_iswspace(ch)
#define wcslen(str) ntdll_wcslen(str) #define wcslen(str) ntdll_wcslen(str)
#define wcscpy(dst,src) ntdll_wcscpy(dst,src) #define wcscpy(dst,src) ntdll_wcscpy(dst,src)
#define wcscat(dst,src) ntdll_wcscat(dst,src) #define wcscat(dst,src) ntdll_wcscat(dst,src)
...@@ -162,6 +261,8 @@ static inline SIZE_T ntdll_wcscspn( const WCHAR *str, const WCHAR *reject ) ...@@ -162,6 +261,8 @@ static inline SIZE_T ntdll_wcscspn( const WCHAR *str, const WCHAR *reject )
#define wcscspn(str,rej) ntdll_wcscspn(str,rej) #define wcscspn(str,rej) ntdll_wcscspn(str,rej)
#define wcsicmp(s1, s2) ntdll_wcsicmp(s1,s2) #define wcsicmp(s1, s2) ntdll_wcsicmp(s1,s2)
#define wcsnicmp(s1, s2,n) ntdll_wcsnicmp(s1,s2,n) #define wcsnicmp(s1, s2,n) ntdll_wcsnicmp(s1,s2,n)
#define wcstol(str,e,b) ntdll_wcstol(str,e,b)
#define wcstoul(str,e,b) ntdll_wcstoul(str,e,b)
#endif /* WINE_UNIX_LIB */ #endif /* WINE_UNIX_LIB */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment