https://git.reactos.org/?p=reactos.git;a=commitdiff;h=4aaf54e0a40e92c820f51…
commit 4aaf54e0a40e92c820f512a6d826acb88c41a47a
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Aug 23 19:10:11 2020 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Aug 23 19:11:40 2020 +0200
[CONUTILS] Use const string pointers for strings that are not modified by the
functions.
---
sdk/lib/conutils/outstream.c | 46 ++++++++++++++++++++++----------------------
sdk/lib/conutils/outstream.h | 26 +++++++++++++++----------
sdk/lib/conutils/pager.c | 6 +++---
sdk/lib/conutils/pager.h | 10 ++++++----
sdk/lib/conutils/stream.c | 4 ++--
sdk/lib/conutils/stream.h | 12 +++++++++---
sdk/lib/conutils/utils.c | 2 +-
7 files changed, 60 insertions(+), 46 deletions(-)
diff --git a/sdk/lib/conutils/outstream.c b/sdk/lib/conutils/outstream.c
index eea90a0cd06..6a45630a9bb 100644
--- a/sdk/lib/conutils/outstream.c
+++ b/sdk/lib/conutils/outstream.c
@@ -84,12 +84,12 @@ INT
__stdcall
ConWrite(
IN PCON_STREAM Stream,
- IN PTCHAR szStr,
- IN DWORD len)
+ IN PCTCH szStr,
+ IN DWORD len)
{
#ifndef USE_CRT
DWORD TotalLen = len, dwNumBytes = 0;
- PVOID p;
+ LPCVOID p;
/* If we do not write anything, just return */
if (!szStr || len == 0)
@@ -168,30 +168,30 @@ ConWrite(
{
/* Loop until we find a newline character */
p = szStr;
- while (len > 0 && *(PWCHAR)p != L'\n')
+ while (len > 0 && *(PCWCH)p != L'\n')
{
/* Advance one character */
- p = (PVOID)((PWCHAR)p + 1);
+ p = (LPCVOID)((PCWCH)p + 1);
--len;
}
/* Write everything up to \n */
- dwNumBytes = ((PWCHAR)p - (PWCHAR)szStr) * sizeof(WCHAR);
+ dwNumBytes = ((PCWCH)p - (PCWCH)szStr) * sizeof(WCHAR);
WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
/*
* If we hit a newline and the previous character is not a carriage-return,
* emit a carriage-return + newline sequence, otherwise just emit the
newline.
*/
- if (len > 0 && *(PWCHAR)p == L'\n')
+ if (len > 0 && *(PCWCH)p == L'\n')
{
- if (p == (PVOID)szStr || (p > (PVOID)szStr && *((PWCHAR)p - 1)
!= L'\r'))
+ if (p == (LPCVOID)szStr || (p > (LPCVOID)szStr && *((PCWCH)p -
1) != L'\r'))
WriteFile(Stream->hHandle, L"\r\n", 2 * sizeof(WCHAR),
&dwNumBytes, NULL);
else
WriteFile(Stream->hHandle, L"\n", sizeof(WCHAR),
&dwNumBytes, NULL);
/* Skip \n */
- p = (PVOID)((PWCHAR)p + 1);
+ p = (LPCVOID)((PCWCH)p + 1);
--len;
}
szStr = p;
@@ -252,30 +252,30 @@ ConWrite(
{
/* Loop until we find a newline character */
p = szStr;
- while (len > 0 && *(PCHAR)p != '\n')
+ while (len > 0 && *(PCCH)p != '\n')
{
/* Advance one character */
- p = (PVOID)((PCHAR)p + 1);
+ p = (LPCVOID)((PCCH)p + 1);
--len;
}
/* Write everything up to \n */
- dwNumBytes = ((PCHAR)p - (PCHAR)szStr) * sizeof(CHAR);
+ dwNumBytes = ((PCCH)p - (PCCH)szStr) * sizeof(CHAR);
WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
/*
* If we hit a newline and the previous character is not a carriage-return,
* emit a carriage-return + newline sequence, otherwise just emit the
newline.
*/
- if (len > 0 && *(PCHAR)p == '\n')
+ if (len > 0 && *(PCCH)p == '\n')
{
- if (p == (PVOID)szStr || (p > (PVOID)szStr && *((PCHAR)p - 1)
!= '\r'))
+ if (p == (LPCVOID)szStr || (p > (LPCVOID)szStr && *((PCCH)p -
1) != '\r'))
WriteFile(Stream->hHandle, "\r\n", 2, &dwNumBytes,
NULL);
else
WriteFile(Stream->hHandle, "\n", 1, &dwNumBytes,
NULL);
/* Skip \n */
- p = (PVOID)((PCHAR)p + 1);
+ p = (LPCVOID)((PCCH)p + 1);
--len;
}
szStr = p;
@@ -397,8 +397,8 @@ do { \
INT
ConStreamWrite(
IN PCON_STREAM Stream,
- IN PTCHAR szStr,
- IN DWORD len)
+ IN PCTCH szStr,
+ IN DWORD len)
{
INT Len;
CON_STREAM_WRITE2(Stream, szStr, len, Len);
@@ -426,7 +426,7 @@ ConStreamWrite(
INT
ConPuts(
IN PCON_STREAM Stream,
- IN LPWSTR szStr)
+ IN PCWSTR szStr)
{
INT Len;
@@ -465,7 +465,7 @@ ConPuts(
INT
ConPrintfV(
IN PCON_STREAM Stream,
- IN LPWSTR szStr,
+ IN PCWSTR szStr,
IN va_list args)
{
INT Len;
@@ -474,12 +474,12 @@ ConPrintfV(
// Len = vfwprintf(Stream->fStream, szStr, args); // vfprintf for direct ANSI
/*
- * Reuse szStr as the pointer to end-of-string, to compute
- * the string length instead of calling wcslen().
+ * Re-use szStr as the pointer to end-of-string, so as
+ * to compute the string length instead of calling wcslen().
*/
// StringCchVPrintfW(bufSrc, ARRAYSIZE(bufSrc), szStr, args);
// Len = wcslen(bufSrc);
- StringCchVPrintfExW(bufSrc, ARRAYSIZE(bufSrc), &szStr, NULL, 0, szStr, args);
+ StringCchVPrintfExW(bufSrc, ARRAYSIZE(bufSrc), (PWSTR*)&szStr, NULL, 0, szStr,
args);
Len = szStr - bufSrc;
CON_STREAM_WRITE2(Stream, bufSrc, Len, Len);
@@ -519,7 +519,7 @@ INT
__cdecl
ConPrintf(
IN PCON_STREAM Stream,
- IN LPWSTR szStr,
+ IN PCWSTR szStr,
...)
{
INT Len;
diff --git a/sdk/lib/conutils/outstream.h b/sdk/lib/conutils/outstream.h
index 47a3e06ae40..ea198299569 100644
--- a/sdk/lib/conutils/outstream.h
+++ b/sdk/lib/conutils/outstream.h
@@ -39,40 +39,46 @@ extern "C" {
// Shadow type, implementation-specific
typedef struct _CON_STREAM CON_STREAM, *PCON_STREAM;
-// typedef INT (__stdcall *CON_READ_FUNC)(IN PCON_STREAM, IN PTCHAR, IN DWORD);
- // Stream, szStr, len
-typedef INT (__stdcall *CON_WRITE_FUNC)(IN PCON_STREAM, IN PTCHAR, IN DWORD);
+// typedef INT (__stdcall *CON_READ_FUNC)(
+ // IN PCON_STREAM Stream,
+ // OUT PTCHAR szStr,
+ // IN OUT PDWORD len);
+
+typedef INT (__stdcall *CON_WRITE_FUNC)(
+ IN PCON_STREAM Stream,
+ IN PCTCH szStr,
+ IN DWORD len);
INT
__stdcall
ConWrite(
IN PCON_STREAM Stream,
- IN PTCHAR szStr,
- IN DWORD len);
+ IN PCTCH szStr,
+ IN DWORD len);
INT
ConStreamWrite(
IN PCON_STREAM Stream,
- IN PTCHAR szStr,
- IN DWORD len);
+ IN PCTCH szStr,
+ IN DWORD len);
INT
ConPuts(
IN PCON_STREAM Stream,
- IN LPWSTR szStr);
+ IN PCWSTR szStr);
INT
ConPrintfV(
IN PCON_STREAM Stream,
- IN LPWSTR szStr,
+ IN PCWSTR szStr,
IN va_list args);
INT
__cdecl
ConPrintf(
IN PCON_STREAM Stream,
- IN LPWSTR szStr,
+ IN PCWSTR szStr,
...);
INT
diff --git a/sdk/lib/conutils/pager.c b/sdk/lib/conutils/pager.c
index 27cbd725008..834590665f9 100644
--- a/sdk/lib/conutils/pager.c
+++ b/sdk/lib/conutils/pager.c
@@ -39,7 +39,7 @@ ConWritePaging(
IN PCON_PAGER Pager,
IN PAGE_PROMPT PagePrompt,
IN BOOL StartPaging,
- IN PTCHAR szStr,
+ IN PCTCH szStr,
IN DWORD len)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
@@ -121,7 +121,7 @@ ConPutsPaging(
IN PCON_PAGER Pager,
IN PAGE_PROMPT PagePrompt,
IN BOOL StartPaging,
- IN LPTSTR szStr)
+ IN PCTSTR szStr)
{
DWORD len;
@@ -142,7 +142,7 @@ ConResPagingEx(
IN UINT uID)
{
INT Len;
- PWCHAR szStr = NULL;
+ PCWSTR szStr = NULL;
Len = K32LoadStringW(hInstance, uID, (PWSTR)&szStr, 0);
if (szStr && Len)
diff --git a/sdk/lib/conutils/pager.h b/sdk/lib/conutils/pager.h
index 27737224a06..31a3ba86970 100644
--- a/sdk/lib/conutils/pager.h
+++ b/sdk/lib/conutils/pager.h
@@ -50,15 +50,17 @@ do { \
} while (0)
- // Pager, Done, Total
-typedef BOOL (__stdcall *PAGE_PROMPT)(IN PCON_PAGER, IN DWORD, IN DWORD);
+typedef BOOL (__stdcall *PAGE_PROMPT)(
+ IN PCON_PAGER Pager,
+ IN DWORD Done,
+ IN DWORD Total);
BOOL
ConWritePaging(
IN PCON_PAGER Pager,
IN PAGE_PROMPT PagePrompt,
IN BOOL StartPaging,
- IN PTCHAR szStr,
+ IN PCTCH szStr,
IN DWORD len);
BOOL
@@ -66,7 +68,7 @@ ConPutsPaging(
IN PCON_PAGER Pager,
IN PAGE_PROMPT PagePrompt,
IN BOOL StartPaging,
- IN LPTSTR szStr);
+ IN PCTSTR szStr);
BOOL
ConResPagingEx(
diff --git a/sdk/lib/conutils/stream.c b/sdk/lib/conutils/stream.c
index 7246453df45..244d97f07c0 100644
--- a/sdk/lib/conutils/stream.c
+++ b/sdk/lib/conutils/stream.c
@@ -232,8 +232,8 @@ ConStreamSetCacheCodePage(
*/
Mode = Stream->Mode;
CON_STREAM_SET_MODE(Stream, Mode, CacheCodePage);
- return TRUE;
#endif
+ return TRUE;
}
HANDLE
@@ -277,7 +277,7 @@ ConStreamSetOSHandle(
if (!Stream->fStream)
return FALSE;
- int fdOut = _open_osfhandle(Handle, _O_TEXT /* FIXME! */);
+ int fdOut = _open_osfhandle((intptr_t)Handle, _O_TEXT /* FIXME! */);
FILE* fpOut = _fdopen(fdOut, "w");
*Stream->fStream = *fpOut;
/// setvbuf(Stream->fStream, NULL, _IONBF, 0);
diff --git a/sdk/lib/conutils/stream.h b/sdk/lib/conutils/stream.h
index 031ae56d305..17e8b0a7431 100644
--- a/sdk/lib/conutils/stream.h
+++ b/sdk/lib/conutils/stream.h
@@ -55,9 +55,15 @@ typedef enum _CON_STREAM_MODE
// Shadow type, implementation-specific
typedef struct _CON_STREAM CON_STREAM, *PCON_STREAM;
-// typedef INT (__stdcall *CON_READ_FUNC)(IN PCON_STREAM, IN PTCHAR, IN DWORD);
- // Stream, szStr, len
-typedef INT (__stdcall *CON_WRITE_FUNC)(IN PCON_STREAM, IN PTCHAR, IN DWORD);
+// typedef INT (__stdcall *CON_READ_FUNC)(
+ // IN PCON_STREAM Stream,
+ // OUT PTCHAR szStr,
+ // IN OUT PDWORD len);
+
+typedef INT (__stdcall *CON_WRITE_FUNC)(
+ IN PCON_STREAM Stream,
+ IN PCTCH szStr,
+ IN DWORD len);
/*
* Standard console streams, initialized by
diff --git a/sdk/lib/conutils/utils.c b/sdk/lib/conutils/utils.c
index 8462be06f3b..15c7ac028f4 100644
--- a/sdk/lib/conutils/utils.c
+++ b/sdk/lib/conutils/utils.c
@@ -133,7 +133,7 @@ K32LoadStringExW(
/*
* If nBufferMax == 0, then return a read-only pointer
* to the resource itself in lpBuffer it is assumed that
- * lpBuffer is actually a (LPWSTR *).
+ * lpBuffer is actually a (LPWSTR*).
*/
if (nBufferMax == 0)
{