summaryrefslogtreecommitdiff
path: root/usr.bin/nc/atomicio.c
diff options
context:
space:
mode:
authorAnil Madhavapeddy <avsm@cvs.openbsd.org>2005-05-24 20:13:29 +0000
committerAnil Madhavapeddy <avsm@cvs.openbsd.org>2005-05-24 20:13:29 +0000
commitbf70235783a080c2b1da5823628d3a3c8ee141bf (patch)
treef7337fa8cf6a703274faa808b732a849af826420 /usr.bin/nc/atomicio.c
parent50168be1381281d3882d0cacf8df97174ebe1864 (diff)
Switch atomicio to a simpler interface which returns size_t and uses
0 to signal errors. should be no functional change in nc apart from different error messages. "groovy", said deraadt@
Diffstat (limited to 'usr.bin/nc/atomicio.c')
-rw-r--r--usr.bin/nc/atomicio.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/usr.bin/nc/atomicio.c b/usr.bin/nc/atomicio.c
index 151dde0cf66..545bbeee949 100644
--- a/usr.bin/nc/atomicio.c
+++ b/usr.bin/nc/atomicio.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (c) 2005 Anil Madhavapeddy. All rights served.
* Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
* All rights reserved.
*
@@ -21,36 +22,42 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * $OpenBSD: atomicio.c,v 1.6 2005/05/24 20:13:28 avsm Exp $
*/
#include <sys/types.h>
#include <sys/uio.h>
-
#include <errno.h>
#include <unistd.h>
-
-ssize_t atomicio(ssize_t (*f)(int, void *, size_t), int fd, void *_s, size_t n);
+#include "atomicio.h"
/*
- * ensure all of data on socket comes through. f==read || f==write
+ * ensure all of data on socket comes through. f==read || f==vwrite
*/
-ssize_t
-atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n)
+size_t
+atomicio(f, fd, _s, n)
+ ssize_t (*f) (int, void *, size_t);
+ int fd;
+ void *_s;
+ size_t n;
{
char *s = _s;
- ssize_t res, pos = 0;
+ size_t pos = 0;
+ ssize_t res;
- while (n > (size_t)pos) {
+ while (n > pos) {
res = (f) (fd, s + pos, n - pos);
switch (res) {
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);
+ return pos;
}