summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorarchie <archie@FreeBSD.org>2002-11-12 19:01:49 +0000
committerarchie <archie@FreeBSD.org>2002-11-12 19:01:49 +0000
commitafee9a3a2ffec5ab0aa13f5da6cce85916386384 (patch)
tree3eafd34a837d7f1f0a4752a374ec0d4779a766de /lib
parent368ee15302a41fa8f252572654a71f8a027b296e (diff)
downloadFreeBSD-src-afee9a3a2ffec5ab0aa13f5da6cce85916386384.zip
FreeBSD-src-afee9a3a2ffec5ab0aa13f5da6cce85916386384.tar.gz
Fix bogus return values from libc_r's writev() routine in situations where
a partial-write is followed by an error. PR: 43335 MFC after: 3 days
Diffstat (limited to 'lib')
-rw-r--r--lib/libc_r/uthread/uthread_writev.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/libc_r/uthread/uthread_writev.c b/lib/libc_r/uthread/uthread_writev.c
index b07278a..77046d5 100644
--- a/lib/libc_r/uthread/uthread_writev.c
+++ b/lib/libc_r/uthread/uthread_writev.c
@@ -174,20 +174,35 @@ _writev(int fd, const struct iovec * iov, int iovcnt)
* interrupted by a signal
*/
if (curthread->interrupted) {
- /* Return an error: */
- ret = -1;
+ if (num > 0) {
+ /* Return partial success: */
+ ret = num;
+ } else {
+ /* Return an error: */
+ errno = EINTR;
+ ret = -1;
+ }
}
/*
- * If performing a non-blocking write or if an
- * error occurred, just return whatever the write
- * syscall did:
+ * If performing a non-blocking write,
+ * just return whatever the write syscall did:
*/
- } else if (!blocking || n < 0) {
+ } else if (!blocking) {
/* A non-blocking call might return zero: */
ret = n;
break;
+ /*
+ * If there was an error, return partial success
+ * (if any bytes were written) or else the error:
+ */
+ } else if (n < 0) {
+ if (num > 0)
+ ret = num;
+ else
+ ret = n;
+
/* Check if the write has completed: */
} else if (idx == iovcnt)
/* Return the number of bytes written: */
OpenPOWER on IntegriCloud