* 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 <http://www.gnu.org/licenses/>.
*/
#include "chiark-tcl-base.h"
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");
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) {