aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-029/daniel-mita/perl6/ch-2.p622
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-029/daniel-mita/perl6/ch-2.p6 b/challenge-029/daniel-mita/perl6/ch-2.p6
new file mode 100755
index 0000000000..9a6365be70
--- /dev/null
+++ b/challenge-029/daniel-mita/perl6/ch-2.p6
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl6
+use v6;
+use NativeCall;
+
+sub getrandom ( Buf, size_t, uint32 --> ssize_t ) is native {*}
+
+#| http://man7.org/linux/man-pages/man2/getrandom.2.html
+sub MAIN (
+ UInt $bytes = 8, #= Number of random bytes (defaults to 8)
+ UInt $flags = 0,
+) {
+ given Buf.allocate($bytes) {
+ given .&getrandom: $bytes, $flags {
+ when -1 {
+ die sub strerror( int32 --> Str ) is native {*}(
+ cglobal( ('c', v6), 'errno', int32 ) );
+ }
+ when * < $bytes { die 'got fewer bytes than requested' }
+ }
+ .say;
+ }
+}