2
* Copyright (C) 2011, Parrot Foundation.
9
src/platform/generic/entropy.c
13
Get some entropy from the system.
23
#include "parrot/parrot.h"
25
/* HEADERIZER HFILE: none */
29
=item C<void Parrot_get_entropy(PARROT_INTERP)>
31
Get one INTVAL worth of entropy from the system.
38
Parrot_get_entropy(PARROT_INTERP) {
41
FILE *urand_fh = fopen("/dev/urandom", "r");
44
const char *msg = "Couldn't open /dev/urandom for reading.";
45
/* This function is called during interp init, so use the GC registry
46
* as a way to figure out interp's initialziedness.
48
if (interp->gc_registry)
49
Parrot_ex_throw_from_c_args(interp, NULL, 1, msg);
53
count = fread(&entropy, sizeof (INTVAL), 1, urand_fh);
55
const char* msg = "Couldn't read from /dev/urandom.";
57
if (interp->gc_registry)
58
Parrot_ex_throw_from_c_args(interp, NULL, 1, msg);
76
* c-file-style: "parrot"
78
* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :