summaryrefslogtreecommitdiffhomepage
path: root/atomicio.c
diff options
context:
space:
mode:
authorFrancois Perrad <francois.perrad@gadz.org>2016-03-25 12:05:17 +0100
committerFrancois Perrad <francois.perrad@gadz.org>2016-11-15 14:56:25 +0100
commitecb4a6173df40a887fee2e8198e5c8985e2ca5e5 (patch)
tree2f67d2d4402413e488f6f1d873874c73b13c9141 /atomicio.c
parent37a66fa5b64ba36285abd346fc8706e6bef4be31 (diff)
upgrade atomicio
in order to remove K&R code in atomicio.c now, vwrite comes from atomicio.h
Diffstat (limited to 'atomicio.c')
-rw-r--r--atomicio.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/atomicio.c b/atomicio.c
index a061cbd..2aacf51 100644
--- a/atomicio.c
+++ b/atomicio.c
@@ -1,6 +1,8 @@
+/* $OpenBSD: atomicio.c,v 1.17 2006/04/01 05:51:34 djm Exp $ */
/*
- * Copied from OpenSSH 3.6.1p2.
+ * Copied from OpenSSH/OpenBSD.
*
+ * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved.
* Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
* All rights reserved.
*
@@ -25,39 +27,32 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/* RCSID("OpenBSD: atomicio.c,v 1.10 2001/05/08 22:48:07 markus Exp "); */
+#include "includes.h"
#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(f, fd, _s, n)
- ssize_t (*f) ();
- int fd;
- void *_s;
- size_t n;
+size_t
+atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n)
{
char *s = _s;
- ssize_t res;
size_t pos = 0;
+ ssize_t res;
while (n > pos) {
res = (f) (fd, s + pos, n - pos);
switch (res) {
case -1:
-#ifdef EWOULDBLOCK
- if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
-#else
if (errno == EINTR || errno == EAGAIN)
-#endif
continue;
- /* FALLTHROUGH */
+ return 0;
case 0:
- return (res);
+ errno = EPIPE;
+ return pos;
default:
- pos += res;
+ pos += (size_t)res;
}
}
return (pos);