// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package elf

import (
	
	
)

// errorReader returns error from all operations.
type errorReader struct {
	error
}

func ( errorReader) ( []byte) ( int,  error) {
	return 0, .error
}

func ( errorReader) ( []byte,  int64) ( int,  error) {
	return 0, .error
}

func ( errorReader) ( int64,  int) (int64, error) {
	return 0, .error
}

func ( errorReader) () error {
	return .error
}

// readSeekerFromReader converts an io.Reader into an io.ReadSeeker.
// In general Seek may not be efficient, but it is optimized for
// common cases such as seeking to the end to find the length of the
// data.
type readSeekerFromReader struct {
	reset  func() (io.Reader, error)
	r      io.Reader
	size   int64
	offset int64
}

func ( *readSeekerFromReader) () {
	,  := .reset()
	if  != nil {
		.r = errorReader{}
	} else {
		.r = 
	}
	.offset = 0
}

func ( *readSeekerFromReader) ( []byte) ( int,  error) {
	if .r == nil {
		.start()
	}
	,  = .r.Read()
	.offset += int64()
	return , 
}

func ( *readSeekerFromReader) ( int64,  int) (int64, error) {
	var  int64
	switch  {
	case seekStart:
		 = 
	case seekCurrent:
		 = .offset + 
	case seekEnd:
		 = .size + 
	default:
		return 0, os.ErrInvalid
	}

	switch {
	case  == .offset:
		return , nil

	case  < 0,  > .size:
		return 0, os.ErrInvalid

	case  == 0:
		.r = nil

	case  == .size:
		.r = errorReader{io.EOF}

	default:
		if  < .offset {
			// Restart at the beginning.
			.start()
		}
		// Read until we reach offset.
		var  [512]byte
		for .offset <  {
			 := [:]
			if -.offset < int64(len()) {
				 = [:-.offset]
			}
			if ,  := .Read();  != nil {
				return 0, 
			}
		}
	}
	.offset = 
	return .offset, nil
}