Jacek Caban : gdi32: Avoid using CRT wide char functions in ntgdi functions.
Alexandre Julliard
julliard at winehq.org
Wed Sep 29 15:54:10 CDT 2021
Module: wine
Branch: master
Commit: ca7998faff3e88dc9451413be3351da4b861d5a6
URL: https://source.winehq.org/git/wine.git/?a=commit;h=ca7998faff3e88dc9451413be3351da4b861d5a6
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Sep 29 14:08:14 2021 +0200
gdi32: Avoid using CRT wide char functions in ntgdi functions.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/gdi32/win32u_private.h | 90 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
diff --git a/dlls/gdi32/win32u_private.h b/dlls/gdi32/win32u_private.h
index cafd06b03f1..8bc40b37abf 100644
--- a/dlls/gdi32/win32u_private.h
+++ b/dlls/gdi32/win32u_private.h
@@ -38,4 +38,94 @@ struct user_callbacks
HWND (WINAPI *pWindowFromDC)( HDC );
};
+static inline WCHAR *win32u_wcsrchr( const WCHAR *str, WCHAR ch )
+{
+ WCHAR *ret = NULL;
+ do { if (*str == ch) ret = (WCHAR *)(ULONG_PTR)str; } while (*str++);
+ return ret;
+}
+
+static inline WCHAR win32u_towupper( WCHAR ch )
+{
+ return RtlUpcaseUnicodeChar( ch );
+}
+
+static inline WCHAR *win32u_wcschr( const WCHAR *str, WCHAR ch )
+{
+ do { if (*str == ch) return (WCHAR *)(ULONG_PTR)str; } while (*str++);
+ return NULL;
+}
+
+static inline int win32u_wcsicmp( const WCHAR *str1, const WCHAR *str2 )
+{
+ int ret;
+ for (;;)
+ {
+ if ((ret = win32u_towupper( *str1 ) - win32u_towupper( *str2 )) || !*str1) return ret;
+ str1++;
+ str2++;
+ }
+}
+
+static inline int win32u_wcscmp( const WCHAR *str1, const WCHAR *str2 )
+{
+ while (*str1 && (*str1 == *str2)) { str1++; str2++; }
+ return *str1 - *str2;
+}
+
+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;
+}
+
+#define towupper(c) win32u_towupper(c)
+#define wcschr(s,c) win32u_wcschr(s,c)
+#define wcscmp(s1,s2) win32u_wcscmp(s1,s2)
+#define wcsicmp(s1,s2) win32u_wcsicmp(s1,s2)
+#define wcsrchr(s,c) win32u_wcsrchr(s,c)
+#define wcstol(s,e,b) win32u_wcstol(s,e,b)
+
#endif /* __WINE_WIN32U_PRIVATE */
More information about the wine-cvs
mailing list