]> Cypherpunks repositories - gostls13.git/commitdiff
net, io/ioutil: remove use of os.Time
authorAnthony Martin <ality@pbrane.org>
Fri, 11 Nov 2011 19:40:41 +0000 (14:40 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 11 Nov 2011 19:40:41 +0000 (14:40 -0500)
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

src/pkg/io/ioutil/tempfile.go
src/pkg/net/hosts.go
src/pkg/time/zoneinfo_unix.go

index 658ea78bb7c700d52a87070710fe383a68e6328c..71028e226773a40cd393f46b56fdd1aad2851c42 100644 (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 {
index d75e9e038a6791360b4f1a1cb49c850015726e7c..ddfb074ee8f12a43f119c344cf218f20c6c15feb 100644 (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
index 0dc423531366af18b7674dd07b311bdde0fdb007..b552e589aa947a08a97d0fbb9dcadb458330ff79 100644 (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() {