diff options
Diffstat (limited to 'atomicio.c')
-rw-r--r-- | atomicio.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/atomicio.c b/atomicio.c index 7637e1671..12abbda16 100644 --- a/atomicio.c +++ b/atomicio.c | |||
@@ -1,4 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved. | ||
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 | * |
@@ -24,14 +25,14 @@ | |||
24 | */ | 25 | */ |
25 | 26 | ||
26 | #include "includes.h" | 27 | #include "includes.h" |
27 | RCSID("$OpenBSD: atomicio.c,v 1.12 2003/07/31 15:50:16 avsm Exp $"); | 28 | RCSID("$OpenBSD: atomicio.c,v 1.13 2005/05/24 17:32:43 avsm Exp $"); |
28 | 29 | ||
29 | #include "atomicio.h" | 30 | #include "atomicio.h" |
30 | 31 | ||
31 | /* | 32 | /* |
32 | * ensure all of data on socket comes through. f==read || f==vwrite | 33 | * ensure all of data on socket comes through. f==read || f==vwrite |
33 | */ | 34 | */ |
34 | ssize_t | 35 | size_t |
35 | atomicio(f, fd, _s, n) | 36 | atomicio(f, fd, _s, n) |
36 | ssize_t (*f) (int, void *, size_t); | 37 | ssize_t (*f) (int, void *, size_t); |
37 | int fd; | 38 | int fd; |
@@ -39,7 +40,8 @@ atomicio(f, fd, _s, n) | |||
39 | size_t n; | 40 | size_t n; |
40 | { | 41 | { |
41 | char *s = _s; | 42 | char *s = _s; |
42 | ssize_t res, pos = 0; | 43 | size_t pos = 0; |
44 | ssize_t res; | ||
43 | 45 | ||
44 | while (n > pos) { | 46 | while (n > pos) { |
45 | res = (f) (fd, s + pos, n - pos); | 47 | res = (f) (fd, s + pos, n - pos); |
@@ -51,10 +53,12 @@ atomicio(f, fd, _s, n) | |||
51 | if (errno == EINTR || errno == EAGAIN) | 53 | if (errno == EINTR || errno == EAGAIN) |
52 | #endif | 54 | #endif |
53 | continue; | 55 | continue; |
56 | return 0; | ||
54 | case 0: | 57 | case 0: |
55 | return (res); | 58 | errno = EPIPE; |
59 | return pos; | ||
56 | default: | 60 | default: |
57 | pos += res; | 61 | pos += (u_int)res; |
58 | } | 62 | } |
59 | } | 63 | } |
60 | return (pos); | 64 | return (pos); |