diff options
Diffstat (limited to 'nacl/curvecp/writeall.c')
-rw-r--r-- | nacl/curvecp/writeall.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/nacl/curvecp/writeall.c b/nacl/curvecp/writeall.c new file mode 100644 index 00000000..58f93011 --- /dev/null +++ b/nacl/curvecp/writeall.c | |||
@@ -0,0 +1,27 @@ | |||
1 | #include <poll.h> | ||
2 | #include <unistd.h> | ||
3 | #include "e.h" | ||
4 | #include "writeall.h" | ||
5 | |||
6 | int writeall(int fd,const void *x,long long xlen) | ||
7 | { | ||
8 | long long w; | ||
9 | while (xlen > 0) { | ||
10 | w = xlen; | ||
11 | if (w > 1048576) w = 1048576; | ||
12 | w = write(fd,x,w); | ||
13 | if (w < 0) { | ||
14 | if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { | ||
15 | struct pollfd p; | ||
16 | p.fd = fd; | ||
17 | p.events = POLLOUT | POLLERR; | ||
18 | poll(&p,1,-1); | ||
19 | continue; | ||
20 | } | ||
21 | return -1; | ||
22 | } | ||
23 | x += w; | ||
24 | xlen -= w; | ||
25 | } | ||
26 | return 0; | ||
27 | } | ||