2011-04-02 15:28:58 -06:00
|
|
|
// Copyright 2009 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.
|
|
|
|
|
2014-01-09 08:49:37 -07:00
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
build: add build comments to core packages
The go/build package already recognizes
system-specific file names like
mycode_darwin.go
mycode_darwin_386.go
mycode_386.s
However, it is also common to write files that
apply to multiple architectures, so a recent CL added
to go/build the ability to process comments
listing a set of conditions for building. For example:
// +build darwin freebsd openbsd/386
says that this file should be compiled only on
OS X, FreeBSD, or 32-bit x86 OpenBSD systems.
These conventions are not yet documented
(hence this long CL description).
This CL adds build comments to the multi-system
files in the core library, a step toward making it
possible to use go/build to build them.
With this change go/build can handle crypto/rand,
exec, net, path/filepath, os/user, and time.
os and syscall need additional adjustments.
R=golang-dev, r, gri, r, gustavo
CC=golang-dev
https://golang.org/cl/5011046
2011-09-15 14:48:57 -06:00
|
|
|
|
2011-04-02 15:28:58 -06:00
|
|
|
package os
|
|
|
|
|
2012-02-14 12:22:34 -07:00
|
|
|
import "syscall"
|
2011-04-02 15:28:58 -06:00
|
|
|
|
2012-03-12 23:48:07 -06:00
|
|
|
func isExist(err error) bool {
|
2012-08-02 22:25:35 -06:00
|
|
|
switch pe := err.(type) {
|
|
|
|
case nil:
|
|
|
|
return false
|
|
|
|
case *PathError:
|
|
|
|
err = pe.Err
|
|
|
|
case *LinkError:
|
2012-02-16 16:04:29 -07:00
|
|
|
err = pe.Err
|
|
|
|
}
|
|
|
|
return err == syscall.EEXIST || err == ErrExist
|
|
|
|
}
|
|
|
|
|
2012-03-12 23:48:07 -06:00
|
|
|
func isNotExist(err error) bool {
|
2012-08-02 22:25:35 -06:00
|
|
|
switch pe := err.(type) {
|
|
|
|
case nil:
|
|
|
|
return false
|
|
|
|
case *PathError:
|
|
|
|
err = pe.Err
|
|
|
|
case *LinkError:
|
2012-02-16 16:04:29 -07:00
|
|
|
err = pe.Err
|
|
|
|
}
|
|
|
|
return err == syscall.ENOENT || err == ErrNotExist
|
|
|
|
}
|
|
|
|
|
2012-03-12 23:48:07 -06:00
|
|
|
func isPermission(err error) bool {
|
2012-08-02 22:25:35 -06:00
|
|
|
switch pe := err.(type) {
|
|
|
|
case nil:
|
|
|
|
return false
|
|
|
|
case *PathError:
|
|
|
|
err = pe.Err
|
|
|
|
case *LinkError:
|
2012-02-16 16:04:29 -07:00
|
|
|
err = pe.Err
|
|
|
|
}
|
|
|
|
return err == syscall.EACCES || err == syscall.EPERM || err == ErrPermission
|
|
|
|
}
|