Commits

Anonymous committed 36c4a9f

updated for Go 1

  • Participants
  • Parent commits 95bf24a

Comments (0)

Files changed (1)

 
 import (
 	"bytes"
+	"errors"
 	"io"
 	"log"
 	"net"
 	"os"
+	"strconv"
 	"strings"
-	"strconv"
 )
 
 // TFTP error codes
 
 // Other TFTP constants
 const (
-	DEFAULT_CHUNK_SIZE int = 512
-	MAX_TFTP_PACKET_SIZE = (1 << 16)
+	DEFAULT_CHUNK_SIZE   int = 512
+	MAX_TFTP_PACKET_SIZE     = (1 << 16)
 )
 
 //
 }
 
 // Create new TFTP file object from local file
-func NewTftpFile(r io.Reader, chunkSize int) (f *TftpFile, err os.Error) {
+func NewTftpFile(r io.Reader, chunkSize int) (f *TftpFile, err error) {
 	f = new(TftpFile)
 	f.chunks = make([]TftpChunk, 0)
 	for {
 		var n int
 		buf := make([]byte, chunkSize)
-		if n, err = r.Read(buf); err != nil && err != os.EOF {
+		if n, err = r.Read(buf); err != nil && err != io.EOF {
 			return
 		}
 		err = nil
 
-		if (len(f.chunks) / chunkSize) + 1 > 0xffff {
-			return nil, os.NewError("File is too large!")
+		if (len(f.chunks)/chunkSize)+1 > 0xffff {
+			return nil, errors.New("File is too large!")
 		}
 
 		id := uint16(len(f.chunks) + 1)
 	return uint8(n >> 8), uint8(n & 0xff)
 }
 
-func readUint16(r io.Reader) (uint16, os.Error) {
+func readUint16(r io.Reader) (uint16, error) {
 	var b []byte = make([]byte, 2)
 	if n, err := r.Read(b); err != nil {
 		return 0, err
 	} else {
 		if n != len(b) {
-			return 0, os.NewError("Unexpected end of data")
+			return 0, errors.New("Unexpected end of data")
 		}
 	}
 	return toUint16(b[0], b[1]), nil
 }
 
-func readString(r io.Reader) (s string, err os.Error) {
+func readString(r io.Reader) (s string, err error) {
 	var b []byte = make([]byte, 1)
 	var str []byte = make([]byte, 0)
 
 			return
 		} else {
 			if n != 1 {
-				err = os.NewError("string is not null-terminated")
+				err = errors.New("string is not null-terminated")
 				return
 			}
 			if b[0] == 0 {
 	return string(str), nil
 }
 
-func readOptions(r io.Reader) (file string, mode string, options map[string]string, err os.Error) {
+func readOptions(r io.Reader) (file string, mode string, options map[string]string, err error) {
 	if file, err = readString(r); err != nil {
 		return
 	}
 	for {
 		var name, value string
 		if name, err = readString(r); err != nil {
-			if err == os.EOF {
+			if err == io.EOF {
 				err = nil
 			}
 			return
 		switch req {
 
 		case RRQ:
-			fileName, fileMode, fileOpts, err := readOptions(tftpPacket);
+			fileName, fileMode, fileOpts, err := readOptions(tftpPacket)
 			if err != nil {
 				log.Println(err)
 				continue