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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Dave Cheney <dave@cheney.net>
parent bce9747e
...@@ -12,8 +12,6 @@ import ( ...@@ -12,8 +12,6 @@ import (
"os" "os"
) )
const EOF = -1
// Reader implements a seekable buffered io.Reader. // Reader implements a seekable buffered io.Reader.
type Reader struct { type Reader struct {
f *os.File f *os.File
...@@ -98,25 +96,6 @@ func Bread(r *Reader, p []byte) int { ...@@ -98,25 +96,6 @@ func Bread(r *Reader, p []byte) int {
return n 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 { func (r *Reader) Close() error {
return r.f.Close() return r.f.Close()
} }
......
...@@ -1269,10 +1269,10 @@ func ldobj(f *bio.Reader, pkg string, length int64, pn string, file string, when ...@@ -1269,10 +1269,10 @@ func ldobj(f *bio.Reader, pkg string, length int64, pn string, file string, when
eof := f.Offset() + length eof := f.Offset() + length
start := f.Offset() start := f.Offset()
c1 := bio.Bgetc(f) c1 := bgetc(f)
c2 := bio.Bgetc(f) c2 := bgetc(f)
c3 := bio.Bgetc(f) c3 := bgetc(f)
c4 := bio.Bgetc(f) c4 := bgetc(f)
f.Seek(start, 0) f.Seek(start, 0)
magic := uint32(c1)<<24 | uint32(c2)<<16 | uint32(c3)<<8 | uint32(c4) 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 ...@@ -1289,9 +1289,9 @@ func ldobj(f *bio.Reader, pkg string, length int64, pn string, file string, when
} }
/* check the header */ /* check the header */
line := bio.Brdline(f, '\n') line, err := f.ReadString('\n')
if line == "" { if err != nil {
Diag("truncated object file: %s", pn) Diag("truncated object file: %s: %v", pn, err)
return nil return nil
} }
...@@ -1336,13 +1336,13 @@ func ldobj(f *bio.Reader, pkg string, length int64, pn string, file string, when ...@@ -1336,13 +1336,13 @@ func ldobj(f *bio.Reader, pkg string, length int64, pn string, file string, when
import0 := f.Offset() import0 := f.Offset()
c1 = '\n' // the last line ended in \n c1 = '\n' // the last line ended in \n
c2 = bio.Bgetc(f) c2 = bgetc(f)
c3 = bio.Bgetc(f) c3 = bgetc(f)
for c1 != '\n' || c2 != '!' || c3 != '\n' { for c1 != '\n' || c2 != '!' || c3 != '\n' {
c1 = c2 c1 = c2
c2 = c3 c2 = c3
c3 = bio.Bgetc(f) c3 = bgetc(f)
if c3 == bio.EOF { if c3 == -1 {
Diag("truncated object file: %s", pn) Diag("truncated object file: %s", pn)
return nil return nil
} }
...@@ -2133,3 +2133,14 @@ func Rnd(v int64, r int64) int64 { ...@@ -2133,3 +2133,14 @@ func Rnd(v int64, r int64) int64 {
v -= c v -= c
return v 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