summaryrefslogtreecommitdiff
path: root/nacl/curvecp/load.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/curvecp/load.c')
-rw-r--r--nacl/curvecp/load.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/nacl/curvecp/load.c b/nacl/curvecp/load.c
new file mode 100644
index 00000000..0cd4e43d
--- /dev/null
+++ b/nacl/curvecp/load.c
@@ -0,0 +1,33 @@
1#include <unistd.h>
2#include "open.h"
3#include "e.h"
4#include "load.h"
5
6static int readall(int fd,void *x,long long xlen)
7{
8 long long r;
9 while (xlen > 0) {
10 r = xlen;
11 if (r > 1048576) r = 1048576;
12 r = read(fd,x,r);
13 if (r == 0) errno = EPROTO;
14 if (r <= 0) {
15 if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) continue;
16 return -1;
17 }
18 x += r;
19 xlen -= r;
20 }
21 return 0;
22}
23
24int load(const char *fn,void *x,long long xlen)
25{
26 int fd;
27 int r;
28 fd = open_read(fn);
29 if (fd == -1) return -1;
30 r = readall(fd,x,xlen);
31 close(fd);
32 return r;
33}