]> gitweb.factorcode.org Git - factor.git/blob - basis/random/unix/unix.factor
run bootstrap and startup hooks inside a with-destructors. use &dispose instead...
[factor.git] / basis / random / unix / unix.factor
1 ! Copyright (C) 2008 Doug Coleman
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.c-types io io.files kernel namespaces random
4 io.encodings.binary init accessors system destructors ;
5 IN: random.unix
6
7 TUPLE: unix-random reader ;
8
9 : <unix-random> ( path -- random )
10     binary <file-reader> unix-random boa ;
11
12 M: unix-random dispose reader>> dispose ;
13
14 M: unix-random random-bytes* ( n tuple -- byte-array )
15     reader>> stream-read ;
16
17 os openbsd? [
18     [
19         "/dev/srandom" <unix-random> &dispose secure-random-generator set-global
20         "/dev/arandom" <unix-random> &dispose system-random-generator set-global
21     ] "random.unix" add-startup-hook
22 ] [
23     [
24         "/dev/random" <unix-random> &dispose secure-random-generator set-global
25         "/dev/urandom" <unix-random> &dispose system-random-generator set-global
26     ] "random.unix" add-startup-hook
27 ] if