diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2003-12-22 21:28:48 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2003-12-22 21:28:48 +0000 |
commit | 78c9d0d98e91effb53376813c31bb3035ca8e3ae (patch) | |
tree | 2f066aa14e67e963fc22f9066da83b62540107b0 /lib/libpthread/uthread | |
parent | f1b4a4fe0abae7b74fa8626ba90f10c564a15a94 (diff) |
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/uthread')
-rw-r--r-- | lib/libpthread/uthread/uthread_writev.c | 29 |
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: */ |