From fe2334c0b0d5f232bd6d501dbb45145792811857 Mon Sep 17 00:00:00 2001 From: Ole Streicher Date: Sat, 13 Jan 2024 11:39:15 +0100 Subject: [PATCH] Use fpurge/__fpurge to cancel buffered output While not really portable, these are the libc functions for this task. Linux is covered with the __GLIBC__ macro here, because it is not a Linux but a glibc feature. HURD is handled like Linux. --- unix/os/zxwhen.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/unix/os/zxwhen.c b/unix/os/zxwhen.c index b9bc75e5f..3c7d6f974 100644 --- a/unix/os/zxwhen.c +++ b/unix/os/zxwhen.c @@ -2,6 +2,9 @@ */ #include +#ifdef __GLIBC__ +#include +#endif #include #include @@ -32,8 +35,10 @@ int debug_sig = 0; /* If the OS allows, cancel any buffered output. If the OS doesn't, * do nothing. */ -#ifdef __APPLE__ -#define fcancel(fp) ((fp)->_r = (fp)->_w = 0) +#if defined(__APPLE__) || defined(BSD) || defined(__USE_BSD) +#define fcancel(fp) (void)fpurge(fp) +#elif defined(__GLIBC__) +#define fcancel(fp) __fpurge(fp) #else #define fcancel(fp) #endif