summaryrefslogtreecommitdiff
path: root/atomicio.c
diff options
context:
space:
mode:
authordjm <djm>2005-05-26 02:23:44 +0000
committerdjm <djm>2005-05-26 02:23:44 +0000
commitc720f30a5a83f139c56b7742197b67b1f7f76712 (patch)
treeaca3c31741bd62bd32f4214ed7537d2c95a64cd0 /atomicio.c
parentc70cf4f100b16906f050f7334fbcfaed42e97b8d (diff)
downloadopenssh-c720f30a5a83f139c56b7742197b67b1f7f76712.tar.gz
- 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);