https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f870bbe1d48efa423830c2507979de787975b981

commit f870bbe1d48efa423830c2507979de787975b981
Author:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
AuthorDate: Thu May 18 12:12:39 2023 +0200
Commit:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
CommitDate: Thu May 18 12:12:44 2023 +0200

    [ATTRIB] Simplify the ErrorMessage() function.
    
    And send the errors to the error stream.
---
 base/applications/cmdutils/attrib/attrib.c | 43 ++++++++++++------------------
 1 file changed, 17 insertions(+), 26 deletions(-)

diff --git a/base/applications/cmdutils/attrib/attrib.c 
b/base/applications/cmdutils/attrib/attrib.c
index ff6185a84ea..9d22255d8eb 100644
--- a/base/applications/cmdutils/attrib/attrib.c
+++ b/base/applications/cmdutils/attrib/attrib.c
@@ -49,41 +49,32 @@ CON_SCREEN StdOutScreen = INIT_CON_SCREEN(StdOut);
 static
 VOID
 ErrorMessage(
-    DWORD dwErrorCode,
-    LPWSTR szFormat,
+    _In_ DWORD dwErrorCode,
+    _In_opt_ PCWSTR pszMsg,
     ...)
 {
-    WCHAR szMsg[RC_STRING_MAX_SIZE];
-    WCHAR  szMessage[1024];
-    LPWSTR szError;
+    INT Len;
     va_list arg_ptr;
 
     if (dwErrorCode == ERROR_SUCCESS)
         return;
 
-    if (szFormat)
-    {
-        va_start(arg_ptr, szFormat);
-        vswprintf(szMessage, szFormat, arg_ptr);
-        va_end(arg_ptr);
-    }
-
-    if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | 
FORMAT_MESSAGE_ALLOCATE_BUFFER,
-                       NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, 
SUBLANG_DEFAULT),
-                       (LPWSTR)&szError, 0, NULL))
-    {
-        ConPrintf(StdOut, L"%s %s\n", szError, szMessage);
-        if (szError)
-            LocalFree(szError);
-        return;
-    }
+    va_start(arg_ptr, pszMsg);
+    Len = ConMsgPrintfV(StdErr,
+                        FORMAT_MESSAGE_FROM_SYSTEM,
+                        NULL,
+                        dwErrorCode,
+                        LANG_USER_DEFAULT,
+                        &arg_ptr);
+    va_end(arg_ptr);
 
     /* Fall back just in case the error is not defined */
-    LoadStringW(GetModuleHandle(NULL), STRING_CONSOLE_ERROR, szMsg, 
ARRAYSIZE(szMsg));
-    if (szFormat)
-        ConPrintf(StdOut, L"%s -- %s\n", szMsg, szMessage);
-    else
-        ConPrintf(StdOut, L"%s\n", szMsg);
+    if (Len <= 0)
+        ConResPrintf(StdErr, STRING_CONSOLE_ERROR, dwErrorCode);
+
+    /* Display the extra optional message if necessary */
+    if (pszMsg)
+        ConPrintf(StdErr, L"  %s\n", pszMsg);
 }
 
 /* Returns TRUE if anything is printed, FALSE otherwise */

Reply via email to