msvcrt: Implement _wperror

Hugh McMaster hugh.mcmaster at outlook.com
Tue Jun 21 03:09:30 CDT 2016


Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
 dlls/msvcrt/errno.c     | 35 +++++++++++++++++++++++++++++++++++
 dlls/msvcrt/msvcrt.spec |  2 +-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/dlls/msvcrt/errno.c b/dlls/msvcrt/errno.c
index 75e211e..a357d1a 100644
--- a/dlls/msvcrt/errno.c
+++ b/dlls/msvcrt/errno.c
@@ -344,6 +344,41 @@ void CDECL MSVCRT_perror(const char* str)
 }
 
 /*********************************************************************
+ *		_wperror (MSVCRT.@)
+ */
+void CDECL MSVCRT__wperror(const MSVCRT_wchar_t* str)
+{
+    int err, size, len;
+    static const WCHAR colon_spaceW[] = {':',' ',0};
+    static const WCHAR newlineW[] = {'\n',0};
+    MSVCRT_wchar_t *buffer = NULL;
+
+    err = *MSVCRT__errno();
+    if (err < 0 || err > MSVCRT__sys_nerr) err = MSVCRT__sys_nerr;
+
+    size = MultiByteToWideChar(CP_ACP, 0, MSVCRT__sys_errlist[err], -1, NULL, 0) + 1 /* add \n */;
+
+    if (str && *str)
+        size += lstrlenW(str) + 2; /* add str length, colon and space */
+
+    buffer = MSVCRT_malloc(size * sizeof(MSVCRT_wchar_t));
+    if (!buffer) return;
+
+    if (str && *str)
+    {
+        lstrcpyW(buffer, str);
+        lstrcatW(buffer, colon_spaceW);
+    }
+    else buffer[0] = 0;
+
+    len = lstrlenW(buffer);
+    MultiByteToWideChar(CP_ACP, 0, MSVCRT__sys_errlist[err], -1, buffer + len, size - len);
+    lstrcatW(buffer, newlineW);
+    MSVCRT__write(2, buffer, lstrlenW(buffer) * sizeof(MSVCRT_wchar_t));
+    MSVCRT_free(buffer);
+}
+
+/*********************************************************************
  *		_wcserror_s (MSVCRT.@)
  */
 int CDECL MSVCRT__wcserror_s(MSVCRT_wchar_t* buffer, MSVCRT_size_t nc, int err)
diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index 37107d5..274d2e7 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -1184,7 +1184,7 @@
 @ cdecl _wmktemp_s(wstr long) MSVCRT__wmktemp_s
 @ varargs _wopen(wstr long) MSVCRT__wopen
 # stub _woutput_s
-@ stub _wperror(wstr)
+@ cdecl _wperror(wstr) MSVCRT__wperror
 @ extern _wpgmptr MSVCRT__wpgmptr
 @ cdecl _wpopen (wstr wstr) MSVCRT__wpopen
 # stub _wprintf_l(wstr ptr)
-- 
2.7.4




More information about the wine-patches mailing list