Skip to content

Commit

Permalink
fix pipe api
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jan 9, 2025
1 parent 33378af commit 43b5723
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/tbox/platform/stdfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/tbox/platform/windows/interface/kernel32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/tbox/platform/windows/interface/kernel32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 43b5723

Please sign in to comment.