mirror of
https://github.com/golang/go
synced 2024-11-19 02:34:44 -07:00
the Big Error Shift applied to lib/time/zoneinfo.go.
R=gri DELTA=22 (5 added, 0 deleted, 17 changed) OCL=27608 CL=27614
This commit is contained in:
parent
34b6f642de
commit
ae08a48719
@ -25,8 +25,8 @@ func (e Errno) String() string {
|
|||||||
return syscall.Errstr(e)
|
return syscall.Errstr(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrnoToError calls NewError to create an _Error object for the string
|
// ErrnoToError converts errno to an Error (underneath, an Errno).
|
||||||
// associated with Unix error code errno.
|
// It returns nil for the "no error" errno.
|
||||||
func ErrnoToError(errno int64) Error {
|
func ErrnoToError(errno int64) Error {
|
||||||
if errno == 0 {
|
if errno == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -68,7 +68,9 @@ import (
|
|||||||
|
|
||||||
// Errors returned during parsing. TODO: different error model for execution?
|
// Errors returned during parsing. TODO: different error model for execution?
|
||||||
|
|
||||||
type ParseError struct { os.ErrorString }
|
type ParseError struct {
|
||||||
|
os.ErrorString
|
||||||
|
}
|
||||||
|
|
||||||
// All the literals are aces.
|
// All the literals are aces.
|
||||||
var lbrace = []byte{ '{' }
|
var lbrace = []byte{ '{' }
|
||||||
|
@ -23,10 +23,13 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Errors that can be generated recovering time zone information.
|
// Errors that can be generated recovering time zone information.
|
||||||
var (
|
type TimeZoneError struct {
|
||||||
badZoneinfo = os.NewError("time: malformed zoneinfo");
|
os.ErrorString
|
||||||
noZoneinfo = os.NewError("time: unknown time zone")
|
}
|
||||||
)
|
|
||||||
|
func error(bytes []byte) os.Error {
|
||||||
|
return TimeZoneError{ `time: malformed zoneinfo: "` + string(bytes) + `"` };
|
||||||
|
}
|
||||||
|
|
||||||
// Simple I/O interface to binary blob of data.
|
// Simple I/O interface to binary blob of data.
|
||||||
type data struct {
|
type data struct {
|
||||||
@ -93,13 +96,13 @@ func parseinfo(bytes []byte) (zt []zonetime, err os.Error) {
|
|||||||
|
|
||||||
// 4-byte magic "TZif"
|
// 4-byte magic "TZif"
|
||||||
if magic := d.read(4); string(magic) != "TZif" {
|
if magic := d.read(4); string(magic) != "TZif" {
|
||||||
return nil, badZoneinfo
|
return nil, error(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1-byte version, then 15 bytes of padding
|
// 1-byte version, then 15 bytes of padding
|
||||||
var p []byte;
|
var p []byte;
|
||||||
if p = d.read(16); len(p) != 16 || p[0] != 0 && p[0] != '2' {
|
if p = d.read(16); len(p) != 16 || p[0] != 0 && p[0] != '2' {
|
||||||
return nil, badZoneinfo
|
return nil, error(bytes)
|
||||||
}
|
}
|
||||||
vers := p[0];
|
vers := p[0];
|
||||||
|
|
||||||
@ -122,7 +125,7 @@ func parseinfo(bytes []byte) (zt []zonetime, err os.Error) {
|
|||||||
for i := 0; i < 6; i++ {
|
for i := 0; i < 6; i++ {
|
||||||
nn, ok := d.big4();
|
nn, ok := d.big4();
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, badZoneinfo
|
return nil, error(bytes)
|
||||||
}
|
}
|
||||||
n[i] = int(nn);
|
n[i] = int(nn);
|
||||||
}
|
}
|
||||||
@ -151,7 +154,7 @@ func parseinfo(bytes []byte) (zt []zonetime, err os.Error) {
|
|||||||
isutc := d.read(n[NUTCLocal]);
|
isutc := d.read(n[NUTCLocal]);
|
||||||
|
|
||||||
if d.error { // ran out of data
|
if d.error { // ran out of data
|
||||||
return nil, badZoneinfo
|
return nil, error(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If version == 2, the entire file repeats, this time using
|
// If version == 2, the entire file repeats, this time using
|
||||||
@ -166,16 +169,16 @@ func parseinfo(bytes []byte) (zt []zonetime, err os.Error) {
|
|||||||
var ok bool;
|
var ok bool;
|
||||||
var n uint32;
|
var n uint32;
|
||||||
if n, ok = zonedata.big4(); !ok {
|
if n, ok = zonedata.big4(); !ok {
|
||||||
return nil, badZoneinfo
|
return nil, error(bytes)
|
||||||
}
|
}
|
||||||
z[i].utcoff = int(n);
|
z[i].utcoff = int(n);
|
||||||
var b byte;
|
var b byte;
|
||||||
if b, ok = zonedata.byte(); !ok {
|
if b, ok = zonedata.byte(); !ok {
|
||||||
return nil, badZoneinfo
|
return nil, error(bytes)
|
||||||
}
|
}
|
||||||
z[i].isdst = b != 0;
|
z[i].isdst = b != 0;
|
||||||
if b, ok = zonedata.byte(); !ok || int(b) >= len(abbrev) {
|
if b, ok = zonedata.byte(); !ok || int(b) >= len(abbrev) {
|
||||||
return nil, badZoneinfo
|
return nil, error(bytes)
|
||||||
}
|
}
|
||||||
z[i].name = byteString(abbrev[b:len(abbrev)])
|
z[i].name = byteString(abbrev[b:len(abbrev)])
|
||||||
}
|
}
|
||||||
@ -186,11 +189,11 @@ func parseinfo(bytes []byte) (zt []zonetime, err os.Error) {
|
|||||||
var ok bool;
|
var ok bool;
|
||||||
var n uint32;
|
var n uint32;
|
||||||
if n, ok = txtimes.big4(); !ok {
|
if n, ok = txtimes.big4(); !ok {
|
||||||
return nil, badZoneinfo
|
return nil, error(bytes)
|
||||||
}
|
}
|
||||||
zt[i].time = int32(n);
|
zt[i].time = int32(n);
|
||||||
if int(txzones[i]) >= len(z) {
|
if int(txzones[i]) >= len(z) {
|
||||||
return nil, badZoneinfo
|
return nil, error(bytes)
|
||||||
}
|
}
|
||||||
zt[i].zone = &z[txzones[i]];
|
zt[i].zone = &z[txzones[i]];
|
||||||
if i < len(isstd) {
|
if i < len(isstd) {
|
||||||
@ -212,7 +215,7 @@ func readfile(name string, max int) (p []byte, err os.Error) {
|
|||||||
n, err1 := io.Readn(f, p);
|
n, err1 := io.Readn(f, p);
|
||||||
f.Close();
|
f.Close();
|
||||||
if err1 == nil { // too long
|
if err1 == nil { // too long
|
||||||
return nil, badZoneinfo;
|
return nil, TimeZoneError{ "time: zone file too long: " + name };
|
||||||
}
|
}
|
||||||
if err1 != io.ErrEOF {
|
if err1 != io.ErrEOF {
|
||||||
return nil, err1;
|
return nil, err1;
|
||||||
|
Loading…
Reference in New Issue
Block a user