From 6878ac5253a2398ec53ff9dd703865a6684b2ab2 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 31 Mar 2013 20:38:03 +0200 Subject: [PATCH] pharo: Povide a pharo specific way to access the /dev/urandom device We need to start with a FileStream and call binary on it. This appears to be doing the tick. --- Makefile | 2 +- pharo-porting/changes_for_pharo.st | 34 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 pharo-porting/changes_for_pharo.st diff --git a/Makefile b/Makefile index a9c4745..edea382 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ CALLAGENT = \ callagent/Tests.st PHARO_COMPAT = pharo-porting/compat_for_pharo.st -PHARO_CHANGES = +PHARO_CHANGES = pharo-porting/changes_for_pharo.st all: diff --git a/pharo-porting/changes_for_pharo.st b/pharo-porting/changes_for_pharo.st new file mode 100644 index 0000000..a8ee50c --- /dev/null +++ b/pharo-porting/changes_for_pharo.st @@ -0,0 +1,34 @@ + +SIPURandom class extend [ + nextByte [ + + | file | + "Pharo has a weird kind of stream support" + + file := (FileStream readOnlyFileNamed: '/dev/urandom') + binary; yourself. + [ + ^ file next value. + ] ensure: [ + file close. + ] + ] + + nextInt [ + + | file | + file := (FileStream readOnlyFileNamed: '/dev/urandom') + binary; yourself. + [ + | data | + data := ByteArray new: 4. + 1 to: data size do: [:each | + data at: each put: file next value. + ]. + + ^ data uintAt: 1 + ] ensure: [ + file close. + ] + ] +]