summaryrefslogtreecommitdiffstats
path: root/lib/libpthread
diff options
context:
space:
mode:
authorbrad <brad@openbsd.org>2003-12-22 21:28:47 +0000
committerbrad <brad@openbsd.org>2003-12-22 21:28:47 +0000
commitf914aaa7c286e01897fb5ef5028142ddd703232d (patch)
tree35fcf6824baf45a0ca707b2e51ed21fab1e2bc6b /lib/libpthread
parenttypos from Jared Yanovich; (diff)
downloadwireguard-openbsd-f914aaa7c286e01897fb5ef5028142ddd703232d.tar.xz
wireguard-openbsd-f914aaa7c286e01897fb5ef5028142ddd703232d.zip
Fix from FreeBSD' libc_r
rev 1.21 Fix bogus return values from libc_r's writev() routine in situations where a partial-write is followed by an error. ok marc@
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/uthread/uthread_writev.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/libpthread/uthread/uthread_writev.c b/lib/libpthread/uthread/uthread_writev.c
index 60b71dda10a..9c2e6ecd292 100644
--- a/lib/libpthread/uthread/uthread_writev.c
+++ b/lib/libpthread/uthread/uthread_writev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_writev.c,v 1.6 2003/01/31 04:46:17 marc Exp $ */
+/* $OpenBSD: uthread_writev.c,v 1.7 2003/12/22 21:28:47 brad Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -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: */