From 43b5723c7881cff929df4f3d6ccc4088dd6ba302 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 9 Jan 2025 23:22:27 +0800 Subject: [PATCH] fix pipe api --- src/tbox/platform/stdfile.c | 13 ++++++++----- src/tbox/platform/windows/interface/kernel32.c | 2 +- src/tbox/platform/windows/interface/kernel32.h | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/tbox/platform/stdfile.c b/src/tbox/platform/stdfile.c index 09dd3200d..949b4008d 100644 --- a/src/tbox/platform/stdfile.c +++ b/src/tbox/platform/stdfile.c @@ -137,16 +137,19 @@ tb_bool_t tb_stdfile_readable(tb_stdfile_ref_t self) #endif HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); - if (tb_kernel32()->PeekConsoleInputW && tb_kernel32()->PeekNamedPipeW) + DWORD fileType = GetFileType(hStdin); + if (fileType == FILE_TYPE_PIPE) { - DWORD fileType = GetFileType(hStdin); - if (fileType == FILE_TYPE_PIPE) + if (tb_kernel32()->PeekNamedPipe) { DWORD bytesAvailable = 0; - BOOL ok = tb_kernel32()->PeekNamedPipeW(hStdin, NULL, NULL, NULL, &bytesAvailable, tb_null); + BOOL ok = tb_kernel32()->PeekNamedPipe(hStdin, NULL, NULL, NULL, &bytesAvailable, tb_null); return ok && bytesAvailable; } - else + } + else + { + if (tb_kernel32()->PeekConsoleInputW) { // we need to ignore left 0x0d charactor, so bytesAvailable must contain at least two characters DWORD bytesAvailable = 0; diff --git a/src/tbox/platform/windows/interface/kernel32.c b/src/tbox/platform/windows/interface/kernel32.c index cfd9149fb..603737dc2 100644 --- a/src/tbox/platform/windows/interface/kernel32.c +++ b/src/tbox/platform/windows/interface/kernel32.c @@ -67,7 +67,7 @@ static tb_bool_t tb_kernel32_instance_init(tb_kernel32_ref_t kernel32) TB_INTERFACE_LOAD(kernel32, DeleteProcThreadAttributeList); TB_INTERFACE_LOAD(kernel32, CopyFileExW); TB_INTERFACE_LOAD(kernel32, PeekConsoleInputW); - TB_INTERFACE_LOAD(kernel32, PeekNamedPipeW); + TB_INTERFACE_LOAD(kernel32, PeekNamedPipe); #if defined(TB_COMPILER_IS_MSVC) && TB_COMPILER_VERSION_BT(16, 0) TB_INTERFACE_LOAD(kernel32, GetLogicalProcessorInformationEx); #endif diff --git a/src/tbox/platform/windows/interface/kernel32.h b/src/tbox/platform/windows/interface/kernel32.h index 8a2711030..ec7f64028 100644 --- a/src/tbox/platform/windows/interface/kernel32.h +++ b/src/tbox/platform/windows/interface/kernel32.h @@ -204,8 +204,8 @@ typedef BOOL (WINAPI* tb_kernel32_PeekConsoleInputW_t)( DWORD nLength, LPDWORD lpNumberOfEventsRead); -// the PeekNamedPipeW func type -typedef BOOL (WINAPI* tb_kernel32_PeekNamedPipeW_t)( +// the PeekNamedPipe func type +typedef BOOL (WINAPI* tb_kernel32_PeekNamedPipe_t)( HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, @@ -298,7 +298,7 @@ typedef struct __tb_kernel32_t tb_kernel32_PeekConsoleInputW_t PeekConsoleInputW; // PeekNamedPipe - tb_kernel32_PeekNamedPipeW_t PeekNamedPipeW; + tb_kernel32_PeekNamedPipe_t PeekNamedPipe; // GetLogicalProcessorInformationEx #if defined(TB_COMPILER_IS_MSVC) && TB_COMPILER_VERSION_BT(16, 0)