diff --git a/src/cmd/internal/bio/buf.go b/src/cmd/internal/bio/buf.go index 564ac77cbf0..6a5d821d455 100644 --- a/src/cmd/internal/bio/buf.go +++ b/src/cmd/internal/bio/buf.go @@ -12,8 +12,6 @@ import ( "os" ) -const EOF = -1 - // Reader implements a seekable buffered io.Reader. type Reader struct { f *os.File @@ -98,25 +96,6 @@ func Bread(r *Reader, p []byte) int { return n } -func Bgetc(r *Reader) int { - c, err := r.ReadByte() - if err != nil { - if err != io.EOF { - log.Fatalf("reading input: %v", err) - } - return EOF - } - return int(c) -} - -func Brdline(r *Reader, delim int) string { - s, err := r.ReadBytes(byte(delim)) - if err != nil { - log.Fatalf("reading input: %v", err) - } - return string(s) -} - func (r *Reader) Close() error { return r.f.Close() } diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 01dca9fc31e..6e33ec3b050 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1269,10 +1269,10 @@ func ldobj(f *bio.Reader, pkg string, length int64, pn string, file string, when eof := f.Offset() + length start := f.Offset() - c1 := bio.Bgetc(f) - c2 := bio.Bgetc(f) - c3 := bio.Bgetc(f) - c4 := bio.Bgetc(f) + c1 := bgetc(f) + c2 := bgetc(f) + c3 := bgetc(f) + c4 := bgetc(f) f.Seek(start, 0) magic := uint32(c1)<<24 | uint32(c2)<<16 | uint32(c3)<<8 | uint32(c4) @@ -1289,9 +1289,9 @@ func ldobj(f *bio.Reader, pkg string, length int64, pn string, file string, when } /* check the header */ - line := bio.Brdline(f, '\n') - if line == "" { - Diag("truncated object file: %s", pn) + line, err := f.ReadString('\n') + if err != nil { + Diag("truncated object file: %s: %v", pn, err) return nil } @@ -1336,13 +1336,13 @@ func ldobj(f *bio.Reader, pkg string, length int64, pn string, file string, when import0 := f.Offset() c1 = '\n' // the last line ended in \n - c2 = bio.Bgetc(f) - c3 = bio.Bgetc(f) + c2 = bgetc(f) + c3 = bgetc(f) for c1 != '\n' || c2 != '!' || c3 != '\n' { c1 = c2 c2 = c3 - c3 = bio.Bgetc(f) - if c3 == bio.EOF { + c3 = bgetc(f) + if c3 == -1 { Diag("truncated object file: %s", pn) return nil } @@ -2133,3 +2133,14 @@ func Rnd(v int64, r int64) int64 { v -= c return v } + +func bgetc(r *bio.Reader) int { + c, err := r.ReadByte() + if err != nil { + if err != io.EOF { + log.Fatalf("reading input: %v", err) + } + return -1 + } + return int(c) +}