[CONUTILS]: Fix build:
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Fri, 7 Oct 2016 21:57:59 +0000 (21:57 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Fri, 7 Oct 2016 21:57:59 +0000 (21:57 +0000)
- Commit the *Puts functions.
- Fix __stdcall that needs to be read __cdecl for variadic functions.

svn path=/trunk/; revision=72931

reactos/sdk/lib/conutils/conutils.c
reactos/sdk/lib/conutils/conutils.h

index a35a99d..226b998 100644 (file)
@@ -531,6 +531,22 @@ ConWrite(
 #endif /* defined(USE_CRT) */
 }
 
+INT
+ConPuts(
+    IN PCON_STREAM Stream,
+    IN LPWSTR szStr)
+{
+    INT Len;
+
+    Len = Stream->WriteFunc(Stream, szStr, wcslen(szStr));
+
+    /* Fixup returned length in case of errors */
+    if (Len < 0)
+        Len = 0;
+
+    return Len;
+}
+
 INT
 ConPrintfV(
     IN PCON_STREAM Stream,
@@ -538,17 +554,17 @@ ConPrintfV(
     IN va_list args) // arg_ptr
 {
     INT Len;
-    WCHAR bufFormatted[CON_RC_STRING_MAX_SIZE];
+    WCHAR bufSrc[CON_RC_STRING_MAX_SIZE];
 
 #if 1 ///////////////////////////////////////////////////////////////////////  0
     PWSTR pEnd;
-    StringCchVPrintfExW(bufFormatted, ARRAYSIZE(bufFormatted), &pEnd, NULL, 0, szStr, args);
-    Len = pEnd - bufFormatted;
+    StringCchVPrintfExW(bufSrc, ARRAYSIZE(bufSrc), &pEnd, NULL, 0, szStr, args);
+    Len = pEnd - bufSrc;
 #else
-    StringCchVPrintfW(bufFormatted, ARRAYSIZE(bufFormatted), szStr, args);
-    Len = wcslen(bufFormatted);
+    StringCchVPrintfW(bufSrc, ARRAYSIZE(bufSrc), szStr, args);
+    Len = wcslen(bufSrc);
 #endif
-    Len = Stream->WriteFunc(Stream, bufFormatted, Len);
+    Len = Stream->WriteFunc(Stream, bufSrc, Len);
 
     /* Fixup returned length in case of errors */
     if (Len < 0)
@@ -558,6 +574,7 @@ ConPrintfV(
 }
 
 INT
+__cdecl
 ConPrintf(
     IN PCON_STREAM Stream,
     IN LPWSTR szStr,
@@ -579,6 +596,33 @@ ConPrintf(
     return Len;
 }
 
+INT
+ConResPuts(
+    IN PCON_STREAM Stream,
+    IN UINT uID)
+{
+    INT Len;
+#if 0
+    WCHAR bufSrc[CON_RC_STRING_MAX_SIZE];
+
+    // NOTE: We may use the special behaviour where nBufMaxSize == 0
+    Len = K32LoadStringW(GetModuleHandleW(NULL), uID, bufSrc, ARRAYSIZE(bufSrc));
+    if (Len)
+        Len = ConPuts(Stream, bufSrc);
+#else
+    PWCHAR szStr = NULL;
+    Len = K32LoadStringW(GetModuleHandleW(NULL), uID, (PWSTR)&szStr, 0);
+    if (Len)
+        Len = Stream->WriteFunc(Stream, szStr, Len);
+
+    /* Fixup returned length in case of errors */
+    if (Len < 0)
+        Len = 0;
+#endif
+
+    return Len;
+}
+
 INT
 ConResPrintfV(
     IN PCON_STREAM Stream,
@@ -597,6 +641,7 @@ ConResPrintfV(
 }
 
 INT
+__cdecl
 ConResPrintf(
     IN PCON_STREAM Stream,
     IN UINT uID,
@@ -612,6 +657,71 @@ ConResPrintf(
     return Len;
 }
 
+INT
+ConMsgPuts(
+    IN PCON_STREAM Stream,
+    IN DWORD   dwFlags,
+    IN LPCVOID lpSource OPTIONAL,
+    IN DWORD   dwMessageId,
+    IN DWORD   dwLanguageId)
+{
+    INT Len;
+    DWORD dwLength  = 0;
+    LPWSTR lpMsgBuf = NULL;
+
+    /*
+     * Sanitize dwFlags. This version always ignore explicitely the inserts
+     * as we emulate the behaviour of the *puts function.
+     */
+    dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer.
+    dwFlags |= FORMAT_MESSAGE_IGNORE_INSERTS;  // Ignore inserts for FormatMessage.
+    dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY;
+
+    dwFlags |= FORMAT_MESSAGE_MAX_WIDTH_MASK;
+
+    /*
+     * Retrieve the message string without appending extra newlines.
+     * Wrap in SEH to protect from invalid string parameters.
+     */
+    _SEH2_TRY
+    {
+        dwLength = FormatMessageW(dwFlags,
+                                  lpSource,
+                                  dwMessageId,
+                                  dwLanguageId,
+                                  (LPWSTR)&lpMsgBuf,
+                                  0, NULL);
+    }
+    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+    {
+    }
+    _SEH2_END;
+
+    Len = (INT)dwLength;
+
+    if (!lpMsgBuf)
+    {
+        // ASSERT(dwLength == 0);
+    }
+    else
+    {
+        // ASSERT(dwLength != 0);
+
+        /* lpMsgBuf is NULL-terminated by FormatMessage */
+        // Len = ConPuts(Stream, lpMsgBuf);
+        Len = Stream->WriteFunc(Stream, lpMsgBuf, dwLength);
+
+        /* Fixup returned length in case of errors */
+        if (Len < 0)
+            Len = 0;
+
+        /* Free the buffer allocated by FormatMessage */
+        LocalFree(lpMsgBuf);
+    }
+
+    return Len;
+}
+
 INT
 ConMsgPrintf2V(
     IN PCON_STREAM Stream,
@@ -739,6 +849,7 @@ ConMsgPrintfV(
 }
 
 INT
+__cdecl
 ConMsgPrintf(
     IN PCON_STREAM Stream,
     IN DWORD   dwFlags,
index 7534b60..2f1d6b4 100644 (file)
@@ -170,6 +170,11 @@ ConWrite(
     IN PTCHAR szStr,
     IN DWORD len);
 
+INT
+ConPuts(
+    IN PCON_STREAM Stream,
+    IN LPWSTR szStr);
+
 INT
 ConPrintfV(
     IN PCON_STREAM Stream,
@@ -177,11 +182,17 @@ ConPrintfV(
     IN va_list args); // arg_ptr
 
 INT
+__cdecl
 ConPrintf(
     IN PCON_STREAM Stream,
     IN LPWSTR szStr,
     ...);
 
+INT
+ConResPuts(
+    IN PCON_STREAM Stream,
+    IN UINT uID);
+
 INT
 ConResPrintfV(
     IN PCON_STREAM Stream,
@@ -189,11 +200,20 @@ ConResPrintfV(
     IN va_list args); // arg_ptr
 
 INT
+__cdecl
 ConResPrintf(
     IN PCON_STREAM Stream,
     IN UINT uID,
     ...);
 
+INT
+ConMsgPuts(
+    IN PCON_STREAM Stream,
+    IN DWORD   dwFlags,
+    IN LPCVOID lpSource OPTIONAL,
+    IN DWORD   dwMessageId,
+    IN DWORD   dwLanguageId);
+
 INT
 ConMsgPrintf2V(
     IN PCON_STREAM Stream,
@@ -213,6 +233,7 @@ ConMsgPrintfV(
     IN va_list args); // arg_ptr
 
 INT
+__cdecl
 ConMsgPrintf(
     IN PCON_STREAM Stream,
     IN DWORD   dwFlags,