Commit 05d53165 authored by David Crawshaw's avatar David Crawshaw

cmd/internal/ld: remove Biobuf unget

The underlying *bufio.Reader does everything that's needed here.

Change-Id: If0712a5b4d3142ae4bceaa2efe287eaf2b91e54e
Reviewed-on: https://go-review.googlesource.com/9365Reviewed-by: 's avatarJosh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent cbbe9f63
......@@ -41,9 +41,11 @@ func ldobjfile(ctxt *Link, f *Biobuf, pkg string, length int64, pn string) {
}
for {
c = Bgetc(f)
Bungetc(f)
if c == 0xff {
c, err := f.r.Peek(1)
if err != nil {
log.Fatalf("%s: peeking: %v", pn, err)
}
if c[0] == 0xff {
break
}
readsym(ctxt, f, pkg, pn)
......
......@@ -77,12 +77,10 @@ func cutStringAtNUL(s string) string {
}
type Biobuf struct {
unget [2]int
numUnget int
f *os.File
r *bufio.Reader
w *bufio.Writer
linelen int
f *os.File
r *bufio.Reader
w *bufio.Writer
linelen int
}
func Bopenw(name string) (*Biobuf, error) {
......@@ -164,10 +162,6 @@ func Bputc(b *Biobuf, c byte) {
const Beof = -1
func Bread(b *Biobuf, p []byte) int {
if b.numUnget > 0 {
Bseek(b, -int64(b.numUnget), 1)
b.numUnget = 0
}
n, err := io.ReadFull(b.r, p)
if n == 0 {
if err != nil && err != io.EOF {
......@@ -178,25 +172,14 @@ func Bread(b *Biobuf, p []byte) int {
}
func Bgetc(b *Biobuf) int {
if b.numUnget > 0 {
b.numUnget--
return int(b.unget[b.numUnget])
}
c, err := b.r.ReadByte()
r := int(c)
if err != nil {
r = -1
return -1
}
b.unget[1] = b.unget[0]
b.unget[0] = r
return r
return int(c)
}
func Bgetrune(b *Biobuf) int {
if b.numUnget > 0 {
Bseek(b, -int64(b.numUnget), 1)
b.numUnget = 0
}
r, _, err := b.r.ReadRune()
if err != nil {
return -1
......@@ -204,19 +187,11 @@ func Bgetrune(b *Biobuf) int {
return int(r)
}
func Bungetrune(b *Biobuf) {
b.r.UnreadRune()
}
func (b *Biobuf) Read(p []byte) (int, error) {
return b.r.Read(p)
}
func Brdline(b *Biobuf, delim int) string {
if b.numUnget > 0 {
Bseek(b, -int64(b.numUnget), 1)
b.numUnget = 0
}
s, err := b.r.ReadBytes(byte(delim))
if err != nil {
log.Fatalf("reading input: %v", err)
......@@ -226,10 +201,6 @@ func Brdline(b *Biobuf, delim int) string {
}
func Brdstr(b *Biobuf, delim int, cut int) string {
if b.numUnget > 0 {
Bseek(b, -int64(b.numUnget), 1)
b.numUnget = 0
}
s, err := b.r.ReadString(byte(delim))
if err != nil {
log.Fatalf("reading input: %v", err)
......@@ -255,10 +226,6 @@ func Blinelen(b *Biobuf) int {
return b.linelen
}
func Bungetc(b *Biobuf) {
b.numUnget++
}
func Bflush(b *Biobuf) error {
return b.w.Flush()
}
......
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