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