diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-12-22 01:15:33 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-12-22 01:15:33 +0000 |
commit | 409a5e7eb4cca107037fafa4a7eea92603edb83d (patch) | |
tree | 06f36bbef6fae78278f799194ad0df8ba2dabaa1 /libgo/go/syscall | |
parent | 7e9268b4cf01ab87d9b602f592ed2e2facfadda9 (diff) | |
download | gcc-409a5e7eb4cca107037fafa4a7eea92603edb83d.zip gcc-409a5e7eb4cca107037fafa4a7eea92603edb83d.tar.gz gcc-409a5e7eb4cca107037fafa4a7eea92603edb83d.tar.bz2 |
libgo: Update to revision 15193:6fdc1974457c of master library.
From-SVN: r194692
Diffstat (limited to 'libgo/go/syscall')
-rw-r--r-- | libgo/go/syscall/env_plan9.go | 36 | ||||
-rw-r--r-- | libgo/go/syscall/libcall_linux_utimesnano.go | 29 | ||||
-rw-r--r-- | libgo/go/syscall/libcall_posix_utimesnano.go | 24 | ||||
-rw-r--r-- | libgo/go/syscall/syscall.go | 13 |
4 files changed, 85 insertions, 17 deletions
diff --git a/libgo/go/syscall/env_plan9.go b/libgo/go/syscall/env_plan9.go index 2848d9b..0f89aa9 100644 --- a/libgo/go/syscall/env_plan9.go +++ b/libgo/go/syscall/env_plan9.go @@ -12,14 +12,17 @@ import ( ) var ( - // envOnce guards initialization by copyenv, which populates env. + // envOnce guards copyenv, which populates env. envOnce sync.Once // envLock guards env. envLock sync.RWMutex // env maps from an environment variable to its value. - env map[string]string + env = make(map[string]string) + + errZeroLengthKey = errors.New("zero length key") + errShortWrite = errors.New("i/o count too small") ) func readenv(key string) (string, error) { @@ -47,12 +50,18 @@ func writeenv(key, value string) error { return err } defer Close(fd) - _, err = Write(fd, []byte(value)) - return err + b := []byte(value) + n, err := Write(fd, b) + if err != nil { + return err + } + if n != len(b) { + return errShortWrite + } + return nil } func copyenv() { - env = make(map[string]string) fd, err := Open("/env", O_RDONLY) if err != nil { return @@ -72,7 +81,6 @@ func copyenv() { } func Getenv(key string) (value string, found bool) { - envOnce.Do(copyenv) if len(key) == 0 { return "", false } @@ -80,17 +88,20 @@ func Getenv(key string) (value string, found bool) { envLock.RLock() defer envLock.RUnlock() - v, ok := env[key] - if !ok { + if v, ok := env[key]; ok { + return v, true + } + v, err := readenv(key) + if err != nil { return "", false } + env[key] = v return v, true } func Setenv(key, value string) error { - envOnce.Do(copyenv) if len(key) == 0 { - return errors.New("zero length key") + return errZeroLengthKey } envLock.Lock() @@ -105,8 +116,6 @@ func Setenv(key, value string) error { } func Clearenv() { - envOnce.Do(copyenv) // prevent copyenv in Getenv/Setenv - envLock.Lock() defer envLock.Unlock() @@ -115,9 +124,10 @@ func Clearenv() { } func Environ() []string { - envOnce.Do(copyenv) envLock.RLock() defer envLock.RUnlock() + + envOnce.Do(copyenv) a := make([]string, len(env)) i := 0 for k, v := range env { diff --git a/libgo/go/syscall/libcall_linux_utimesnano.go b/libgo/go/syscall/libcall_linux_utimesnano.go new file mode 100644 index 0000000..043ab0d --- /dev/null +++ b/libgo/go/syscall/libcall_linux_utimesnano.go @@ -0,0 +1,29 @@ +// Copyright 2012 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. + +// GNU/Linux version of UtimesNano. + +package syscall + +import "unsafe" + +//sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) +//utimensat(dirfd int, path *byte, times *[2]Timespec, flags int) int +func UtimesNano(path string, ts []Timespec) (err error) { + if len(ts) != 2 { + return EINVAL + } + err = utimensat(_AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0) + if err != ENOSYS { + return err + } + // If the utimensat syscall isn't available (utimensat was added to Linux + // in 2.6.22, Released, 8 July 2007) then fall back to utimes + var tv [2]Timeval + for i := 0; i < 2; i++ { + tv[i].Sec = Timeval_sec_t(ts[i].Sec) + tv[i].Usec = Timeval_usec_t(ts[i].Nsec / 1000) + } + return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0]))) +} diff --git a/libgo/go/syscall/libcall_posix_utimesnano.go b/libgo/go/syscall/libcall_posix_utimesnano.go new file mode 100644 index 0000000..e0751f5 --- /dev/null +++ b/libgo/go/syscall/libcall_posix_utimesnano.go @@ -0,0 +1,24 @@ +// Copyright 2012 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. + +// General POSIX version of UtimesNano. + +package syscall + +import "unsafe" + +func UtimesNano(path string, ts []Timespec) error { + // TODO: The BSDs can do utimensat with SYS_UTIMENSAT but it + // isn't supported by darwin so this uses utimes instead + if len(ts) != 2 { + return EINVAL + } + // Not as efficient as it could be because Timespec and + // Timeval have different types in the different OSes + tv := [2]Timeval{ + NsecToTimeval(TimespecToNsec(ts[0])), + NsecToTimeval(TimespecToNsec(ts[1])), + } + return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0]))) +} diff --git a/libgo/go/syscall/syscall.go b/libgo/go/syscall/syscall.go index 56296c8..c4f2125 100644 --- a/libgo/go/syscall/syscall.go +++ b/libgo/go/syscall/syscall.go @@ -3,10 +3,15 @@ // license that can be found in the LICENSE file. // Package syscall contains an interface to the low-level operating system -// primitives. The details vary depending on the underlying system. -// Its primary use is inside other packages that provide a more portable -// interface to the system, such as "os", "time" and "net". Use those -// packages rather than this one if you can. +// primitives. The details vary depending on the underlying system, and +// by default, godoc will display the syscall documentation for the current +// system. If you want godoc to display syscall documentation for another +// system, set $GOOS and $GOARCH to the desired system. For example, if +// you want to view documentation for freebsd/arm on linux/amd64, set $GOOS +// to freebsd and $GOARCH to arm. +// The primary use of syscall is inside other packages that provide a more +// portable interface to the system, such as "os", "time" and "net". Use +// those packages rather than this one if you can. // For details of the functions and data types in this package consult // the manuals for the appropriate operating system. // These calls return err == nil to indicate success; otherwise |