Commit 2be13a80 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

os: add Seek whence constants

R=r, r2, rsc1, rsc, jacek.masiulaniec
CC=golang-dev
https://golang.org/cl/4344062
parent d3ca620b
...@@ -95,7 +95,7 @@ func (tr *Reader) skipUnread() { ...@@ -95,7 +95,7 @@ func (tr *Reader) skipUnread() {
nr := tr.nb + tr.pad // number of bytes to skip nr := tr.nb + tr.pad // number of bytes to skip
tr.nb, tr.pad = 0, 0 tr.nb, tr.pad = 0, 0
if sr, ok := tr.r.(io.Seeker); ok { if sr, ok := tr.r.(io.Seeker); ok {
if _, err := sr.Seek(nr, 1); err == nil { if _, err := sr.Seek(nr, os.SEEK_CUR); err == nil {
return return
} }
} }
......
...@@ -73,7 +73,7 @@ func NewReader(r io.ReaderAt, size int64) (*Reader, os.Error) { ...@@ -73,7 +73,7 @@ func NewReader(r io.ReaderAt, size int64) (*Reader, os.Error) {
Comment: end.comment, Comment: end.comment,
} }
rs := io.NewSectionReader(r, 0, size) rs := io.NewSectionReader(r, 0, size)
if _, err = rs.Seek(int64(end.directoryOffset), 0); err != nil { if _, err = rs.Seek(int64(end.directoryOffset), os.SEEK_SET); err != nil {
return nil, err return nil, err
} }
buf := bufio.NewReader(rs) buf := bufio.NewReader(rs)
...@@ -94,7 +94,7 @@ func (f *File) Open() (rc io.ReadCloser, err os.Error) { ...@@ -94,7 +94,7 @@ func (f *File) Open() (rc io.ReadCloser, err os.Error) {
if err = readFileHeader(f, r); err != nil { if err = readFileHeader(f, r); err != nil {
return return
} }
if f.bodyOffset, err = r.Seek(0, 1); err != nil { if f.bodyOffset, err = r.Seek(0, os.SEEK_CUR); err != nil {
return return
} }
} }
......
...@@ -228,7 +228,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) { ...@@ -228,7 +228,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
switch f.Class { switch f.Class {
case ELFCLASS32: case ELFCLASS32:
hdr := new(Header32) hdr := new(Header32)
sr.Seek(0, 0) sr.Seek(0, os.SEEK_SET)
if err := binary.Read(sr, f.ByteOrder, hdr); err != nil { if err := binary.Read(sr, f.ByteOrder, hdr); err != nil {
return nil, err return nil, err
} }
...@@ -243,7 +243,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) { ...@@ -243,7 +243,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
shstrndx = int(hdr.Shstrndx) shstrndx = int(hdr.Shstrndx)
case ELFCLASS64: case ELFCLASS64:
hdr := new(Header64) hdr := new(Header64)
sr.Seek(0, 0) sr.Seek(0, os.SEEK_SET)
if err := binary.Read(sr, f.ByteOrder, hdr); err != nil { if err := binary.Read(sr, f.ByteOrder, hdr); err != nil {
return nil, err return nil, err
} }
...@@ -269,7 +269,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) { ...@@ -269,7 +269,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
names := make([]uint32, shnum) names := make([]uint32, shnum)
for i := 0; i < shnum; i++ { for i := 0; i < shnum; i++ {
off := shoff + int64(i)*int64(shentsize) off := shoff + int64(i)*int64(shentsize)
sr.Seek(off, 0) sr.Seek(off, os.SEEK_SET)
s := new(Section) s := new(Section)
switch f.Class { switch f.Class {
case ELFCLASS32: case ELFCLASS32:
......
...@@ -132,7 +132,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) { ...@@ -132,7 +132,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
} else { } else {
base = int64(0) base = int64(0)
} }
sr.Seek(base, 0) sr.Seek(base, os.SEEK_SET)
if err := binary.Read(sr, binary.LittleEndian, &f.FileHeader); err != nil { if err := binary.Read(sr, binary.LittleEndian, &f.FileHeader); err != nil {
return nil, err return nil, err
} }
...@@ -140,7 +140,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) { ...@@ -140,7 +140,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
return nil, os.NewError("Invalid PE File Format.") return nil, os.NewError("Invalid PE File Format.")
} }
// get symbol string table // get symbol string table
sr.Seek(int64(f.FileHeader.PointerToSymbolTable+18*f.FileHeader.NumberOfSymbols), 0) sr.Seek(int64(f.FileHeader.PointerToSymbolTable+18*f.FileHeader.NumberOfSymbols), os.SEEK_SET)
var l uint32 var l uint32
if err := binary.Read(sr, binary.LittleEndian, &l); err != nil { if err := binary.Read(sr, binary.LittleEndian, &l); err != nil {
return nil, err return nil, err
...@@ -149,9 +149,9 @@ func NewFile(r io.ReaderAt) (*File, os.Error) { ...@@ -149,9 +149,9 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
if _, err := r.ReadAt(ss, int64(f.FileHeader.PointerToSymbolTable+18*f.FileHeader.NumberOfSymbols)); err != nil { if _, err := r.ReadAt(ss, int64(f.FileHeader.PointerToSymbolTable+18*f.FileHeader.NumberOfSymbols)); err != nil {
return nil, err return nil, err
} }
sr.Seek(base, 0) sr.Seek(base, os.SEEK_SET)
binary.Read(sr, binary.LittleEndian, &f.FileHeader) binary.Read(sr, binary.LittleEndian, &f.FileHeader)
sr.Seek(int64(f.FileHeader.SizeOfOptionalHeader), 1) //Skip OptionalHeader sr.Seek(int64(f.FileHeader.SizeOfOptionalHeader), os.SEEK_CUR) //Skip OptionalHeader
f.Sections = make([]*Section, f.FileHeader.NumberOfSections) f.Sections = make([]*Section, f.FileHeader.NumberOfSections)
for i := 0; i < int(f.FileHeader.NumberOfSections); i++ { for i := 0; i < int(f.FileHeader.NumberOfSections); i++ {
sh := new(SectionHeader32) sh := new(SectionHeader32)
......
...@@ -148,7 +148,7 @@ func serveFile(w ResponseWriter, r *Request, name string, redirect bool) { ...@@ -148,7 +148,7 @@ func serveFile(w ResponseWriter, r *Request, name string, redirect bool) {
} else { } else {
w.Header().Set("Content-Type", "application/octet-stream") // generic binary w.Header().Set("Content-Type", "application/octet-stream") // generic binary
} }
f.Seek(0, 0) // rewind to output whole file f.Seek(0, os.SEEK_SET) // rewind to output whole file
} }
// handle Content-Range header. // handle Content-Range header.
...@@ -163,7 +163,7 @@ func serveFile(w ResponseWriter, r *Request, name string, redirect bool) { ...@@ -163,7 +163,7 @@ func serveFile(w ResponseWriter, r *Request, name string, redirect bool) {
} }
if len(ranges) == 1 { if len(ranges) == 1 {
ra := ranges[0] ra := ranges[0]
if _, err := f.Seek(ra.start, 0); err != nil { if _, err := f.Seek(ra.start, os.SEEK_SET); err != nil {
Error(w, err.String(), StatusRequestedRangeNotSatisfiable) Error(w, err.String(), StatusRequestedRangeNotSatisfiable)
return return
} }
......
...@@ -61,6 +61,13 @@ const ( ...@@ -61,6 +61,13 @@ const (
O_CREATE int = O_CREAT // create a new file if none exists. O_CREATE int = O_CREAT // create a new file if none exists.
) )
// Seek whence values.
const (
SEEK_SET int = 0 // seek relative to the origin of the file
SEEK_CUR int = 1 // seek relative to the current offset
SEEK_END int = 2 // seek relative to the end
)
type eofError int type eofError int
func (eofError) String() string { return "EOF" } func (eofError) String() string { return "EOF" }
......
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