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
This commit is contained in:
Anthony Martin 2011-11-11 14:40:41 -05:00 committed by Russ Cox
parent 3199a6ca8d
commit a6c501e4b1
3 changed files with 14 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"strconv"
"time"
)
// Random number state, accessed without lock; racy but harmless.
@ -17,8 +18,7 @@ import (
var rand uint32
func reseed() uint32 {
sec, nsec, _ := os.Time()
return uint32(sec*1e9 + nsec + int64(os.Getpid()))
return uint32(time.Nanoseconds() + int64(os.Getpid()))
}
func nextSuffix() string {

View File

@ -7,8 +7,8 @@
package net
import (
"os"
"sync"
"time"
)
const cacheMaxAge = int64(300) // 5 minutes.
@ -26,7 +26,7 @@ var hosts struct {
}
func readHosts() {
now, _, _ := os.Time()
now := time.Seconds()
hp := hostsPath
if len(hosts.byName) == 0 || hosts.time+cacheMaxAge <= now || hosts.path != hp {
hs := make(map[string][]string)
@ -51,7 +51,7 @@ func readHosts() {
}
}
// Update the data cache.
hosts.time, _, _ = os.Time()
hosts.time = time.Seconds()
hosts.path = hp
hosts.byName = hs
hosts.byAddr = is

View File

@ -12,7 +12,7 @@
package time
import (
"io/ioutil"
"bytes"
"os"
)
@ -180,11 +180,17 @@ func parseinfo(bytes []byte) (zt []zonetime, ok bool) {
}
func readinfofile(name string) ([]zonetime, bool) {
buf, err := ioutil.ReadFile(name)
var b bytes.Buffer
f, err := os.Open(name)
if err != nil {
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() {