]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: plan 9 does have /dev/random
authorJeff Sickel <jas@corpus-callosum.com>
Sat, 4 Jan 2014 18:53:22 +0000 (10:53 -0800)
committerRob Pike <r@golang.org>
Sat, 4 Jan 2014 18:53:22 +0000 (10:53 -0800)
R=golang-codereviews, r, aram
CC=0intro, golang-codereviews, rsc
https://golang.org/cl/43420045

src/pkg/runtime/os_plan9.c

index 07db2c3055a96402ce14000aede70fa39eb428de..dd2828b1d9a30ac70bf0d1f2a475b808724ded47 100644 (file)
@@ -102,8 +102,18 @@ runtime·crash(void)
 void
 runtime·get_random_data(byte **rnd, int32 *rnd_len)
 {
-       *rnd = nil;
-       *rnd_len = 0;
+       static byte random_data[HashRandomBytes];
+       int32 fd;
+
+       fd = runtime·open("/dev/random", 0 /* O_RDONLY */, 0);
+       if(runtime·read(fd, random_data, HashRandomBytes) == HashRandomBytes) {
+               *rnd = random_data;
+               *rnd_len = HashRandomBytes;
+       } else {
+               *rnd = nil;
+               *rnd_len = 0;
+       }
+       runtime·close(fd);
 }
 
 void