diff options
Diffstat (limited to 'libgo/go/os/file.go')
-rw-r--r-- | libgo/go/os/file.go | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/libgo/go/os/file.go b/libgo/go/os/file.go index 3efa650c657..85f151e2840 100644 --- a/libgo/go/os/file.go +++ b/libgo/go/os/file.go @@ -3,7 +3,13 @@ // license that can be found in the LICENSE file. // Package os provides a platform-independent interface to operating system -// functionality. The design is Unix-like. +// functionality. The design is Unix-like, although the error handling is +// Go-like; failing calls return values of type error rather than error numbers. +// Often, more information is available within the error. For example, +// if a call that takes a file name fails, such as Open or Stat, the error +// will include failing file name when printed and will be of type *PathError, +// which may be unpacked for more information. +// // The os interface is intended to be uniform across all operating systems. // Features not generally available appear in the system-specific package syscall. package os @@ -19,26 +25,22 @@ func (f *File) Name() string { return f.name } // Stdin, Stdout, and Stderr are open Files pointing to the standard input, // standard output, and standard error file descriptors. var ( - Stdin = NewFile(syscall.Stdin, "/dev/stdin") - Stdout = NewFile(syscall.Stdout, "/dev/stdout") - Stderr = NewFile(syscall.Stderr, "/dev/stderr") + Stdin = NewFile(uintptr(syscall.Stdin), "/dev/stdin") + Stdout = NewFile(uintptr(syscall.Stdout), "/dev/stdout") + Stderr = NewFile(uintptr(syscall.Stderr), "/dev/stderr") ) // Flags to Open wrapping those of the underlying system. Not all flags // may be implemented on a given system. const ( - O_RDONLY int = syscall.O_RDONLY // open the file read-only. - O_WRONLY int = syscall.O_WRONLY // open the file write-only. - O_RDWR int = syscall.O_RDWR // open the file read-write. - O_APPEND int = syscall.O_APPEND // append data to the file when writing. - O_ASYNC int = syscall.O_ASYNC // generate a signal when I/O is available. - O_CREATE int = syscall.O_CREAT // create a new file if none exists. - O_EXCL int = syscall.O_EXCL // used with O_CREATE, file must not exist - O_NOCTTY int = syscall.O_NOCTTY // do not make file the controlling tty. - O_NONBLOCK int = syscall.O_NONBLOCK // open in non-blocking mode. - O_NDELAY int = O_NONBLOCK // synonym for O_NONBLOCK - O_SYNC int = syscall.O_SYNC // open for synchronous I/O. - O_TRUNC int = syscall.O_TRUNC // if possible, truncate file when opened. + O_RDONLY int = syscall.O_RDONLY // open the file read-only. + O_WRONLY int = syscall.O_WRONLY // open the file write-only. + O_RDWR int = syscall.O_RDWR // open the file read-write. + O_APPEND int = syscall.O_APPEND // append data to the file when writing. + O_CREATE int = syscall.O_CREAT // create a new file if none exists. + O_EXCL int = syscall.O_EXCL // used with O_CREATE, file must not exist + O_SYNC int = syscall.O_SYNC // open for synchronous I/O. + O_TRUNC int = syscall.O_TRUNC // if possible, truncate file when opened. ) // Seek whence values. @@ -157,7 +159,7 @@ func (f *File) WriteString(s string) (ret int, err error) { } // Mkdir creates a new directory with the specified name and permission bits. -// It returns an error, if any. +// If there is an error, it will be of type *PathError. func Mkdir(name string, perm FileMode) error { e := syscall.Mkdir(name, syscallMode(perm)) if e != nil { @@ -167,6 +169,7 @@ func Mkdir(name string, perm FileMode) error { } // Chdir changes the current working directory to the named directory. +// If there is an error, it will be of type *PathError. func Chdir(dir string) error { if e := syscall.Chdir(dir); e != nil { return &PathError{"chdir", dir, e} @@ -176,6 +179,7 @@ func Chdir(dir string) error { // Chdir changes the current working directory to the file, // which must be a directory. +// If there is an error, it will be of type *PathError. func (f *File) Chdir() error { if e := syscall.Fchdir(f.fd); e != nil { return &PathError{"chdir", f.name, e} @@ -186,7 +190,7 @@ func (f *File) Chdir() error { // Open opens the named file for reading. If successful, methods on // the returned file can be used for reading; the associated file // descriptor has mode O_RDONLY. -// It returns the File and an error, if any. +// If there is an error, it will be of type *PathError. func Open(name string) (file *File, err error) { return OpenFile(name, O_RDONLY, 0) } @@ -195,7 +199,7 @@ func Open(name string) (file *File, err error) { // it if it already exists. If successful, methods on the returned // File can be used for I/O; the associated file descriptor has mode // O_RDWR. -// It returns the File and an error, if any. +// If there is an error, it will be of type *PathError. func Create(name string) (file *File, err error) { return OpenFile(name, O_RDWR|O_CREATE|O_TRUNC, 0666) } |