Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(324)

Unified Diff: src/pkg/crypto/rand/rand_plan9.go

Issue 4342043: code review 4342043: crypto/rand: Fix on Plan 9
Patch Set: diff -r 1cad1e8470ba https://go.googlecode.com/hg/ Created 14 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/crypto/rand/prng.go ('k') | src/pkg/crypto/rand/rand_unix.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/crypto/rand/rand_plan9.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/pkg/crypto/rand/rand_plan9.go
@@ -0,0 +1,33 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package rand
+
+import (
+ "io"
+ "os"
+ "sync"
+)
+
+func init() { Reader = newReader(nil) }
+
+// A devReader satisfies reads by reading the file named name.
+type devReader struct {
+ name string
+ f io.Reader
+ mu sync.Mutex
+}
+
+func (r *devReader) Read(b []byte) (n int, err os.Error) {
+ r.mu.Lock()
+ defer r.mu.Unlock()
+ if r.f == nil {
+ f, err := os.Open(r.name)
+ if f == nil {
+ return 0, err
+ }
+ r.f = f
+ }
+ return r.f.Read(b)
+}
« no previous file with comments | « src/pkg/crypto/rand/prng.go ('k') | src/pkg/crypto/rand/rand_unix.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b