serval-dna/nacl/nacl-20110221/curvecp/load.c
Daniel O'Connor bf9710fd5a Unpacked nacl-20110221 after processing by nacl-prepare-sources.
This only affects build_android, if nacl-gcc-prep is run then build/`uname -s` will be created.
2012-02-27 12:40:14 +10:30

34 lines
599 B
C

#include <unistd.h>
#include "open.h"
#include "e.h"
#include "load.h"
static int readall(int fd,void *x,long long xlen)
{
long long r;
while (xlen > 0) {
r = xlen;
if (r > 1048576) r = 1048576;
r = read(fd,x,r);
if (r == 0) errno = EPROTO;
if (r <= 0) {
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) continue;
return -1;
}
x += r;
xlen -= r;
}
return 0;
}
int load(const char *fn,void *x,long long xlen)
{
int fd;
int r;
fd = open_read(fn);
if (fd == -1) return -1;
r = readall(fd,x,xlen);
close(fd);
return r;
}