X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=random.c;h=323fffd692e4677732edef90fe5d5a4106261872;hb=4bc0381500403be5f3e40bc39f65a2d8fb75cf19;hp=c4815270d414a6f42162b18adc658e5a672c0bfa;hpb=8689b3a94c043f04e334a7b181a7250ad5940616;p=secnet.git diff --git a/random.c b/random.c index c481527..323fffd 100644 --- a/random.c +++ b/random.c @@ -1,4 +1,20 @@ -/* $Log$ +/* + * This file is part of secnet. + * See README for full list of copyright holders. + * + * secnet is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * secnet is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 3 along with secnet; if not, see + * https://www.gnu.org/licenses/gpl.html. */ #include "secnet.h" @@ -7,6 +23,7 @@ #include #include #include +#include struct rgen_data { closure_t cl; @@ -16,14 +33,18 @@ struct rgen_data { }; static random_fn random_generate; -static bool_t random_generate(void *data, uint32_t bytes, uint8_t *buff) +static void random_generate(void *data, int32_t bytes, uint8_t *buff) { struct rgen_data *st=data; + int r; - /* XXX XXX error checking */ - read(st->fd,buff,bytes); + r= read(st->fd,buff,bytes); - return True; + assert(r == bytes); + /* This is totally crap error checking, but callers of + * this function do not check the return value and dealing + * with failure of this everywhere would be very inconvenient. + */ } static list_t *random_apply(closure_t *self, struct cloc loc, @@ -33,7 +54,7 @@ static list_t *random_apply(closure_t *self, struct cloc loc, item_t *arg1, *arg2; string_t filename=NULL; - st=safe_malloc(sizeof(*st),"random_apply"); + NEW(st); st->cl.description="randomsource"; st->cl.type=CL_RANDOMSRC; @@ -48,7 +69,7 @@ static list_t *random_apply(closure_t *self, struct cloc loc, arg2=list_elem(args,1); if (!arg1) { - fatal("randomsource: requires a filename\n"); + cfgfatal(loc,"randomsource","requires a filename\n"); } if (arg1->type != t_string) { cfgfatal(arg1->loc,"randomsource", @@ -65,7 +86,7 @@ static list_t *random_apply(closure_t *self, struct cloc loc, } if (!filename) { - fatal("randomsource requires a filename"); + cfgfatal(loc,"randomsource","requires a filename\n"); } st->fd=open(filename,O_RDONLY); if (st->fd<0) {