From fa5e0ed157b49dfcb657e412fe969f538831f516 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Thu, 6 Jan 2022 12:18:10 -0800 Subject: [PATCH] SCP: Assure that debug writes that check errno get a correct value The original solution provided in response to #957 needs to be adjusted to reflect that errno is only guaranteed to be set by fwrite() if an error occurred. otherwise a non zero value may have been set by some other call elsewhere in the program. All other cases where errno is explicitly check in simh, it is only done after receiving a return status from a system call. Fix problem reported in #1108 --- scp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scp.c b/scp.c index 81a6f4ab..fcd3a609 100644 --- a/scp.c +++ b/scp.c @@ -13396,12 +13396,12 @@ static void _debug_fwrite_all (const char *buf, size_t len, FILE *f) size_t len_written; while (len > 0) { + errno = 0; len_written = fwrite (buf, 1, len, f); len -= len_written; buf += len_written; if (errno == EAGAIN) /* Non blocking file descriptor buffer full? */ sim_os_ms_sleep(10);/* wait a bit to retry */ - errno = 0; } }