gcc/libgo/go/time/zoneinfo_android.go
Ian Lance Taylor 1a2f01efa6 libgo: update to Go1.10beta1
Update the Go library to the 1.10beta1 release.
    
    Requires a few changes to the compiler for modifications to the map
    runtime code, and to handle some nowritebarrier cases in the runtime.
    
    Reviewed-on: https://go-review.googlesource.com/86455

gotools/:
	* Makefile.am (go_cmd_vet_files): New variable.
	(go_cmd_buildid_files, go_cmd_test2json_files): New variables.
	(s-zdefaultcc): Change from constants to functions.
	(noinst_PROGRAMS): Add vet, buildid, and test2json.
	(cgo$(EXEEXT)): Link against $(LIBGOTOOL).
	(vet$(EXEEXT)): New target.
	(buildid$(EXEEXT)): New target.
	(test2json$(EXEEXT)): New target.
	(install-exec-local): Install all $(noinst_PROGRAMS).
	(uninstall-local): Uninstasll all $(noinst_PROGRAMS).
	(check-go-tool): Depend on $(noinst_PROGRAMS).  Copy down
	objabi.go.
	(check-runtime): Depend on $(noinst_PROGRAMS).
	(check-cgo-test, check-carchive-test): Likewise.
	(check-vet): New target.
	(check): Depend on check-vet.  Look at cmd_vet-testlog.
	(.PHONY): Add check-vet.
	* Makefile.in: Rebuild.

From-SVN: r256365
2018-01-09 01:23:08 +00:00

79 lines
2.1 KiB
Go

// Copyright 2016 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.
// Parse the "tzdata" packed timezone file used on Android.
// The format is lifted from ZoneInfoDB.java and ZoneInfo.java in
// java/libcore/util in the AOSP.
package time
import (
"errors"
"runtime"
)
var zoneSources = []string{
"/system/usr/share/zoneinfo/tzdata",
"/data/misc/zoneinfo/current/tzdata",
runtime.GOROOT() + "/lib/time/zoneinfo.zip",
}
func initLocal() {
// TODO(elias.naur): getprop persist.sys.timezone
localLoc = *UTC
}
func init() {
loadTzinfoFromTzdata = androidLoadTzinfoFromTzdata
}
func androidLoadTzinfoFromTzdata(file, name string) ([]byte, error) {
const (
headersize = 12 + 3*4
namesize = 40
entrysize = namesize + 3*4
)
if len(name) > namesize {
return nil, errors.New(name + " is longer than the maximum zone name length (40 bytes)")
}
fd, err := open(file)
if err != nil {
return nil, err
}
defer closefd(fd)
buf := make([]byte, headersize)
if err := preadn(fd, buf, 0); err != nil {
return nil, errors.New("corrupt tzdata file " + file)
}
d := dataIO{buf, false}
if magic := d.read(6); string(magic) != "tzdata" {
return nil, errors.New("corrupt tzdata file " + file)
}
d = dataIO{buf[12:], false}
indexOff, _ := d.big4()
dataOff, _ := d.big4()
indexSize := dataOff - indexOff
entrycount := indexSize / entrysize
buf = make([]byte, indexSize)
if err := preadn(fd, buf, int(indexOff)); err != nil {
return nil, errors.New("corrupt tzdata file " + file)
}
for i := 0; i < int(entrycount); i++ {
entry := buf[i*entrysize : (i+1)*entrysize]
// len(name) <= namesize is checked at function entry
if string(entry[:len(name)]) != name {
continue
}
d := dataIO{entry[namesize:], false}
off, _ := d.big4()
size, _ := d.big4()
buf := make([]byte, size)
if err := preadn(fd, buf, int(off+dataOff)); err != nil {
return nil, errors.New("corrupt tzdata file " + file)
}
return buf, nil
}
return nil, errors.New("cannot find " + name + " in tzdata file " + file)
}