diff options
author | 2014-01-15 00:31:34 +0000 | |
---|---|---|
committer | 2014-01-15 00:31:34 +0000 | |
commit | bcd4d29fac42034f7d8273cc3ec78c4880d523d2 (patch) | |
tree | 0798161c8e980378e2675f0957498559ddb53a59 | |
parent | Add wcstring attribute support for Wbounded. To be used for wchar.h (diff) | |
download | wireguard-openbsd-bcd4d29fac42034f7d8273cc3ec78c4880d523d2.tar.xz wireguard-openbsd-bcd4d29fac42034f7d8273cc3ec78c4880d523d2.zip |
pipes mean read/write may short out.
okay tedu@
-rw-r--r-- | usr.bin/signify/signify.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/usr.bin/signify/signify.c b/usr.bin/signify/signify.c index 9bc6bacedc9..cf9e239657a 100644 --- a/usr.bin/signify/signify.c +++ b/usr.bin/signify/signify.c @@ -1,4 +1,4 @@ -/* $OpenBSD: signify.c,v 1.37 2014/01/14 21:34:30 tedu Exp $ */ +/* $OpenBSD: signify.c,v 1.38 2014/01/15 00:31:34 espie Exp $ */ /* * Copyright (c) 2013 Ted Unangst <tedu@openbsd.org> * @@ -120,12 +120,15 @@ static void readall(int fd, void *buf, size_t len, const char *filename) { ssize_t x; - - x = read(fd, buf, len); - if (x == -1) { - err(1, "read from %s", filename); - } else if (x != len) { - errx(1, "short read from %s", filename); + + while (len != 0) { + x = read(fd, buf, len); + if (x == -1) + err(1, "read from %s", filename); + else { + len -= x; + buf = (char*)buf + x; + } } } @@ -200,12 +203,15 @@ static void writeall(int fd, const void *buf, size_t len, const char *filename) { ssize_t x; - - x = write(fd, buf, len); - if (x == -1) { - err(1, "write to %s", filename); - } else if (x != len) { - errx(1, "short write to %s", filename); + + while (len != 0) { + x = write(fd, buf, len); + if (x == -1) + err(1, "write to %s", filename); + else { + len -= x; + buf = (char*)buf + x; + } } } |