X-Git-Url: http://andersk.mit.edu/gitweb/openssh.git/blobdiff_plain/521b39139562af2ac97b16d1ca8f50f642613dd5..9c54c067cca6a1d021a6d5120e0adc05f3252a97:/atomicio.c diff --git a/atomicio.c b/atomicio.c index 1b960e56..12abbda1 100644 --- a/atomicio.c +++ b/atomicio.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 1999 Theo de Raadt + * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved. + * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,33 +25,40 @@ */ #include "includes.h" -RCSID("$Id$"); +RCSID("$OpenBSD: atomicio.c,v 1.13 2005/05/24 17:32:43 avsm Exp $"); -#include "xmalloc.h" -#include "ssh.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 */ -int -atomicio(f, fd, s, n) - int (*f) (); +size_t +atomicio(f, fd, _s, n) + ssize_t (*f) (int, void *, size_t); int fd; - void *s; + void *_s; size_t n; { - int res, pos = 0; + char *s = _s; + 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; + return 0; case 0: - return (res); + errno = EPIPE; + return pos; default: - pos += res; + pos += (u_int)res; } } return (pos);