aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/io
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-12-13 19:16:27 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-12-13 19:16:27 +0000
commit7b1c3dd9e670da2041ff1af415999310f88888ad (patch)
treec5132538d5da85ed816c7e1f9d93c4a503b838ab /libgo/go/io
parent36cfbee133027429a681ce585643d38228ab1213 (diff)
downloadgcc-7b1c3dd9e670da2041ff1af415999310f88888ad.zip
gcc-7b1c3dd9e670da2041ff1af415999310f88888ad.tar.gz
gcc-7b1c3dd9e670da2041ff1af415999310f88888ad.tar.bz2
libgo: Update to weekly.2011-12-02.
From-SVN: r182295
Diffstat (limited to 'libgo/go/io')
-rw-r--r--libgo/go/io/ioutil/ioutil.go24
-rw-r--r--libgo/go/io/ioutil/ioutil_test.go8
-rw-r--r--libgo/go/io/ioutil/tempfile.go2
-rw-r--r--libgo/go/io/multi_test.go2
4 files changed, 16 insertions, 20 deletions
diff --git a/libgo/go/io/ioutil/ioutil.go b/libgo/go/io/ioutil/ioutil.go
index f6c8cd8..be7fa5f 100644
--- a/libgo/go/io/ioutil/ioutil.go
+++ b/libgo/go/io/ioutil/ioutil.go
@@ -36,8 +36,8 @@ func ReadFile(filename string) ([]byte, error) {
// read, so let's try it but be prepared for the answer to be wrong.
fi, err := f.Stat()
var n int64
- if err == nil && fi.Size < 2e9 { // Don't preallocate a huge buffer, just in case.
- n = fi.Size
+ if size := fi.Size(); err == nil && size < 2e9 { // Don't preallocate a huge buffer, just in case.
+ n = size
}
// As initial capacity for readAll, use n + a little extra in case Size is zero,
// and to avoid another allocation after Read has filled the buffer. The readAll
@@ -63,16 +63,16 @@ func WriteFile(filename string, data []byte, perm uint32) error {
return err
}
-// A fileInfoList implements sort.Interface.
-type fileInfoList []*os.FileInfo
+// byName implements sort.Interface.
+type byName []os.FileInfo
-func (f fileInfoList) Len() int { return len(f) }
-func (f fileInfoList) Less(i, j int) bool { return f[i].Name < f[j].Name }
-func (f fileInfoList) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
+func (f byName) Len() int { return len(f) }
+func (f byName) Less(i, j int) bool { return f[i].Name() < f[j].Name() }
+func (f byName) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
// ReadDir reads the directory named by dirname and returns
// a list of sorted directory entries.
-func ReadDir(dirname string) ([]*os.FileInfo, error) {
+func ReadDir(dirname string) ([]os.FileInfo, error) {
f, err := os.Open(dirname)
if err != nil {
return nil, err
@@ -82,12 +82,8 @@ func ReadDir(dirname string) ([]*os.FileInfo, error) {
if err != nil {
return nil, err
}
- fi := make(fileInfoList, len(list))
- for i := range list {
- fi[i] = &list[i]
- }
- sort.Sort(fi)
- return fi, nil
+ sort.Sort(byName(list))
+ return list, nil
}
type nopCloser struct {
diff --git a/libgo/go/io/ioutil/ioutil_test.go b/libgo/go/io/ioutil/ioutil_test.go
index 55e4b2c..89d6815 100644
--- a/libgo/go/io/ioutil/ioutil_test.go
+++ b/libgo/go/io/ioutil/ioutil_test.go
@@ -15,8 +15,8 @@ func checkSize(t *testing.T, path string, size int64) {
if err != nil {
t.Fatalf("Stat %q (looking for size %d): %s", path, size, err)
}
- if dir.Size != size {
- t.Errorf("Stat %q: size %d want %d", path, dir.Size, size)
+ if dir.Size() != size {
+ t.Errorf("Stat %q: size %d want %d", path, dir.Size(), size)
}
}
@@ -76,9 +76,9 @@ func TestReadDir(t *testing.T) {
foundTestDir := false
for _, dir := range list {
switch {
- case dir.IsRegular() && dir.Name == "ioutil_test.go":
+ case !dir.IsDir() && dir.Name() == "ioutil_test.go":
foundTest = true
- case dir.IsDirectory() && dir.Name == "_test":
+ case dir.IsDir() && dir.Name() == "_test":
foundTestDir = true
}
}
diff --git a/libgo/go/io/ioutil/tempfile.go b/libgo/go/io/ioutil/tempfile.go
index 71028e2..645eed6 100644
--- a/libgo/go/io/ioutil/tempfile.go
+++ b/libgo/go/io/ioutil/tempfile.go
@@ -18,7 +18,7 @@ import (
var rand uint32
func reseed() uint32 {
- return uint32(time.Nanoseconds() + int64(os.Getpid()))
+ return uint32(time.Now().UnixNano() + int64(os.Getpid()))
}
func nextSuffix() string {
diff --git a/libgo/go/io/multi_test.go b/libgo/go/io/multi_test.go
index 0de5cc3..eb717f7 100644
--- a/libgo/go/io/multi_test.go
+++ b/libgo/go/io/multi_test.go
@@ -77,7 +77,7 @@ func TestMultiWriter(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
- sha1hex := fmt.Sprintf("%x", sha1.Sum())
+ sha1hex := fmt.Sprintf("%x", sha1.Sum(nil))
if sha1hex != "01cb303fa8c30a64123067c5aa6284ba7ec2d31b" {
t.Error("incorrect sha1 value")
}