diff options
author | Anil Madhavapeddy <avsm@cvs.openbsd.org> | 2005-05-24 17:32:45 +0000 |
---|---|---|
committer | Anil Madhavapeddy <avsm@cvs.openbsd.org> | 2005-05-24 17:32:45 +0000 |
commit | 8d70480c583a93f537beb6ba10177b405033e6d2 (patch) | |
tree | af6655f91ee72626175bd38e315fcdef4cb74ff3 /usr.bin/ssh/atomicio.c | |
parent | e4259f82cd9c63cff5f23fc9d63da9a4a294e389 (diff) |
Switch atomicio to use a simpler interface; it now returns a size_t
(containing number of bytes read/written), and indicates error by
returning 0. EOF is signalled by errno==EPIPE.
Typical use now becomes:
if (atomicio(read, ..., len) != len)
err(1,"read");
ok deraadt@, cloder@, djm@
Diffstat (limited to 'usr.bin/ssh/atomicio.c')
-rw-r--r-- | usr.bin/ssh/atomicio.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/usr.bin/ssh/atomicio.c b/usr.bin/ssh/atomicio.c index 26f52c5cb94..a71808a6846 100644 --- a/usr.bin/ssh/atomicio.c +++ b/usr.bin/ssh/atomicio.c @@ -1,4 +1,5 @@ /* + * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved. * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. * All rights reserved. * @@ -24,14 +25,14 @@ */ #include "includes.h" -RCSID("$OpenBSD: atomicio.c,v 1.12 2003/07/31 15:50:16 avsm Exp $"); +RCSID("$OpenBSD: atomicio.c,v 1.13 2005/05/24 17:32:43 avsm Exp $"); #include "atomicio.h" /* * ensure all of data on socket comes through. f==read || f==vwrite */ -ssize_t +size_t atomicio(f, fd, _s, n) ssize_t (*f) (int, void *, size_t); int fd; @@ -39,7 +40,8 @@ atomicio(f, fd, _s, n) size_t n; { char *s = _s; - ssize_t res, pos = 0; + size_t pos = 0; + ssize_t res; while (n > pos) { res = (f) (fd, s + pos, n - pos); @@ -47,10 +49,12 @@ atomicio(f, fd, _s, n) case -1: if (errno == EINTR || errno == EAGAIN) continue; + return 0; case 0: - return (res); + errno = EPIPE; + return pos; default: - pos += res; + pos += (u_int)res; } } return (pos); |