X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-tcl.git;a=blobdiff_plain;f=base%2Fhook.c;h=6e4b3a102e4abe26cf48cdb26faad2066dd2d439;hp=cc3eba867eaf9111e62bab013376f724aee53334;hb=382dc154ad04e75c16d062af9e4ab49a82330ba0;hpb=ceed4cf646a34245b3bc88089a2187ebf7a41f0f diff --git a/base/hook.c b/base/hook.c index cc3eba8..6e4b3a1 100644 --- a/base/hook.c +++ b/base/hook.c @@ -1,6 +1,6 @@ /* * base code for various Tcl extensions - * Copyright 2006 Ian Jackson + * Copyright 2006-2012 Ian Jackson * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -13,9 +13,7 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with this library; if not, see . */ #include "chiark-tcl-base.h" @@ -86,7 +84,7 @@ void cht_obj_updatestr_string(Tcl_Obj *o, const char *str) { int cht_get_urandom(Tcl_Interp *ip, Byte *buffer, int l) { static FILE *urandom; - int r, esave; + int r; if (!urandom) { urandom= fopen(URANDOM,"rb"); @@ -95,15 +93,14 @@ int cht_get_urandom(Tcl_Interp *ip, Byte *buffer, int l) { r= fread(buffer,1,l,urandom); if (r==l) return 0; - esave= errno; - fclose(urandom); urandom=0; - if (ferror(urandom)) { - return cht_posixerr(ip,errno,"read " URANDOM); + r = cht_posixerr(ip,errno,"read " URANDOM); } else { assert(feof(urandom)); - return cht_staticerr(ip, URANDOM " gave eof!", 0); + r = cht_staticerr(ip, URANDOM " gave eof!", 0); } + fclose(urandom); urandom=0; + return r; } void cht_prepare__basic(Tcl_Interp *ip) {