From 1baa36725d2a75333f1ed0d2b355dfc0398a07be Mon Sep 17 00:00:00 2001 From: Nishi Date: Wed, 13 May 2026 15:02:13 +0900 Subject: [PATCH] add ppr_process_readable --- .clang-format | 24 ++++++++++++++++++++++++ include/ppr_base.h | 1 + src/base/process.c | 23 +++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..eb9d30c --- /dev/null +++ b/.clang-format @@ -0,0 +1,24 @@ +--- +UseTab: Always +TabWidth: 8 +AlignConsecutiveAssignments: + Enabled: true +AlignConsecutiveDeclarations: + Enabled: true +AccessModifierOffset: -4 +NamespaceIndentation: All +IndentWidth: 8 +PointerAlignment: Left +ColumnLimit: 0 +AllowShortIfStatementsOnASingleLine: Always +AllowShortBlocksOnASingleLine: Never +AllowShortFunctionsOnASingleLine: Empty +AllowShortLoopsOnASingleLine: true +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: true +SpaceBeforeParens: Never +AlignEscapedNewlines: DontAlign +SortIncludes: false +AllowShortEnumsOnASingleLine: false +#IndentPPDirectives: AfterHash diff --git a/include/ppr_base.h b/include/ppr_base.h index a678d8b..f206a79 100644 --- a/include/ppr_base.h +++ b/include/ppr_base.h @@ -210,6 +210,7 @@ void* ppr_process_create(const char* exec, char** env); void ppr_process_close(void* handle); int ppr_process_write(void* handle, const void* data, int len); int ppr_process_read(void* handle, void* data, int len); +int ppr_process_readable(void* handle); void ppr_process_destroy(void* handle); /* dirent.c */ diff --git a/src/base/process.c b/src/base/process.c index 417fcb3..3610854 100644 --- a/src/base/process.c +++ b/src/base/process.c @@ -245,6 +245,29 @@ int ppr_process_read(void* handle, void* data, int len) { #endif } +int ppr_process_readable(void* handle) { + process_t* proc = handle; +#if defined(PPR_IS_WIN32) + DWORD avail; + + if(!PeekNamedPipe(proc->h_stdout, NULL, 0, NULL, &avail, NULL)) return 0; + + return (avail > 0) ? 1 : 0; +#elif defined(FPR_IS_UNIX) + struct ppr_pollfd pfd; + int n; + + pfd.fd = proc->fd_stdout; + pfd.events = FPR_POLLIN | FPR_POLLPRI; + + if((n = ppr_poll(&pfd, 1, 0)) < 0) return 0; + + return (n > 0) ? 1 : 0; +#else + return 0; +#endif +} + void ppr_process_destroy(void* handle) { process_t* proc = handle; #if defined(PPR_IS_WIN32)