Commit a6c501e4 authored by Anthony Martin's avatar Anthony Martin Committed by Russ Cox

net, io/ioutil: remove use of os.Time

I had to replace the single use of io/ioutil
in the time package with a bytes.Buffer since
there would've been a dependency cycle.

There are no other uses of os.Time.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5372054
parent 3199a6ca
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"time"
) )
// Random number state, accessed without lock; racy but harmless. // Random number state, accessed without lock; racy but harmless.
...@@ -17,8 +18,7 @@ import ( ...@@ -17,8 +18,7 @@ import (
var rand uint32 var rand uint32
func reseed() uint32 { func reseed() uint32 {
sec, nsec, _ := os.Time() return uint32(time.Nanoseconds() + int64(os.Getpid()))
return uint32(sec*1e9 + nsec + int64(os.Getpid()))
} }
func nextSuffix() string { func nextSuffix() string {
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
package net package net
import ( import (
"os"
"sync" "sync"
"time"
) )
const cacheMaxAge = int64(300) // 5 minutes. const cacheMaxAge = int64(300) // 5 minutes.
...@@ -26,7 +26,7 @@ var hosts struct { ...@@ -26,7 +26,7 @@ var hosts struct {
} }
func readHosts() { func readHosts() {
now, _, _ := os.Time() now := time.Seconds()
hp := hostsPath hp := hostsPath
if len(hosts.byName) == 0 || hosts.time+cacheMaxAge <= now || hosts.path != hp { if len(hosts.byName) == 0 || hosts.time+cacheMaxAge <= now || hosts.path != hp {
hs := make(map[string][]string) hs := make(map[string][]string)
...@@ -51,7 +51,7 @@ func readHosts() { ...@@ -51,7 +51,7 @@ func readHosts() {
} }
} }
// Update the data cache. // Update the data cache.
hosts.time, _, _ = os.Time() hosts.time = time.Seconds()
hosts.path = hp hosts.path = hp
hosts.byName = hs hosts.byName = hs
hosts.byAddr = is hosts.byAddr = is
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
package time package time
import ( import (
"io/ioutil" "bytes"
"os" "os"
) )
...@@ -180,11 +180,17 @@ func parseinfo(bytes []byte) (zt []zonetime, ok bool) { ...@@ -180,11 +180,17 @@ func parseinfo(bytes []byte) (zt []zonetime, ok bool) {
} }
func readinfofile(name string) ([]zonetime, bool) { func readinfofile(name string) ([]zonetime, bool) {
buf, err := ioutil.ReadFile(name) var b bytes.Buffer
f, err := os.Open(name)
if err != nil { if err != nil {
return nil, false return nil, false
} }
return parseinfo(buf) defer f.Close()
if _, err := b.ReadFrom(f); err != nil {
return nil, false
}
return parseinfo(b.Bytes())
} }
func setupTestingZone() { func setupTestingZone() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment