summaryrefslogtreecommitdiff
path: root/atomicio.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2005-05-26 12:23:44 +1000
committerDamien Miller <djm@mindrot.org>2005-05-26 12:23:44 +1000
commitb253cc42136649e3eac80e02667f8fbc1e43baaa (patch)
treee3824a905c7b12e4901e60e87ecdc968228e645e /atomicio.c
parent02e754f1f01470c11a175a0d07381361afe37fff (diff)
- avsm@cvs.openbsd.org 2005/05/24 17:32:44
[atomicio.c atomicio.h authfd.c monitor_wrap.c msg.c scp.c sftp-client.c] [ssh-keyscan.c sshconnect.c] 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 'atomicio.c')
-rw-r--r--atomicio.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/atomicio.c b/atomicio.c
index 7637e167..12abbda1 100644
--- a/atomicio.c
+++ b/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);
@@ -51,10 +53,12 @@ atomicio(f, fd, _s, n)
if (errno == EINTR || errno == EAGAIN)
#endif
continue;
+ return 0;
case 0:
- return (res);
+ errno = EPIPE;
+ return pos;
default:
- pos += res;
+ pos += (u_int)res;
}
}
return (pos);