summaryrefslogtreecommitdiffstats
path: root/libgo/go/archive
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-12-03 02:17:34 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-12-03 02:17:34 +0000
commit6692ad1d1b2710fc619d04aad2ae0668cc59f4db (patch)
tree7f76eff391f37fe6467ff4ffbc0c582c9959ea30 /libgo/go/archive
parent96265ae6967d08ca35d36e87b7588c0c9e6e5cca (diff)
downloadppe42-gcc-6692ad1d1b2710fc619d04aad2ae0668cc59f4db.tar.gz
ppe42-gcc-6692ad1d1b2710fc619d04aad2ae0668cc59f4db.zip
libgo: Update to weekly.2011-11-02.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181964 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/archive')
-rw-r--r--libgo/go/archive/tar/reader.go15
-rw-r--r--libgo/go/archive/tar/reader_test.go10
-rw-r--r--libgo/go/archive/tar/writer.go18
-rw-r--r--libgo/go/archive/zip/reader.go35
-rw-r--r--libgo/go/archive/zip/reader_test.go5
-rw-r--r--libgo/go/archive/zip/struct.go10
-rw-r--r--libgo/go/archive/zip/writer.go24
-rw-r--r--libgo/go/archive/zip/zip_test.go6
8 files changed, 62 insertions, 61 deletions
diff --git a/libgo/go/archive/tar/reader.go b/libgo/go/archive/tar/reader.go
index 12de2ada083..65bf1204ab4 100644
--- a/libgo/go/archive/tar/reader.go
+++ b/libgo/go/archive/tar/reader.go
@@ -9,6 +9,7 @@ package tar
import (
"bytes"
+ "errors"
"io"
"io/ioutil"
"os"
@@ -16,7 +17,7 @@ import (
)
var (
- HeaderError = os.NewError("invalid tar header")
+ HeaderError = errors.New("invalid tar header")
)
// A Reader provides sequential access to the contents of a tar archive.
@@ -39,7 +40,7 @@ var (
// }
type Reader struct {
r io.Reader
- err os.Error
+ err error
nb int64 // number of unread bytes for current file entry
pad int64 // amount of padding (ignored) after current file entry
}
@@ -48,7 +49,7 @@ type Reader struct {
func NewReader(r io.Reader) *Reader { return &Reader{r: r} }
// Next advances to the next entry in the tar archive.
-func (tr *Reader) Next() (*Header, os.Error) {
+func (tr *Reader) Next() (*Header, error) {
var hdr *Header
if tr.err == nil {
tr.skipUnread()
@@ -119,7 +120,7 @@ func (tr *Reader) readHeader() *Header {
return nil
}
if bytes.Equal(header, zeroBlock[0:blockSize]) {
- tr.err = os.EOF
+ tr.err = io.EOF
} else {
tr.err = HeaderError // zero block and then non-zero block
}
@@ -201,10 +202,10 @@ func (tr *Reader) readHeader() *Header {
// Read reads from the current entry in the tar archive.
// It returns 0, os.EOF when it reaches the end of that entry,
// until Next is called to advance to the next entry.
-func (tr *Reader) Read(b []byte) (n int, err os.Error) {
+func (tr *Reader) Read(b []byte) (n int, err error) {
if tr.nb == 0 {
// file consumed
- return 0, os.EOF
+ return 0, io.EOF
}
if int64(len(b)) > tr.nb {
@@ -213,7 +214,7 @@ func (tr *Reader) Read(b []byte) (n int, err os.Error) {
n, err = tr.r.Read(b)
tr.nb -= int64(n)
- if err == os.EOF && tr.nb > 0 {
+ if err == io.EOF && tr.nb > 0 {
err = io.ErrUnexpectedEOF
}
tr.err = err
diff --git a/libgo/go/archive/tar/reader_test.go b/libgo/go/archive/tar/reader_test.go
index f473c900f26..00eea6b62d7 100644
--- a/libgo/go/archive/tar/reader_test.go
+++ b/libgo/go/archive/tar/reader_test.go
@@ -132,7 +132,7 @@ testLoop:
}
}
hdr, err := tr.Next()
- if err == os.EOF {
+ if err == io.EOF {
break
}
if hdr != nil || err != nil {
@@ -195,7 +195,7 @@ func TestIncrementalRead(t *testing.T) {
// loop over all files
for ; ; nread++ {
hdr, err := tr.Next()
- if hdr == nil || err == os.EOF {
+ if hdr == nil || err == io.EOF {
break
}
@@ -211,7 +211,7 @@ func TestIncrementalRead(t *testing.T) {
rdbuf := make([]uint8, 8)
for {
nr, err := tr.Read(rdbuf)
- if err == os.EOF {
+ if err == io.EOF {
break
}
if err != nil {
@@ -250,7 +250,7 @@ func TestNonSeekable(t *testing.T) {
for {
nr, err := f.Read(rdbuf)
w.Write(rdbuf[0:nr])
- if err == os.EOF {
+ if err == io.EOF {
break
}
}
@@ -262,7 +262,7 @@ func TestNonSeekable(t *testing.T) {
for ; ; nread++ {
hdr, err := tr.Next()
- if hdr == nil || err == os.EOF {
+ if hdr == nil || err == io.EOF {
break
}
}
diff --git a/libgo/go/archive/tar/writer.go b/libgo/go/archive/tar/writer.go
index c6ce2241af0..222df90782c 100644
--- a/libgo/go/archive/tar/writer.go
+++ b/libgo/go/archive/tar/writer.go
@@ -8,15 +8,15 @@ package tar
// - catch more errors (no first header, write after close, etc.)
import (
+ "errors"
"io"
- "os"
"strconv"
)
var (
- ErrWriteTooLong = os.NewError("write too long")
- ErrFieldTooLong = os.NewError("header field too long")
- ErrWriteAfterClose = os.NewError("write after close")
+ ErrWriteTooLong = errors.New("write too long")
+ ErrFieldTooLong = errors.New("header field too long")
+ ErrWriteAfterClose = errors.New("write after close")
)
// A Writer provides sequential writing of a tar archive in POSIX.1 format.
@@ -36,7 +36,7 @@ var (
// tw.Close()
type Writer struct {
w io.Writer
- err os.Error
+ err error
nb int64 // number of unwritten bytes for current file entry
pad int64 // amount of padding to write after current file entry
closed bool
@@ -47,7 +47,7 @@ type Writer struct {
func NewWriter(w io.Writer) *Writer { return &Writer{w: w} }
// Flush finishes writing the current file (optional).
-func (tw *Writer) Flush() os.Error {
+func (tw *Writer) Flush() error {
n := tw.nb + tw.pad
for n > 0 && tw.err == nil {
nr := n
@@ -107,7 +107,7 @@ func (tw *Writer) numeric(b []byte, x int64) {
// WriteHeader writes hdr and prepares to accept the file's contents.
// WriteHeader calls Flush if it is not the first header.
// Calling after a Close will return ErrWriteAfterClose.
-func (tw *Writer) WriteHeader(hdr *Header) os.Error {
+func (tw *Writer) WriteHeader(hdr *Header) error {
if tw.closed {
return ErrWriteAfterClose
}
@@ -165,7 +165,7 @@ func (tw *Writer) WriteHeader(hdr *Header) os.Error {
// Write writes to the current entry in the tar archive.
// Write returns the error ErrWriteTooLong if more than
// hdr.Size bytes are written after WriteHeader.
-func (tw *Writer) Write(b []byte) (n int, err os.Error) {
+func (tw *Writer) Write(b []byte) (n int, err error) {
if tw.closed {
err = ErrWriteTooLong
return
@@ -187,7 +187,7 @@ func (tw *Writer) Write(b []byte) (n int, err os.Error) {
// Close closes the tar archive, flushing any unwritten
// data to the underlying writer.
-func (tw *Writer) Close() os.Error {
+func (tw *Writer) Close() error {
if tw.err != nil || tw.closed {
return tw.err
}
diff --git a/libgo/go/archive/zip/reader.go b/libgo/go/archive/zip/reader.go
index b0a559936bd..64152b4245c 100644
--- a/libgo/go/archive/zip/reader.go
+++ b/libgo/go/archive/zip/reader.go
@@ -7,6 +7,7 @@ package zip
import (
"bufio"
"compress/flate"
+ "errors"
"hash"
"hash/crc32"
"encoding/binary"
@@ -16,9 +17,9 @@ import (
)
var (
- FormatError = os.NewError("zip: not a valid zip file")
- UnsupportedMethod = os.NewError("zip: unsupported compression algorithm")
- ChecksumError = os.NewError("zip: checksum error")
+ FormatError = errors.New("zip: not a valid zip file")
+ UnsupportedMethod = errors.New("zip: unsupported compression algorithm")
+ ChecksumError = errors.New("zip: checksum error")
)
type Reader struct {
@@ -44,7 +45,7 @@ func (f *File) hasDataDescriptor() bool {
}
// OpenReader will open the Zip file specified by name and return a ReadCloser.
-func OpenReader(name string) (*ReadCloser, os.Error) {
+func OpenReader(name string) (*ReadCloser, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
@@ -64,7 +65,7 @@ func OpenReader(name string) (*ReadCloser, os.Error) {
// NewReader returns a new Reader reading from r, which is assumed to
// have the given size in bytes.
-func NewReader(r io.ReaderAt, size int64) (*Reader, os.Error) {
+func NewReader(r io.ReaderAt, size int64) (*Reader, error) {
zr := new(Reader)
if err := zr.init(r, size); err != nil {
return nil, err
@@ -72,7 +73,7 @@ func NewReader(r io.ReaderAt, size int64) (*Reader, os.Error) {
return zr, nil
}
-func (z *Reader) init(r io.ReaderAt, size int64) os.Error {
+func (z *Reader) init(r io.ReaderAt, size int64) error {
end, err := readDirectoryEnd(r, size)
if err != nil {
return err
@@ -110,13 +111,13 @@ func (z *Reader) init(r io.ReaderAt, size int64) os.Error {
}
// Close closes the Zip file, rendering it unusable for I/O.
-func (rc *ReadCloser) Close() os.Error {
+func (rc *ReadCloser) Close() error {
return rc.f.Close()
}
// Open returns a ReadCloser that provides access to the File's contents.
// It is safe to Open and Read from files concurrently.
-func (f *File) Open() (rc io.ReadCloser, err os.Error) {
+func (f *File) Open() (rc io.ReadCloser, err error) {
bodyOffset, err := f.findBodyOffset()
if err != nil {
return
@@ -148,10 +149,10 @@ type checksumReader struct {
zipr io.Reader // for reading the data descriptor
}
-func (r *checksumReader) Read(b []byte) (n int, err os.Error) {
+func (r *checksumReader) Read(b []byte) (n int, err error) {
n, err = r.rc.Read(b)
r.hash.Write(b[:n])
- if err != os.EOF {
+ if err != io.EOF {
return
}
if r.f.hasDataDescriptor() {
@@ -165,9 +166,9 @@ func (r *checksumReader) Read(b []byte) (n int, err os.Error) {
return
}
-func (r *checksumReader) Close() os.Error { return r.rc.Close() }
+func (r *checksumReader) Close() error { return r.rc.Close() }
-func readFileHeader(f *File, r io.Reader) os.Error {
+func readFileHeader(f *File, r io.Reader) error {
var b [fileHeaderLen]byte
if _, err := io.ReadFull(r, b[:]); err != nil {
return err
@@ -197,7 +198,7 @@ func readFileHeader(f *File, r io.Reader) os.Error {
// findBodyOffset does the minimum work to verify the file has a header
// and returns the file body offset.
-func (f *File) findBodyOffset() (int64, os.Error) {
+func (f *File) findBodyOffset() (int64, error) {
r := io.NewSectionReader(f.zipr, f.headerOffset, f.zipsize-f.headerOffset)
var b [fileHeaderLen]byte
if _, err := io.ReadFull(r, b[:]); err != nil {
@@ -215,7 +216,7 @@ func (f *File) findBodyOffset() (int64, os.Error) {
// readDirectoryHeader attempts to read a directory header from r.
// It returns io.ErrUnexpectedEOF if it cannot read a complete header,
// and FormatError if it doesn't find a valid header signature.
-func readDirectoryHeader(f *File, r io.Reader) os.Error {
+func readDirectoryHeader(f *File, r io.Reader) error {
var b [directoryHeaderLen]byte
if _, err := io.ReadFull(r, b[:]); err != nil {
return err
@@ -250,7 +251,7 @@ func readDirectoryHeader(f *File, r io.Reader) os.Error {
return nil
}
-func readDataDescriptor(r io.Reader, f *File) os.Error {
+func readDataDescriptor(r io.Reader, f *File) error {
var b [dataDescriptorLen]byte
if _, err := io.ReadFull(r, b[:]); err != nil {
return err
@@ -262,7 +263,7 @@ func readDataDescriptor(r io.Reader, f *File) os.Error {
return nil
}
-func readDirectoryEnd(r io.ReaderAt, size int64) (dir *directoryEnd, err os.Error) {
+func readDirectoryEnd(r io.ReaderAt, size int64) (dir *directoryEnd, err error) {
// look for directoryEndSignature in the last 1k, then in the last 65k
var b []byte
for i, bLen := range []int64{1024, 65 * 1024} {
@@ -270,7 +271,7 @@ func readDirectoryEnd(r io.ReaderAt, size int64) (dir *directoryEnd, err os.Erro
bLen = size
}
b = make([]byte, int(bLen))
- if _, err := r.ReadAt(b, size-bLen); err != nil && err != os.EOF {
+ if _, err := r.ReadAt(b, size-bLen); err != nil && err != io.EOF {
return nil, err
}
if p := findSignatureInBlock(b); p >= 0 {
diff --git a/libgo/go/archive/zip/reader_test.go b/libgo/go/archive/zip/reader_test.go
index 3b7b0dc1304..4d80aab709e 100644
--- a/libgo/go/archive/zip/reader_test.go
+++ b/libgo/go/archive/zip/reader_test.go
@@ -9,7 +9,6 @@ import (
"encoding/binary"
"io"
"io/ioutil"
- "os"
"testing"
"time"
)
@@ -18,7 +17,7 @@ type ZipTest struct {
Name string
Comment string
File []ZipTestFile
- Error os.Error // the error that Opening this file should return
+ Error error // the error that Opening this file should return
}
type ZipTestFile struct {
@@ -245,7 +244,7 @@ func TestInvalidFiles(t *testing.T) {
type sliceReaderAt []byte
-func (r sliceReaderAt) ReadAt(b []byte, off int64) (int, os.Error) {
+func (r sliceReaderAt) ReadAt(b []byte, off int64) (int, error) {
copy(b, r[int(off):int(off)+len(b)])
return len(b), nil
}
diff --git a/libgo/go/archive/zip/struct.go b/libgo/go/archive/zip/struct.go
index 4f9f599a148..b862b5a6acb 100644
--- a/libgo/go/archive/zip/struct.go
+++ b/libgo/go/archive/zip/struct.go
@@ -11,7 +11,7 @@ This package does not support ZIP64 or disk spanning.
*/
package zip
-import "os"
+import "errors"
import "time"
// Compression methods.
@@ -60,9 +60,9 @@ type directoryEnd struct {
comment string
}
-func recoverError(errp *os.Error) {
+func recoverError(errp *error) {
if e := recover(); e != nil {
- if err, ok := e.(os.Error); ok {
+ if err, ok := e.(error); ok {
*errp = err
return
}
@@ -96,11 +96,11 @@ func (h *FileHeader) Mtime_ns() int64 {
// Mode returns the permission and mode bits for the FileHeader.
// An error is returned in case the information is not available.
-func (h *FileHeader) Mode() (mode uint32, err os.Error) {
+func (h *FileHeader) Mode() (mode uint32, err error) {
if h.CreatorVersion>>8 == creatorUnix {
return h.ExternalAttrs >> 16, nil
}
- return 0, os.NewError("file mode not available")
+ return 0, errors.New("file mode not available")
}
// SetMode changes the permission and mode bits for the FileHeader.
diff --git a/libgo/go/archive/zip/writer.go b/libgo/go/archive/zip/writer.go
index 3a6dc38e20f..a1530644eee 100644
--- a/libgo/go/archive/zip/writer.go
+++ b/libgo/go/archive/zip/writer.go
@@ -8,10 +8,10 @@ import (
"bufio"
"compress/flate"
"encoding/binary"
+ "errors"
"hash"
"hash/crc32"
"io"
- "os"
)
// TODO(adg): support zip file comments
@@ -37,7 +37,7 @@ func NewWriter(w io.Writer) *Writer {
// Close finishes writing the zip file by writing the central directory.
// It does not (and can not) close the underlying writer.
-func (w *Writer) Close() (err os.Error) {
+func (w *Writer) Close() (err error) {
if w.last != nil && !w.last.closed {
if err = w.last.close(); err != nil {
return
@@ -45,7 +45,7 @@ func (w *Writer) Close() (err os.Error) {
w.last = nil
}
if w.closed {
- return os.NewError("zip: writer closed twice")
+ return errors.New("zip: writer closed twice")
}
w.closed = true
@@ -94,7 +94,7 @@ func (w *Writer) Close() (err os.Error) {
// It returns a Writer to which the file contents should be written.
// The file's contents must be written to the io.Writer before the next
// call to Create, CreateHeader, or Close.
-func (w *Writer) Create(name string) (io.Writer, os.Error) {
+func (w *Writer) Create(name string) (io.Writer, error) {
header := &FileHeader{
Name: name,
Method: Deflate,
@@ -107,7 +107,7 @@ func (w *Writer) Create(name string) (io.Writer, os.Error) {
// It returns a Writer to which the file contents should be written.
// The file's contents must be written to the io.Writer before the next
// call to Create, CreateHeader, or Close.
-func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, os.Error) {
+func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) {
if w.last != nil && !w.last.closed {
if err := w.last.close(); err != nil {
return nil, err
@@ -148,7 +148,7 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, os.Error) {
return fw, nil
}
-func writeHeader(w io.Writer, h *FileHeader) (err os.Error) {
+func writeHeader(w io.Writer, h *FileHeader) (err error) {
defer recoverError(&err)
write(w, uint32(fileHeaderSignature))
write(w, h.ReaderVersion)
@@ -176,17 +176,17 @@ type fileWriter struct {
closed bool
}
-func (w *fileWriter) Write(p []byte) (int, os.Error) {
+func (w *fileWriter) Write(p []byte) (int, error) {
if w.closed {
- return 0, os.NewError("zip: write to closed file")
+ return 0, errors.New("zip: write to closed file")
}
w.crc32.Write(p)
return w.rawCount.Write(p)
}
-func (w *fileWriter) close() (err os.Error) {
+func (w *fileWriter) close() (err error) {
if w.closed {
- return os.NewError("zip: file closed twice")
+ return errors.New("zip: file closed twice")
}
w.closed = true
if err = w.comp.Close(); err != nil {
@@ -213,7 +213,7 @@ type countWriter struct {
count int64
}
-func (w *countWriter) Write(p []byte) (int, os.Error) {
+func (w *countWriter) Write(p []byte) (int, error) {
n, err := w.w.Write(p)
w.count += int64(n)
return n, err
@@ -223,7 +223,7 @@ type nopCloser struct {
io.Writer
}
-func (w nopCloser) Close() os.Error {
+func (w nopCloser) Close() error {
return nil
}
diff --git a/libgo/go/archive/zip/zip_test.go b/libgo/go/archive/zip/zip_test.go
index 0f71fdfac17..2075715f3e0 100644
--- a/libgo/go/archive/zip/zip_test.go
+++ b/libgo/go/archive/zip/zip_test.go
@@ -9,15 +9,15 @@ package zip
import (
"bytes"
"fmt"
- "os"
+ "io"
"testing"
)
type stringReaderAt string
-func (s stringReaderAt) ReadAt(p []byte, off int64) (n int, err os.Error) {
+func (s stringReaderAt) ReadAt(p []byte, off int64) (n int, err error) {
if off >= int64(len(s)) {
- return 0, os.EOF
+ return 0, io.EOF
}
n = copy(p, s[off:])
return
OpenPOWER on IntegriCloud