diff --git a/scsh/fdports1.c b/scsh/fdports1.c index 78562ac..6dc00e5 100644 --- a/scsh/fdports1.c +++ b/scsh/fdports1.c @@ -394,8 +394,9 @@ int read_fdport_substring(scheme_value buf, int start, int end, scheme_value dat int write_fdport_substring(scheme_value buf, int start, int end, scheme_value data) { FILE *f = fstar_cache[EXTRACT_FIXNUM(*PortData_Fd(data))]; - int retval = fwrite(StrByte(buf,start), 1, end-start, f); - return ferror(f) ? -1 : retval; /* -1: error, 0: eof */ + int nbytes = end - start; + int retval = fwrite(StrByte(buf,start), 1, nbytes, f); + return (retval < nbytes) ? -1 : retval; /* -1: error, otw numwritten */ } /* 1st return value says why we terminated the read: