Commit 9d4efdfd authored by Dave Cheney's avatar Dave Cheney

cmd/internal/bio: move Bgetc to link/internal/ld

Also, remove bio.Brdline.

Change-Id: I3e0caed27a373fd71737cf6892de5e8fc208b776
Reviewed-on: https://go-review.googlesource.com/21783Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Dave Cheney <dave@cheney.net>
parent bce9747e
......@@ -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()
}
......
......@@ -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)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment