diff options
author | avsm <> | 2005-05-24 20:13:28 +0000 |
---|---|---|
committer | avsm <> | 2005-05-24 20:13:28 +0000 |
commit | a3374fefe00db04f7c91ec3205b912b87f2cbe18 (patch) | |
tree | fc8ed8403633c4027bd5b04b34482aee974a4dc3 /src/usr.bin/nc/atomicio.c | |
parent | 33ce8b8d9887f1d1e3b1e1b2673b810adf2fa717 (diff) | |
download | openbsd-a3374fefe00db04f7c91ec3205b912b87f2cbe18.tar.gz openbsd-a3374fefe00db04f7c91ec3205b912b87f2cbe18.tar.bz2 openbsd-a3374fefe00db04f7c91ec3205b912b87f2cbe18.zip |
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 'src/usr.bin/nc/atomicio.c')
-rw-r--r-- | src/usr.bin/nc/atomicio.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/usr.bin/nc/atomicio.c b/src/usr.bin/nc/atomicio.c index 151dde0cf6..545bbeee94 100644 --- a/src/usr.bin/nc/atomicio.c +++ b/src/usr.bin/nc/atomicio.c | |||
@@ -1,4 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2005 Anil Madhavapeddy. All rights served. | ||
2 | * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. | 3 | * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. |
3 | * All rights reserved. | 4 | * All rights reserved. |
4 | * | 5 | * |
@@ -21,36 +22,42 @@ | |||
21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | * $OpenBSD: atomicio.c,v 1.6 2005/05/24 20:13:28 avsm Exp $ | ||
24 | */ | 26 | */ |
25 | 27 | ||
26 | #include <sys/types.h> | 28 | #include <sys/types.h> |
27 | #include <sys/uio.h> | 29 | #include <sys/uio.h> |
28 | |||
29 | #include <errno.h> | 30 | #include <errno.h> |
30 | #include <unistd.h> | 31 | #include <unistd.h> |
31 | 32 | #include "atomicio.h" | |
32 | ssize_t atomicio(ssize_t (*f)(int, void *, size_t), int fd, void *_s, size_t n); | ||
33 | 33 | ||
34 | /* | 34 | /* |
35 | * ensure all of data on socket comes through. f==read || f==write | 35 | * ensure all of data on socket comes through. f==read || f==vwrite |
36 | */ | 36 | */ |
37 | ssize_t | 37 | size_t |
38 | atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n) | 38 | atomicio(f, fd, _s, n) |
39 | ssize_t (*f) (int, void *, size_t); | ||
40 | int fd; | ||
41 | void *_s; | ||
42 | size_t n; | ||
39 | { | 43 | { |
40 | char *s = _s; | 44 | char *s = _s; |
41 | ssize_t res, pos = 0; | 45 | size_t pos = 0; |
46 | ssize_t res; | ||
42 | 47 | ||
43 | while (n > (size_t)pos) { | 48 | while (n > pos) { |
44 | res = (f) (fd, s + pos, n - pos); | 49 | res = (f) (fd, s + pos, n - pos); |
45 | switch (res) { | 50 | switch (res) { |
46 | case -1: | 51 | case -1: |
47 | if (errno == EINTR || errno == EAGAIN) | 52 | if (errno == EINTR || errno == EAGAIN) |
48 | continue; | 53 | continue; |
54 | return 0; | ||
49 | case 0: | 55 | case 0: |
50 | return (res); | 56 | errno = EPIPE; |
57 | return pos; | ||
51 | default: | 58 | default: |
52 | pos += res; | 59 | pos += (u_int)res; |
53 | } | 60 | } |
54 | } | 61 | } |
55 | return (pos); | 62 | return pos; |
56 | } | 63 | } |