diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-18 18:55:44 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-18 18:55:44 +0000 |
commit | 3534b428629be185e096be99e3bd5fdfe32d5544 (patch) | |
tree | 210ef3198ed66bc7f7b7bf6a85e4579f455e5a36 /src/librandom/rrandom_read.c | |
download | skalibs-3534b428629be185e096be99e3bd5fdfe32d5544.tar.xz |
initial commit with rc for skalibs-2.0.0.0
Diffstat (limited to 'src/librandom/rrandom_read.c')
-rw-r--r-- | src/librandom/rrandom_read.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/librandom/rrandom_read.c b/src/librandom/rrandom_read.c new file mode 100644 index 0000000..57ff920 --- /dev/null +++ b/src/librandom/rrandom_read.c @@ -0,0 +1,21 @@ +/* ISC license. */ + +#include <errno.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/error.h> +#include <skalibs/unirandom.h> +#include <skalibs/rrandom.h> + +unsigned int rrandom_read (rrandom_ref z, char *s, unsigned int n, unsigned int (*f) (unirandom_ref, char *, unsigned int)) +{ + unsigned int i = 0 ; + for (; i < 3 ; i++) + { + int r ; + if (!z->tries[i].ok) continue ; + r = sanitize_read((*f)(&z->tries[i].it, s, n)) ; + if (r > 0) return r ; + z->tries[i].ok = error_temp(errno) ? z->tries[i].ok - 1 : 0 ; + } + return (errno = ENOENT, 0) ; +} |