mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
os: talk about errors and PathError in the package documentation
Fixes #2383. R=golang-dev, bradfitz, adg, rsc CC=golang-dev https://golang.org/cl/5641061
This commit is contained in:
parent
1253c75cf5
commit
be0f6febad
9 changed files with 54 additions and 18 deletions
|
|
@ -60,7 +60,7 @@ const DevNull = "/dev/null"
|
|||
// or Create instead. It opens the named file with specified flag
|
||||
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
|
||||
// methods on the returned File can be used for I/O.
|
||||
// It returns the File and an error, if any.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func OpenFile(name string, flag int, perm FileMode) (file *File, err error) {
|
||||
r, e := syscall.Open(name, flag|syscall.O_CLOEXEC, syscallMode(perm))
|
||||
if e != nil {
|
||||
|
|
@ -103,7 +103,7 @@ func (file *file) close() error {
|
|||
}
|
||||
|
||||
// Stat returns the FileInfo structure describing file.
|
||||
// It returns the FileInfo and an error, if any.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func (f *File) Stat() (fi FileInfo, err error) {
|
||||
var stat syscall.Stat_t
|
||||
err = syscall.Fstat(f.fd, &stat)
|
||||
|
|
@ -113,11 +113,12 @@ func (f *File) Stat() (fi FileInfo, err error) {
|
|||
return fileInfoFromStat(&stat, f.name), nil
|
||||
}
|
||||
|
||||
// Stat returns a FileInfo describing the named file and an error, if any.
|
||||
// Stat returns a FileInfo describing the named file.
|
||||
// If name names a valid symbolic link, the returned FileInfo describes
|
||||
// the file pointed at by the link and has fi.FollowedSymlink set to true.
|
||||
// If name names an invalid symbolic link, the returned FileInfo describes
|
||||
// the link itself and has fi.FollowedSymlink set to false.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func Stat(name string) (fi FileInfo, err error) {
|
||||
var stat syscall.Stat_t
|
||||
err = syscall.Stat(name, &stat)
|
||||
|
|
@ -127,9 +128,10 @@ func Stat(name string) (fi FileInfo, err error) {
|
|||
return fileInfoFromStat(&stat, name), nil
|
||||
}
|
||||
|
||||
// Lstat returns a FileInfo describing the named file and an
|
||||
// error, if any. If the file is a symbolic link, the returned FileInfo
|
||||
// Lstat returns a FileInfo describing the named file.
|
||||
// If the file is a symbolic link, the returned FileInfo
|
||||
// describes the symbolic link. Lstat makes no attempt to follow the link.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func Lstat(name string) (fi FileInfo, err error) {
|
||||
var stat syscall.Stat_t
|
||||
err = syscall.Lstat(name, &stat)
|
||||
|
|
@ -193,6 +195,7 @@ func (f *File) seek(offset int64, whence int) (ret int64, err error) {
|
|||
|
||||
// Truncate changes the size of the named file.
|
||||
// If the file is a symbolic link, it changes the size of the link's target.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func Truncate(name string, size int64) error {
|
||||
if e := syscall.Truncate(name, size); e != nil {
|
||||
return &PathError{"truncate", name, e}
|
||||
|
|
@ -201,6 +204,7 @@ func Truncate(name string, size int64) error {
|
|||
}
|
||||
|
||||
// Remove removes the named file or directory.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func Remove(name string) error {
|
||||
// System call interface forces us to know
|
||||
// whether name is a file or directory.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue