From 6bbcd01421a78b73ef80c524733df59c7745a283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=95=8F=E6=9D=B0?= Date: Mon, 21 Jul 2025 08:10:10 +0000 Subject: [PATCH] =?UTF-8?q?write=E6=AD=BB=E5=BE=AA=E7=8E=AF=E6=BC=8F?= =?UTF-8?q?=E6=B4=9E=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 吴敏杰 --- funcs.c | 24 ++++++++++++++++++++++++ sh.h | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/funcs.c b/funcs.c index ce94594..eac501a 100644 --- a/funcs.c +++ b/funcs.c @@ -565,6 +565,29 @@ c_print(const char **wp) po.coproc = po.copipe = false; s = Xstring(xs, xp); +#ifdef MKSH_OH_ADAPT + unsigned int retry_count = 0; + while (len > 0) { + ssize_t nwritten = write(po.fd, s, len); + retry_count = nwritten ? 0 : retry_count + 1; + if (nwritten < 0 || retry_count > = MAX_WRITE_RETRY_TIME) { + if (nwritten < 0 && errno == EINTR) { + if (po.copipe) + restore_pipe(); + /* give the user a chance to ^C out */ + intrcheck(); + /* interrupted, try again */ + if (po.coproc) + po.copipe = block_pipe(); + continue; + } + c = 1; + break; + } + s += nwritten; + len -= nwritten; + } +#else while (len > 0) { ssize_t nwritten; @@ -585,6 +608,7 @@ c_print(const char **wp) s += nwritten; len -= nwritten; } +#endif if (po.copipe) restore_pipe(); } diff --git a/sh.h b/sh.h index 1097e7b..9fcd3a2 100644 --- a/sh.h +++ b/sh.h @@ -258,6 +258,10 @@ typedef void (*sig_t)(int); typedef MKSH_TYPEDEF_SIG_ATOMIC_T sig_atomic_t; #endif +#ifdef MKSH_OH_ADAPT +#define MAX_WRITE_RETRY_TIME 10 +#endif + #ifdef MKSH_TYPEDEF_SSIZE_T typedef MKSH_TYPEDEF_SSIZE_T ssize_t; #endif