summaryrefslogtreecommitdiffstats
path: root/contrib/netcat/atomicio.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2006-05-21 15:49:27 +0000
committerdelphij <delphij@FreeBSD.org>2006-05-21 15:49:27 +0000
commitae5f19e683f661b5fdb91368ed13625b8184eca7 (patch)
tree243e38414b80cb75b334161d99a0c8e89e6273c1 /contrib/netcat/atomicio.c
parentfe20bac494132d72a50195b9fac6ff1258b6f32f (diff)
downloadFreeBSD-src-ae5f19e683f661b5fdb91368ed13625b8184eca7.zip
FreeBSD-src-ae5f19e683f661b5fdb91368ed13625b8184eca7.tar.gz
Import netcat from OpenBSD 3.9-RELEASE.
Diffstat (limited to 'contrib/netcat/atomicio.c')
-rw-r--r--contrib/netcat/atomicio.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/contrib/netcat/atomicio.c b/contrib/netcat/atomicio.c
index 9e73290..c3f2684 100644
--- a/contrib/netcat/atomicio.c
+++ b/contrib/netcat/atomicio.c
@@ -1,4 +1,7 @@
+/* $OpenBSD: atomicio.c,v 1.8 2006/02/11 19:31:18 otto Exp $ */
+
/*
+ * Copyright (c) 2005 Anil Madhavapeddy. All rights served.
* Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
* All rights reserved.
*
@@ -25,20 +28,23 @@
#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 > pos) {
res = (f) (fd, s + pos, n - pos);
@@ -46,11 +52,13 @@ atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n)
case -1:
if (errno == EINTR || errno == EAGAIN)
continue;
+ return 0;
case 0:
- return (res);
+ errno = EPIPE;
+ return pos;
default:
- pos += res;
+ pos += (size_t)res;
}
}
- return (pos);
+ return pos;
}
OpenPOWER on IntegriCloud